-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
80 lines (67 loc) · 2.44 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
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow
*/
import React, {useReducer} from 'react';
import {Dimensions, SafeAreaView, StatusBar, View} from 'react-native';
import Navigation from "./src/navigation/Navigation";
import useBackButton from "./src/hooks/UseBackButton";
import LoginStyle13 from './src/screens/login/LoginStyle13';
import OrdersList from './src/screens/prim/OrdersList';
import HomeScreen from './src/screens/HomeScreen';
export const PageContext = React.createContext();
const initialState = {
page: 'login13',
category: 'login',
pageStack: ['login13', 'activity1', 'menu14', 'ecommerce8', 'ecommerce14','home', 'customerlist', 'orderslist'],
info: {} //screens que voy a utilizar en mi app
};
const reducer = (state, action) => {
let newStack = state.pageStack;
if (action.page === 'pop'){
if (newStack.length > 2){
let lastpage = newStack[newStack.length - 2];
newStack.pop();
return {...state, page: lastpage, pageStack: newStack};
} else if (newStack.length === 2) {
let lastpage = newStack[newStack.length - 2];
newStack.pop();
return {...state, page: lastpage, category: 'none', pageStack: newStack};
} else {
return initialState
}
} else {
newStack.push(action.page);
return {...state, page: action.page, category: action.category, pageStack: newStack, info: action.info};
}
};
const screenWidth = Dimensions.get('window').width;
const App: () => React$Node = () => {
const [state, dispatch] = useReducer(reducer, initialState);
function backButtonHandler () {
if (state.category !== 'none'){
dispatch({page: 'pop'});
return true;
} else {
return false;
}
}
useBackButton(backButtonHandler);
return (
<PageContext.Provider value={{pageState: state, pageDispatch: dispatch}}>
<StatusBar barStyle="dark-content"/>
<SafeAreaView style={{flex: 1}}>
<View style={{flex: 1, flexDirection: 'row'}}>
<View style={{width: screenWidth, backgroundColor: '#434244'}}>
<LoginStyle13/>
</View>
<Navigation page={state.page}/>
</View>
</SafeAreaView>
</PageContext.Provider>
);
};
export default App;