forked from crowdbotics-apps/test-33602
-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
86 lines (73 loc) · 2.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
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 {
configureStore,
createReducer,
combineReducers
} from "@reduxjs/toolkit"
import { screens } from "@screens"
import { modules, reducers, hooks, initialRoute } from "@modules"
import { connectors } from "@store"
const Stack = createStackNavigator()
import { GlobalOptionsContext, OptionsContext, getOptions } from "@options"
const getNavigation = (modules, screens, initialRoute) => {
const Navigation = () => {
const routes = modules.concat(screens).map(mod => {
const pakage = mod.package;
const name = mod.value.title;
const Navigator = mod.value.navigator;
const Component = () => {
return (
<OptionsContext.Provider value={getOptions(pakage)}>
<Navigator />
</OptionsContext.Provider>
)
}
return <Stack.Screen key={name} name={name} component={Component} />
})
const screenOptions = { headerShown: true };
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, screens, initialRoute)
const store = getStore(global)
let effects = {}
hooks.map(hook => {
effects[hook.name] = hook.value()
})
return (
<Provider store={store}>
<Navigation />
</Provider>
)
}
export default App