-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathApp.tsx
78 lines (73 loc) · 2.17 KB
/
App.tsx
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
/**
* Created by supervons 2019/08/02
*
* App 入口文件
* App entry file
*
* https://github.com/supervons/ExploreRN
*
* @format
* @flow
*/
import React, { useEffect } from "react";
import { Provider } from "react-redux";
import { StatusBar, BackHandler, Platform } from "react-native";
import { PersistGate } from "redux-persist/integration/react";
import { RootSiblingParent } from "react-native-root-siblings";
import { HomeStackScreen } from "~/routers/index";
import Loading from "~/common/loading";
import configureStore from "~/redux/store/store";
import Toast from "~/components/toast";
import I18n from "~/common/languages";
import * as Sentry from "@sentry/react-native";
Sentry.init({
dsn: "https://[email protected]/0000", // replace your sentry DSN.
});
Sentry.setUser({ name: "test_user" });
// 引入 redux 及 redux-persist 配置后的变量供使用
import { accelerometer } from "react-native-sensors";
const subscriber = accelerometer.subscribe(
({ x, y, z, timestamp }) => {
// console.log(timestamp);
},
err => {
// console.log(err);
},
);
const { store, persist } = configureStore();
const APP = function () {
let lastBackPressed = 0;
useEffect(() => {
if (Platform.OS === "android") {
BackHandler.addEventListener("hardwareBackPress", onBackAndroid);
}
}, []);
function onBackAndroid() {
if (lastBackPressed && lastBackPressed + 2000 >= Date.now()) {
//最近2秒内按过back键,可以退出应用。
BackHandler.exitApp();
return;
}
lastBackPressed = Date.now();
Toast.showToast(I18n.t("exitApp"), "SHORT", "BOTTOM");
return true;
}
return (
// 外层需 Provider 包裹, PersistGate 中的 loading 需为一个组件,否则在启动页后会有短暂黑屏
<Provider store={store}>
<PersistGate loading={null} persistor={persist}>
<StatusBar
animated={false}
backgroundColor={"transparent"}
translucent={true}
barStyle={"dark-content"}
/>
<RootSiblingParent>
<HomeStackScreen />
</RootSiblingParent>
<Loading />
</PersistGate>
</Provider>
);
};
export default APP;