-
Notifications
You must be signed in to change notification settings - Fork 8
/
App.js
executable file
·54 lines (50 loc) · 1.75 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
/**
* @date :2018/8/12
* @author :JessieKate
* @email :[email protected]
* @description : 导航注册
*/
import React from 'react'
import {AppRegistry, DeviceEventEmitter} from 'react-native'
import NavigationService from './js/navigator/NavigationService'
import NavigatorApp from './js/navigator/StackNavigator'
import Config from './js/constant/Config'
export default class App extends React.Component {
render() {
// return <NavigatorApp/>;
return (
<NavigatorApp
ref={navigatorRef => {NavigationService.setTopLevelNavigator(navigatorRef);}}
onNavigationStateChange = {(prevState, currentState) => {
const currentScreen = getCurrentRouteName(currentState);
const prevScreen = getCurrentRouteName(prevState);
if (prevScreen !== currentScreen) {
console.log("当前屏幕切换到了:" + currentScreen);
if (currentScreen === 'Netease'){
DeviceEventEmitter.emit("Netease", null)
}
else if (currentScreen === 'Tencent'){
DeviceEventEmitter.emit("Tencent", null)
}
}
}}
/>
)
}
}
function getCurrentRouteName(navigationState) {
if (!navigationState) {
return null;
}
const route = navigationState.routes[navigationState.index];
// dive into nested navigators
if (route.routes) {
return getCurrentRouteName(route);
}
return route.routeName;
}
//是否关闭log日志
if(!Config.DEBUG){
console.log = function() {}
}
AppRegistry.registerComponent('App', () => App);