-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.js
56 lines (52 loc) · 1.7 KB
/
index.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
import React from 'react';
import { View, Alert } from 'react-native';
import { createStackNavigator, createAppContainer } from 'react-navigation';
import { Client } from 'react-native-im-easemob';
import { IMStandard } from 'react-native-im';
import * as Constant from './Constant';
import PageKeys from './PageKeys';
import Home from './Home';
import setI18nConfig from './i18n';
export default function () {
return App;
}
class App extends React.PureComponent {
constructor(props) {
super(props);
setI18nConfig();
this.state = {
app: null,
};
}
componentDidMount() {
IMStandard.setup_common_model();
IMStandard.setup_common_component();
IMStandard.setup_common_page();
const page = IMStandard.Delegate.page;
const scenes = Object.keys(page).reduce((prv, cur) => {
prv[cur] = {screen: page[cur]};
return prv;
}, {});
const AppNavigator = createStackNavigator({
[PageKeys.Home]: {
screen: Home,
},
...scenes,
}, {
initialRouteName: PageKeys.Home,
});
const app = createAppContainer(AppNavigator);
const {plugin} = this.props;
if (plugin === 'easemob') {
const Easemob = require('react-native-im/src/plugin/easemob');
Easemob.setup();
Client.initWithAppKey(Constant.AppKey)
.then(() => this.setState({app}))
.catch(() => Alert.alert('Error', 'Initialize Easemob SDK is failed.'));
}
}
render() {
const AppContainer = this.state.app;
return AppContainer ? <AppContainer /> : <View />;
}
}