-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
99 lines (84 loc) · 3.19 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import "react-native-gesture-handler";
import React, { Suspense, useCallback, useEffect } from "react";
import { Dimensions, Platform, SafeAreaView, StyleSheet, UIManager } from "react-native";
import LoadingScreen from "./src/pages/LoadingScreen";
import { Provider as ReduxProvider, useDispatch } from "react-redux";
import store, { persistor } from "./src/store";
import AppNavigator from "./AppNavigator";
import { PersistGate } from "redux-persist/integration/react";
import { useDynamicColor } from "./src/hooks/useDynamicColor";
import { StatusBar } from "expo-status-bar";
import changeNavigationBarColor from "react-native-navigation-bar-color";
import mobileAds, { MaxAdContentRating } from "react-native-google-mobile-ads";
import {endConnection, getProducts, initConnection} from "react-native-iap";
import config from "./config";
import { setDonateProducts } from "./src/store/actions";
import * as SplashScreen from "expo-splash-screen";
import { DarkTheme, NavigationContainer } from "@react-navigation/native";
const { width, height } = Dimensions.get("window");
if (
Platform.OS === "android" &&
UIManager.setLayoutAnimationEnabledExperimental
) {
UIManager.setLayoutAnimationEnabledExperimental(true);
}
mobileAds()
.setRequestConfiguration({
maxAdContentRating: MaxAdContentRating.T,
tagForChildDirectedTreatment: true,
tagForUnderAgeOfConsent: true,
testDeviceIdentifiers: [],
})
.then(() => {
mobileAds().initialize();
});
const ReduxBlocker = () => {
const backgroundColor = useDynamicColor({ dark: "#000", light: "#fff" });
return <SafeAreaView style={[ styles.container, { backgroundColor }]}></SafeAreaView>;
};
const styles = StyleSheet.create({
container: {
flex: 1,
width: width,
height: height,
},
});
const IAPConnection : React.FC<{ children: React.ReactNode }> = ({ children }) => {
const dispatch = useDispatch();
// Set up In-App Purchases (IAP)
const handleIAPBootstrap = useCallback(async () => {
await initConnection();
const products = await getProducts({
skus: config.iap.skus
}).catch(_e => []);
if (!products.length) return;
dispatch(setDonateProducts(products));
}, []);
useEffect(() => {
handleIAPBootstrap();
return () => { endConnection(); };
}, [ handleIAPBootstrap ]);
return <>{ children }</>;
};
export default function App() {
changeNavigationBarColor("#000000", false, false);
useEffect(() => {
SplashScreen.hideAsync();
}, []);
return (
<NavigationContainer theme={DarkTheme}>
<ReduxProvider store={store}>
<PersistGate loading={<ReduxBlocker/>} persistor={persistor}>
<Suspense fallback={LoadingScreen}>
{ Platform.OS === "android" && (
<StatusBar translucent={true} />
)}
<IAPConnection>
<AppNavigator />
</IAPConnection>
</Suspense>
</PersistGate>
</ReduxProvider>
</NavigationContainer>
);
}