This repository was archived by the owner on Mar 15, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
130 lines (120 loc) · 3.6 KB
/
App.js
File metadata and controls
130 lines (120 loc) · 3.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import React from 'react';
import { Text, View, Alert,
AsyncStorage, Button} from 'react-native';
import {TabNavigator} from 'react-navigation';
import styles from './StyleSheet.js';
import List from './List';
import ShopList from './ShopList';
import FridgeList from './FridgeList';
import RecipeStack from './RecipeStack';
import ModalSelector from './ModalSelector';
import ColorSets from './ColorSets';
class Main extends React.Component{
constructor(props){
super(props);
}
clearStorage(){
console.log("Removing everithing in here");
AsyncStorage.removeItem("mainList");
AsyncStorage.removeItem("toBuy");
AsyncStorage.removeItem("fridge");
}
render(){
const {navigate} = this.props.navigation;
return <View style={[styles().cont,{padding:0}]}>
<View style={styles().button}/>
<Button title="Shopping List"
onPress={()=>navigate("List")}/>
<Button title="Suggested Recipes"
color="chocolate"
onPress={()=>navigate("Recipes")}/>
<Button title="Theme 1"
color="black"
onPress={()=>App.changeTheme(0)}/>
<Button title="Theme 2"
color="darkred"
onPress={()=>App.changeTheme(1)}/>
<Button title="Theme 3"
color="indigo"
onPress={()=>App.changeTheme(2)}/>
<Button title="Theme 4"
color="goldenrod"
onPress={()=>App.changeTheme(3)}/>
<Button title="Theme 5"
color="palegreen"
onPress={()=>App.changeTheme(4)}/>
<Button title="Theme 6"
color="teal"
onPress={()=>App.changeTheme(5)}/>
<Button title="Clear All Data"
color="red"
onPress={()=>
Alert.alert(
'Attention!',
'Are you sure to delete everything in here?',
[
{text: 'Yes', onPress:()=>this.clearStorage()},
{text: 'No', onPress:()=>console.log('No Pressed')},
],
)}/>
</View>
}
}
/*
* In this way the navigator is created every time (with updated data)
*/
const NavF = ()=>TabNavigator({
Main: {
screen: Main,
navigationOptions:({navigation})=>({
}),
},
List: {
screen: List,
},
Recipes: {
screen: RecipeStack,
},
},({
tabBarPosition: 'bottom',
tabBarOptions:({
style: [styles().bar,{paddingTop:2,height:60}],
labelStyle: [styles().icon,{fontSize:undefined}],
indicatorStyle:styles().line,
}),
}));
export default class App extends React.Component {
constructor(props){
super(props);
this.state={loaded:false};
App.changeTheme = this.changeTheme.bind(this);
}
/*
* This is to ensure the color has been loaded (cannot wait for it from
* here so I put a conservative delay)
*/
componentDidMount(){
setTimeout(()=>this.setState({loaded:true}),100);
}
/*
* This will reload the whole app to change the theme
*/
changeTheme(num){
ColorSets.setTheme(num);
this.setState({theme:num});
//Alert.alert( //it should be ok now
// "","Changes will be complete after having restarted the app",
// [
// {text: 'Ok', onPress:()=>null},
// ],
//)
}
/*
* The TabNavigator is no more a constant but a function, so that at
* each render it's recomputer with the new colors
*/
render(){
let Nav = NavF(); //redo at each render
return this.state.loaded?<Nav/>:<View/>
}
}