-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
89 lines (77 loc) · 1.96 KB
/
Copy pathApp.js
File metadata and controls
89 lines (77 loc) · 1.96 KB
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
import React from "react";
import "react-native-gesture-handler";
import { Asset } from "expo-asset";
import { AppLoading } from "expo";
import { StyleSheet } from "react-native";
import { NavigationContainer } from "@react-navigation/native";
import StackScreen from "./screens/stack";
import { enableScreens } from "react-native-screens";
import { decode, encode } from "base-64";
import { YellowBox } from "react-native";
import _ from "lodash";
// Fix cannot find atob warning
if (!global.btoa) {
global.btoa = encode;
}
if (!global.atob) {
global.atob = decode;
}
// Fix setting a timer warning
YellowBox.ignoreWarnings(["Setting a timer"]);
const _console = _.clone(console);
console.warn = (message) => {
if (message.indexOf("Setting a timer") <= -1) {
_console.warn(message);
}
};
// Enable perf optimisation
enableScreens();
export default class App extends React.Component {
constructor() {
super();
this.state = {
// Check for preloading of assets
isReady: false,
};
}
// Fetch assets before showing app
async _loadAssetsAsync() {
const imageAssets = cacheImages([require("./assets/background/bg.jpg")]);
await Promise.all([...imageAssets]);
}
measureView = (event) => {
this.setState({ boardWidth: event.nativeEvent.layout.width });
};
render() {
if (!this.state.isReady) {
return (
<AppLoading
startAsync={this._loadAssetsAsync}
onFinish={() => this.setState({ isReady: true })}
onError={console.warn}
/>
);
}
return (
<NavigationContainer>
<StackScreen />
</NavigationContainer>
);
}
}
// Function to cache images
function cacheImages(images) {
return images.map((image) => {
if (typeof image === "string") {
return Image.prefetch(image);
} else {
return Asset.fromModule(image).downloadAsync();
}
});
}
const styles = StyleSheet.create({
container: {
margin: 20,
flex: 1,
},
});