-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo-81-expo-no-nativebase.js
72 lines (61 loc) · 1.97 KB
/
demo-81-expo-no-nativebase.js
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
// This demo uses React Navigation
// We use React Navigation to manage navigation between screens in our App
import React, { Component } from 'react';
import { View, Text } from 'react-native';
import * as SplashScreen from 'expo-splash-screen';
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
import AsyncStorage from '@react-native-async-storage/async-storage';
// break your screens out to separate pages for readability
import Book from './app/book';
import Home from './app/home';
import API from './app/api';
// this always needs to be in your App.js file for react navigation
const Stack = createStackNavigator();
export default class App extends Component {
state = {
appIsReady: false,
}
async componentDidMount() {
// Prevent native splash screen from autohiding
try {
await SplashScreen.preventAutoHideAsync();
} catch (e) {
console.warn(e);
}
this.prepareResources();
// Use the line below to empty local storage while testing
//AsyncStorage.removeItem('@favourite_books');
}
// method to load resources and make API calls for splashscreen
prepareResources = async () => {
try {
await performAPICalls();
await downloadAssets();
} catch (e) {
console.warn(e);
} finally {
this.setState({ appIsReady: true }, async () => {
await SplashScreen.hideAsync();
});
}
};
render(){
if (!this.state.appIsReady) {
return null
}
return (
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen name="Home" component={Home} />
<Stack.Screen name="API" component={API} />
<Stack.Screen name="Book" component={Book} />
</Stack.Navigator>
</NavigationContainer>
);
}
}
// Put any code you need to prepare your app in these functions
// for splashscreen
async function performAPICalls() {}
async function downloadAssets() {}