-
Notifications
You must be signed in to change notification settings - Fork 1
/
App.js
98 lines (84 loc) · 2.3 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
import React, { useContext } from "react"
import { Provider } from "react-redux"
import "react-native-gesture-handler"
import { NavigationContainer } from "@react-navigation/native"
import { createStackNavigator } from "@react-navigation/stack"
import { Provider as PaperProvider } from "react-native-paper";
import {
configureStore,
createReducer,
combineReducers
} from "@reduxjs/toolkit"
import { screens } from "@screens"
import { modules, reducers, hooks } from "@modules"
import { connectors } from "@store"
import {
GlobalOptionsContext,
OptionsContext,
getOptions,
getGlobalOptions
} from "@options"
const Stack = createStackNavigator()
const getNavigation = modules => {
const globalOptions = getGlobalOptions()
const initialRoute =
globalOptions.initialRoute || (modules[0] && modules[0].value.title)
const Navigation = () => {
const routes = modules.map(mod => {
const pakage = mod.package
const name = mod.value.title
const Navigator = mod.value.navigator
const Component = props => {
return (
<OptionsContext.Provider value={getOptions(pakage)}>
<Navigator {...props} />
</OptionsContext.Provider>
)
}
return <Stack.Screen key={name} name={name} component={Component} />
})
const { screenOptions } = globalOptions
return (
<NavigationContainer>
<Stack.Navigator
initialRouteName={initialRoute}
screenOptions={screenOptions}
>
{routes}
</Stack.Navigator>
</NavigationContainer>
)
}
return Navigation
}
const getStore = globalState => {
const appReducer = createReducer(globalState, _ => {
return globalState
})
const reducer = combineReducers({
app: appReducer,
...reducers,
...connectors
})
return configureStore({
reducer: reducer,
middleware: getDefaultMiddleware => getDefaultMiddleware()
})
}
const App = () => {
const global = useContext(GlobalOptionsContext)
const Navigation = getNavigation(modules.concat(screens))
const store = getStore(global)
let effects = {}
hooks.map(hook => {
effects[hook.name] = hook.value()
})
return (
<Provider store={store}>
<PaperProvider>
<Navigation />
</PaperProvider>
</Provider>
)
}
export default App