-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathApp.js
86 lines (78 loc) · 3.03 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
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, {Component} from 'react';
import {AppNavigator} from "./src/AppNav";
import {Provider} from 'mobx-react'
import {BaseAppStore} from './src/store/index'
import {RouteHelper} from 'react-navigation-easy-helper'
import codePush from 'react-native-code-push'
import MoveView from "./src/components/MoveView";
import {Platform, StatusBar, Text, TouchableOpacity, View} from "react-native";
import JPushModule from 'jpush-react-native';
import {Toast} from 'teaset'
const store = new BaseAppStore();
const needLoginPage = ['UserPage'];
//设置路由拦截器,项目所有跳转方法推荐都用RouteHelper.navigate()
RouteHelper.routeInterceptor = (routeName, params) => {
if (!store.userStore.isLogin && needLoginPage.indexOf(routeName) !== -1) {
RouteHelper.navigate('LoginPage', {
routeName,
params
});
return false;
}
console.log(store, params);
return true
};
@codePush({checkFrequency: codePush.CheckFrequency.MANUAL})
export default class App extends Component<Props> {
componentDidMount() {
if (Platform.OS === 'android') {
StatusBar.setTranslucent(true);
StatusBar.setBackgroundColor('transparent');
JPushModule.notifyJSDidLoad(res => console.log(res));
}
JPushModule.getRegistrationID(registrationId => {
console.log('registrationId', registrationId);
Toast.message(registrationId);
});
this.notificationListener = event => {
console.log('addReceiveNotificationListener', event);
alert(`Notification:${JSON.stringify(event)}`);
};
JPushModule.addReceiveNotificationListener(this.notificationListener);
this.customMsgListener = event => {
console.log('addReceiveCustomMsgListener', event);
alert(`Custom:${JSON.stringify(event)}`);
};
JPushModule.addReceiveCustomMsgListener(this.customMsgListener);
}
componentWillUnmount() {
JPushModule.removeReceiveCustomMsgListener(this.customMsgListener);
JPushModule.removeReceiveNotificationListener(this.notificationListener);
}
render() {
return <Provider {...store}>
<View style={{flex: 1}}>
<AppNavigator/>
<MoveView style={{top: SCREEN_HEIGHT - 140, left: SCREEN_WIDTH - 120}}>
<TouchableOpacity
onPress={() => alert('')}
style={{
width: 80,
height: 80,
borderRadius: 40,
backgroundColor: '#0008',
alignItems: 'center',
justifyContent: 'center'
}}>
<Text style={{color: 'white'}}>悬浮窗口</Text>
</TouchableOpacity>
</MoveView>
</View>
</Provider>
}
}