-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
199 lines (179 loc) · 5.08 KB
/
App.js
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
import React from 'react';
import { StyleSheet, Text, View, AsyncStorage, Image } from 'react-native';
import { createStackNavigator, createAppContainer, createSwitchNavigator } from "react-navigation";
import { MenuIcon } from "./components/Menu"
import Menu from "./components/Menu"
import HomeScreen from "./screens/Home"
import LoginScreen from "./screens/LoginScreen"
import AreaCliente from "./screens/AreaCliente"
import MeuPerfil from "./screens/MeuPerfil"
import MeusPontos from "./screens/MeusPontos"
import AdicionarCupom from "./screens/AdicionarCupom"
import CadastroScreen from './screens/CadastroScreen';
import CadastroSimples from './screens/CadastroSimples';
import { AppLoading } from 'expo';
import * as Font from 'expo-font';
import ListaDesejos from './screens/ListaDesejos';
import { UserProvider } from './UserContext';
import { LojaProvider } from './LojaContext';
import Loja from './screens/Loja';
import Link from './ui/Link';
import Produtos from './screens/Produtos';
import Oferta from './screens/Oferta';
import CupomDetalhe from './screens/CupomDetalhe';
import MeusCupons from './screens/MeusCupons';
import FaleConosco from './screens/FaleConosco';
import EsqueceuSenha from './screens/EsqueceuSenha';
class LogoTitle extends React.Component {
render() {
return (
<View style={{ flex: 1, alignItems: 'center', paddingBottom: 10 }}>
<Link to="Home">
<Image
source={require('./assets/logofull.png')}
resizeMode="contain"
style={{ height: 45, marginBottom: 5, marginTop: 2 }}
/>
</Link>
</View>
);
}
}
class AuthLoadingScreen extends React.Component {
constructor() {
super();
this._bootstrapAsync();
}
// Fetch the token from storage then navigate to our appropriate place
_bootstrapAsync = async () => {
//this.props.navigation.navigate('Cadastro');
const userToken = await AsyncStorage.getItem('userToken');
// This will switch to the App screen or Auth screen and this loading
// screen will be unmounted and thrown away.
//const userToken = false;
this.props.navigation.navigate(userToken ? 'Home' : 'Cadastro');
};
// Render any loading content that you like here
render() {
return (
<View style={styles.container}>
<Text>Loading...</Text>
</View>
);
}
}
const AuthStack = createStackNavigator(
{
Cadastro: CadastroScreen,
CadastroSimples: CadastroSimples,
EsqueceuSenha: EsqueceuSenha,
Login: LoginScreen,
},
{
mode: 'modal',
headerMode: 'none',
initialRouteName: "Cadastro",
}
);
const AppNavigator = createStackNavigator(
{
AdicionarCupom: AdicionarCupom,
AreaCliente: AreaCliente,
Cupom: CupomDetalhe,
FaleConosco: FaleConosco,
Home: HomeScreen,
ListaDesejos: ListaDesejos,
Loja: Loja,
MeuPerfil: MeuPerfil,
MeusCupons: MeusCupons,
MeusPontos: MeusPontos,
Oferta: Oferta,
Produtos: Produtos,
},
{
initialRouteName: "Home",
defaultNavigationOptions: ({navigation}) => ({
headerTitle: <LogoTitle/>,
headerRight: <MenuIcon navigation={navigation}/>
})
}
);
const RootStack = createStackNavigator(
{
Main: {
screen: AppNavigator,
},
Menu: Menu,
},
{
mode: 'modal',
headerMode: 'none',
}
);
const AppContainer = createAppContainer(createSwitchNavigator(
{
App: RootStack,
Auth: AuthStack,
},
{
initialRouteName: 'App',
}
));
class App extends React.Component {
state = {
fontLoaded: false
}
async componentDidMount() {
await Font.loadAsync({
'LaughingSmiling': require('./assets/fonts/ls.ttf'),
'Rubik': require('./assets/fonts/Rubik-Regular.ttf'),
'RubikBold': require('./assets/fonts/Rubik-Bold.ttf')
});
this.setState({
fontLoaded: true
})
}
render() {
if ( !this.state.fontLoaded ) {
return <AppLoading />;
}
return <LojaProvider>
<UserProvider>
<AppContainer />
</UserProvider>
</LojaProvider>;
}
}
export default App;
const styles = StyleSheet.create({
container: {
backgroundColor: '#0ff',
justifyContent: 'center',
alignItems: 'center',
flexDirection: 'column',
},
});
// attach the .equals method to Array's prototype to call it on any array
Array.prototype.equals = function (array) {
// if the other array is a falsy value, return
if (!array)
return false;
// compare lengths - can save a lot of time
if (this.length != array.length)
return false;
for (var i = 0, l=this.length; i < l; i++) {
// Check if we have nested arrays
if (this[i] instanceof Array && array[i] instanceof Array) {
// recurse into the nested arrays
if (!this[i].equals(array[i]))
return false;
}
else if (this[i] != array[i]) {
// Warning - two different object instances will never be equal: {x:20} != {x:20}
return false;
}
}
return true;
}
// Hide method from for-in loops
Object.defineProperty(Array.prototype, "equals", {enumerable: false});