forked from ant-design/ant-design-mobile-rn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
77 lines (69 loc) · 1.94 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
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
import React from 'react';
import { AppRegistry } from 'react-native';
import 'react-native-gesture-handler';
import Provider from '../components/provider';
import RnIndex from './components/index';
import { OTHERS, UIBARS, UICONTROLS, UIVIEWS } from './demoList';
const getOptions = title => ({
title,
headerStyle: {
backgroundColor: 'black',
},
headerTintColor: 'white',
});
const scenes = {
native: {
screen: RnIndex,
navigationOptions: getOptions('Ant Design'),
},
};
[...UIVIEWS, ...UICONTROLS, ...OTHERS, ...UIBARS].map((component) => {
const Module = component.module.default;
scenes[component.title] = {
screen: Module,
navigationOptions: getOptions(component.title),
};
});
const Stack = createStackNavigator();
class App extends React.Component {
state = {
theme: null,
currentTheme: null,
};
changeTheme = (theme, currentTheme) => {
this.setState({ theme, currentTheme });
};
render() {
const { theme, currentTheme } = this.state;
return (
<Provider theme={theme}>
<NavigationContainer
screenProps={{ changeTheme: this.changeTheme, currentTheme }}
initialRouteName="Home"
>
<Stack.Navigator>
{Object.keys(scenes).map(key => (
<Stack.Screen
name={key}
key={key}
component={scenes[key].screen}
options={scenes[key].navigationOptions}
/>
))}
</Stack.Navigator>
</NavigationContainer>
</Provider>
);
}
}
AppRegistry.registerComponent('KitchenSink', () => App);
export default App;
// global catch error to avoid crash
global.ErrorUtils.setGlobalHandler((e, isFatal) => {
if (isFatal) {
// eslint-disable-next-line no-alert
alert(`${e.name}: ${e.message}`);
}
});