-
Notifications
You must be signed in to change notification settings - Fork 2
/
AppLoader.tsx
136 lines (123 loc) · 3.46 KB
/
AppLoader.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import { Ionicons } from "@expo/vector-icons";
import Colors from "constants/Colors";
import * as Font from "expo-font";
import * as ExpoSplashScreen from "expo-splash-screen";
import * as React from "react";
import { Animated, View, StyleSheet, Text, Image } from "react-native";
ExpoSplashScreen.preventAutoHideAsync().catch(() => {});
interface Props {
children?: React.ReactNode;
}
export default function AppLoader({ children }: Props) {
const animation = React.useMemo(() => new Animated.Value(0), []);
const [isAppReady, setAppReady] = React.useState(false);
const [isSplashAnimationComplete, setAnimationComplete] =
React.useState(false);
const font = "main-font-bold";
React.useEffect(() => {
// Once everything is loaded, run animation
if (isAppReady && Font.isLoaded(font)) {
Animated.timing(animation, {
toValue: 1,
duration: 1500,
useNativeDriver: true,
}).start(() => setTimeout(() => setAnimationComplete(true), 1500));
}
}, [isAppReady]);
React.useEffect(() => {
// Load data
async function loadResourcesAndDataAsync() {
try {
// Load fonts
await Font.loadAsync({
...Ionicons.font,
"secondary-font": require("../assets/fonts/BAHNSCHRIFT.ttf"),
"main-font-bold": require("../assets/fonts/MyriadProBoldCondensed.ttf"),
"main-font": require("../assets/fonts/MyriadProCondensed.ttf"),
});
} catch (e) {
// We might want to provide this error information to an error reporting service
console.warn(e);
// FIX ger error i expo
}
}
loadResourcesAndDataAsync();
}, []);
const onImageLoaded = async () => {
try {
// Hide static splash screen
await ExpoSplashScreen.hideAsync();
} catch (e) {
console.warn(e);
} finally {
setAppReady(true);
}
};
const animationStyles = {
opacity: animation,
};
const fontStyles = {
fontFamily: font,
};
// Temporrarly disable splash screen when in DEVELOPMENT mode
// If not disabled the mobile test application of Expo Go wont work
if (__DEV__) {
return <View style={styles.container}>{children}</View>;
}
return (
<View style={styles.container}>
{isAppReady && children}
{!isSplashAnimationComplete && (
<View
pointerEvents="none"
style={[
StyleSheet.absoluteFill,
{
backgroundColor: Colors.arkadNavy,
},
]}
>
<Animated.View style={[styles.animatedContainer, animationStyles]}>
<Image
style={styles.logo}
source={require("../assets/images/splash.png")}
onLoadEnd={onImageLoaded}
fadeDuration={0}
/>
{Font.isLoaded(font) && (
<Text
style={[styles.title, fontStyles]}
numberOfLines={1}
adjustsFontSizeToFit
>
Welcome to ARKAD
</Text>
)}
</Animated.View>
</View>
)}
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
animatedContainer: {
width: "100%",
height: "100%",
alignItems: "center",
justifyContent: "center",
},
logo: {
width: "100%",
height: "100%",
resizeMode: "contain",
},
title: {
position: "absolute",
alignSelf: "center",
color: Colors.white,
fontSize: 30,
},
});