-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
70 lines (63 loc) · 1.97 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
/* eslint-disable react-native/no-inline-styles */
import React, { Component } from "react";
import { Provider } from "react-redux";
import { createAppContainer } from "react-navigation";
import TabNavigator from "./src/tab";
import { BackHandler, View } from "react-native";
import Toast from "react-native-easy-toast";
import Loading from "./src/components/Loading";
import SplashScreen from "react-native-splash-screen";
import store from "./src/store";
import pushNotificationConfig from "./src/utils/pushNotification";
console.warn("111");
//挂载推送api到rn实例
let Navigation = createAppContainer(TabNavigator);
// Render the app container component with the provider around it
export default class App extends Component {
componentDidMount() {
console.warn("222");
pushNotificationConfig();
SplashScreen.hide();
BackHandler.addEventListener("hardwareBackPress", this.handleBackPress);
}
componentWillUnmount() {
BackHandler.removeEventListener("hardwareBackPress", this.handleBackPress);
}
handleBackPress = () => {
this.navigator && console.warn(this.navigator.state);
this.$toast && this.$toast.show("hello world!");
// this.onMainScreen and this.goBack are just examples, you need to use your own implementation here
// Typically you would use the navigator here to go to the last state.
// if (!this.onMainScreen()) {
// this.goBack();
// return true;
// }
return false;
};
onMainScreen() {
return true;
}
render() {
return (
<Provider store={store}>
<View style={{ flex: 1 }}>
<Navigation
ref={nav => {
this.navigator = nav;
}}
/>
<Toast
ref={toast => {
Component.prototype.$toast = toast;
}}
/>
<Loading
ref={loading => {
Component.prototype.$loading = loading;
}}
/>
</View>
</Provider>
);
}
}