🎨 ajout du darkmode. il faut plus de front pour rendre cela joli. 💄

DarkLightTheme
Pierre Ferreira 2 years ago
parent b1863bd1d3
commit 6039b9462c

@ -1,14 +0,0 @@
// export class ApiDataManager{
// public async getCards() : Promise<String[]> {
// const CardPromise = await fetch('https://omgvamp-hearthstone-v1.p.rapidapi.com/cards')
// const CardListJson = await CardPromise.json();
// const CardList: String[] = Array.of(CardListJson);
// return CardList;
// }
// }

@ -1,13 +0,0 @@
import { Card } from "../models/Card"
export class StubLib {
public getCards(): Card[] {
const NOUNOURS_LIST : Card[] = [
]
return NOUNOURS_LIST
}
}

@ -3,12 +3,9 @@ import {THEME_CHANGE, FETCH_DATA, ADD_FAVORITE_DATA} from '../constants'
const initialState = { const initialState = {
mode: 'light', mode: 'light',
cards: [], cards: [],
favoriteCards: [], favoriteCards: []
// cards: ["C_ace", "C_K", "C_Q", "C_J"],
// favoriteCards: [ "C_ace", "C_K"],
} }
// @ts-ignore // @ts-ignore
export default appReducer = (state = initialState, action) => { export default appReducer = (state = initialState, action) => {
switch (action.type) { switch (action.type) {

@ -1,5 +1,5 @@
import { StyleSheet, Text, View, Button, TouchableHighlight } from 'react-native'; import { StyleSheet, Text, View, Button, TouchableHighlight, Pressable } from 'react-native';
import { StatusBar } from 'expo-status-bar'; import { StatusBar } from 'expo-status-bar';
import React, { useState, useEffect } from "react"; import React, { useState, useEffect } from "react";
import { FlatList } from 'react-native-gesture-handler'; import { FlatList } from 'react-native-gesture-handler';
@ -26,7 +26,6 @@ const Item = ({url}) => (
<Image <Image
source={{uri:url}} source={{uri:url}}
style={{flex:1, minHeight:250, minWidth:180}}/> style={{flex:1, minHeight:250, minWidth:180}}/>
</View> </View>
); );
@ -37,11 +36,12 @@ export default function ListScreen({navigation}){
// get the current theme // get the current theme
//@ts-ignore //@ts-ignore
const theme = useSelector(state => state.theme); const theme = useSelector(state => state.theme);
// // Initialize the binding content with the application initial state
//@ts-ignore //@ts-ignore
const nList = useSelector(state => state.appReducer.cards); const nList = useSelector(state => state.appReducer.cards);
//@ts-ignore
const mode = useSelector(state => state.appReducer.mode);
// Create a const that will hold the react-redux events dispatcher // Create a const that will hold the react-redux events dispatcher
const dispatch = useDispatch(); const dispatch = useDispatch();
@ -56,40 +56,31 @@ export default function ListScreen({navigation}){
loadCards(); loadCards();
}, [dispatch]); }, [dispatch]);
//* Stub
// const {getCards} = new StubLib();
// const list: Card[] = getCards();
// const req = fetch('https://omgvamp-hearthstone-v1.p.rapidapi.com/cards')
//https://us.api.blizzard.com/hearthstone/cards/678?locale=en_US
//* Themes *// //* Themes *//
// define a component mode state // define a component mode state
const [mode, setMode] = useState(theme.mode); //const [mode, setMode] = useState(theme.mode);
// Handle changing the theme mode // Handle changing the theme mode
const handleThemeChange = () => {
dispatch(switchMode(theme.mode === 'light' ? 'dark' : 'light')); //@ts-ignore
const handleThemeChange = (mode) => {
dispatch(switchMode(mode === 'light' ? 'dark' : 'light'));
} }
// Update the app Incase the theme mode changes // Update the app Incase the theme mode changes
useEffect(() => { // useEffect(() => {
setMode(theme.mode); // setMode(theme.mode);
}, [theme]); // }, [theme]);
return ( return (
<View style={styles.container}> <View style={mode === 'light' ? styles.container_light : styles.container_dark}>
{/* <FlatList data={nList} <Pressable style={mode === 'light' ? styles.button_white : styles.button_black} onPress={() => handleThemeChange(mode)}>
renderItem={({item}) => <Item title={item.name} />} <Text>Switch Mode</Text>
keyExtractor={item => item.id}/> */} </Pressable>
<FlatList <FlatList
numColumns={2} numColumns={2}
data={nList} data={nList}
@ -100,17 +91,8 @@ export default function ListScreen({navigation}){
<Item url={item.img}/> <Item url={item.img}/>
</TouchableHighlight> </TouchableHighlight>
// //<Text>{item.name}</Text>
// // <View>
// // <Image
// // source={{uri:item.img}}
// // style={{flex:1, minHeight:250, minWidth:180}}/>
// // </View>
} keyExtractor={(item: Card) => item.id.toString()}/> } keyExtractor={(item: Card) => item.id.toString()}/>
</View> </View>
); );
} }
@ -143,30 +125,44 @@ const styles = StyleSheet.create({
title: { title: {
fontStyle: "italic", fontStyle: "italic",
}, },
///themes
container_light: { container_light: {
flex: 1, flex: 1,
backgroundColor: '#fff', backgroundColor: '#fff',
alignItems: 'center', alignItems: 'center',
justifyContent: 'center', justifyContent: 'center',
} },
,
container_dark: { container_dark: {
flex: 1, flex: 1,
backgroundColor: '#121212', backgroundColor: '#121212',
alignItems: 'center', alignItems: 'center',
justifyContent: 'center', justifyContent: 'center',
} },
,
text_light: { text_light: {
marginBottom: 20, marginBottom: 20,
color: '#000' color: '#000'
} },
,
text_dark: { text_dark: {
marginBottom: 20, marginBottom: 20,
color: "#fff" color: "#fff"
},
button_black: {
alignItems: 'center',
justifyContent: 'center',
paddingVertical: 12,
paddingHorizontal: 32,
borderRadius: 4,
elevation: 3,
backgroundColor: 'black',
},
button_white: {
alignItems: 'center',
justifyContent: 'center',
paddingVertical: 12,
paddingHorizontal: 32,
borderRadius: 4,
elevation: 3,
backgroundColor: 'white',
} }
}); });

Loading…
Cancel
Save