ajout switch settings page + option component 🔨

pull/1/head
Maxence LANONE 2 years ago
parent 8d2460f10e
commit 3b4213c78c

@ -8,39 +8,43 @@ import { useNavigation } from '@react-navigation/native';
type CityListItemProps = { type CityListItemProps = {
item: City; item: City;
} }
export default function CityListItem(props: CityListItemProps) { export default function CityListItem(props: CityListItemProps) {
return ( return (
<View> <>
<View style={styles.container}> <View style={styles.container}>
<View style={{width: "80%"}}>
<Text>{props.item.name}</Text> <Text style={styles.text}>{props.item.name}</Text>
<Text>{props.item.name}</Text> </View>
<Text>{props.item.longitude}</Text> <View style={styles.separator} />
<Text>{props.item.latitude}</Text> </>
</View>
</View> )
<View style={styles.separator}/>
</View>
)
} }
const styles = StyleSheet.create({ const styles = StyleSheet.create({
container: { container: {
flex: 1, flex: 0,
flexDirection: "row", flexDirection: 'row',
marginHorizontal: "30%" justifyContent: 'space-between',
}, alignItems: 'center',
separator: { width: '100%',
marginVertical: 4, },
backgroundColor: "rgba(255,255,255,0.3)", separator: {
height: 1, marginVertical: 4,
width: '90%', backgroundColor: "rgba(223,223,223,1)",
}, height: 1,
teaserImage: { width: '90%',
width: 50, },
height: 50, teaserImage: {
} width: 50,
height: 50,
},
text: {
fontWeight: "bold",
color: "black",
margin: 10,
width: '100%',
},
}); });

@ -0,0 +1,54 @@
//item for meteo in list
import React from 'react';
import { StyleSheet, Text, View, Image, TouchableOpacity, Switch } from 'react-native';
import { City, Weather, CITIES_DATA, FAVORITE_CITY_DATA, getCurrentWeather } from '../../data/stub';
import { useNavigation } from '@react-navigation/native';
import { useState } from 'react';
type OptionComponentProps = {
nameOption: String;
}
export default function OptionComponent(props: OptionComponentProps) {
const [isEnabled, setIsEnabled] = useState(false);
const toggleSwitch = () => setIsEnabled(previousState => !previousState);
return (
<>
<View style={styles.container}>
<Text style={styles.text}>{props.nameOption}</Text>
<Switch trackColor={{ false: '#767577' }}
onValueChange={toggleSwitch}
value={isEnabled}></Switch>
</View>
</>
)
}
const styles = StyleSheet.create({
container: {
flex: 0,
flexDirection: 'row',
justifyContent: 'space-evenly',
alignItems: 'center',
width: '80%',
},
separator: {
marginVertical: 4,
backgroundColor: "rgba(223,223,223,1)",
height: 1,
width: '90%',
},
teaserImage: {
width: 50,
height: 50,
},
text: {
fontWeight: "bold",
color: "black",
margin: 10,
width: '100%',
},
});

@ -29,7 +29,6 @@ const styles = StyleSheet.create({
flex: 0, flex: 0,
justifyContent: 'center', justifyContent: 'center',
alignItems: 'center', alignItems: 'center',
backgroundColor: '#F5FCFF',
margin: 10, margin: 10,
padding: 10, padding: 10,
shadowColor: "#000", shadowColor: "#000",

@ -6,6 +6,7 @@ import { FontAwesome } from "@expo/vector-icons";
import DetailMeteo from "../screen/DetailMeteo"; import DetailMeteo from "../screen/DetailMeteo";
import Meteo from "../screen/Meteo"; import Meteo from "../screen/Meteo";
import AddCity from "../screen/AddCity"; import AddCity from "../screen/AddCity";
import Settings from "../screen/Settings";
const Tab = createBottomTabNavigator(); const Tab = createBottomTabNavigator();
export default function MainTab() { export default function MainTab() {
@ -29,7 +30,7 @@ export default function MainTab() {
title: 'Add', title: 'Add',
tabBarIcon: ({ color }) => <FontAwesome name="plus" size={24} color="black" />, tabBarIcon: ({ color }) => <FontAwesome name="plus" size={24} color="black" />,
}} /> }} />
<Tab.Screen name="Settings" component={Meteo} <Tab.Screen name="Settings" component={Settings}
options={{ options={{
title: 'Settings', title: 'Settings',
tabBarIcon: ({ color }) => <TabBarIcon name="cog" color="black" /> tabBarIcon: ({ color }) => <TabBarIcon name="cog" color="black" />

@ -13,14 +13,14 @@ export default function AddCity() {
return ( return (
<View style={styles.container}> <View style={styles.container}>
<View style={styles.searchBar}> <View style={styles.searchBar}>
<Image source={require("../../assets/magnifyingglass.png")} style={styles.imageLoupe}></Image> <Image source={require("../../assets/magnifyingglass.png")} style={styles.imageLoupe}></Image>
<TextInput style={styles.textInput} placeholder="Search"> <TextInput style={styles.textInput} placeholder="Search">
</TextInput> </TextInput>
</View> </View>
<FlatList data={CITIES_DATA} renderItem={CityListItem} <FlatList data={CITIES_DATA} renderItem={CityListItem}
keyExtractor={(item: City) => item.name}/> keyExtractor={(item: City) => item.name} />
</View> </View>
); );
@ -29,31 +29,30 @@ export default function AddCity() {
const styles = StyleSheet.create({ const styles = StyleSheet.create({
container: { container: {
flex: 1, flex: 1,
backgroundColor: 'rgba(223,223,223,0.3)',
alignItems: 'center',
justifyContent: 'center', justifyContent: 'center',
alignItems: 'center',
margin: 10,
}, },
textInput: { textInput: {
height: 40, width: "90%"
borderColor: 'gray',
borderRadius: 10,
borderWidth: 1,
width: "90%",
margin: 10
}, },
searchBar: { searchBar: {
flexDirection: "row", flexDirection: 'row',
justifyContent: "center", justifyContent: 'center',
alignItems: "center", alignItems: 'center',
width: "100%", borderWidth: 0.5,
height: 50, borderColor: '#000',
backgroundColor: "rgba(255,255,255,0.3)", height: 40,
borderRadius: 10,
margin: 10,
}, },
imageLoupe: { imageLoupe: {
width: 20, padding: 10,
height: 20, margin: 5,
margin: 10 height: 15,
width: 15,
resizeMode: 'stretch',
alignItems: 'center',
} }
}); });

@ -0,0 +1,29 @@
import { useState } from 'react';
import { Button, StyleSheet, Text, View, SafeAreaView, FlatList, ListViewBase } from 'react-native';
import { City, Weather, CITIES_DATA, FAVORITE_CITY_DATA, getCurrentWeather } from '../../data/stub';
import CityListItem from '../components/CityListItem';
import OptionComponent from '../components/OptionComponent';
export default function Settings() {
const [meteo, setMeteo] = useState("Meteo");
const [city, setCity] = useState<City>(new City("Paris", 48.856614, 2.3522219));
return (
<View style={styles.container}>
<SafeAreaView/>
<OptionComponent nameOption="Dark Theme"></OptionComponent>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'flex-start',
paddingTop: 20,
},
});
Loading…
Cancel
Save