-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.jsx
77 lines (68 loc) · 2.19 KB
/
App.jsx
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
import React from "react";
import { Platform, AppState, View } from "react-native";
import { Notifications } from "expo";
import NavbarBottom from "./Layout/NavbarBottom";
import { ProfileProvider } from "./Providers/ProfileProviderConfig";
import { StatsProvider } from "./Providers/StatsProviderConfig";
import { ItemsProvider } from "./Providers/ItemsProviderConfig";
import { CoinsProvider } from "./Providers/CoinsProviderConfig";
import {
listenForNotifications,
getiOSNotificationPermission,
initNotification
} from "./Notifications/NotificationsScheduler";
import { StaminaProvider } from "./Providers/StaminaProviderConfig";
import CoinsBar from "./Layout/CoinsBar";
Platform.select({ ios: "Arial", android: "Comic Sans" });
class LayoutSimpleUsageShowcase extends React.Component {
constructor(props) {
super(props);
this.state = {
appState: AppState.currentState
};
}
async componentDidMount() {
AppState.addEventListener("change", this.handleAppStateChange);
getiOSNotificationPermission();
listenForNotifications();
}
componentWillUnmount() {
AppState.removeEventListener("change", this.handleAppStateChange);
}
handleAppStateChange = async nextAppState => {
if (
this.state.appState === "active" &&
nextAppState.match(/inactive|background/)
) {
const notificationId = initNotification();
this.setState({ idPromise: notificationId });
} else if (
this.state.appState.match(/inactive|background/) &&
nextAppState === "active"
) {
this.state.idPromise.then(value =>
Notifications.cancelScheduledNotificationAsync(value)
);
}
this.setState({ appState: nextAppState });
};
render() {
return (
<View style={{ backgroundColor: "#FFD5F4", flex: 1 }}>
<ItemsProvider>
<StatsProvider>
<StaminaProvider>
<CoinsProvider>
<ProfileProvider>
<CoinsBar />
<NavbarBottom />
</ProfileProvider>
</CoinsProvider>
</StaminaProvider>
</StatsProvider>
</ItemsProvider>
</View>
);
}
}
export default LayoutSimpleUsageShowcase;