Browse Source

Show splash screen when app not finished loading instead of basic view

keplyx 4 years ago
parent
commit
75ab575322
2 changed files with 31 additions and 25 deletions
  1. 30
    24
      App.js
  2. 1
    1
      app.json

+ 30
- 24
App.js View File

2
 
2
 
3
 import * as React from 'react';
3
 import * as React from 'react';
4
 import {Root, StyleProvider} from 'native-base';
4
 import {Root, StyleProvider} from 'native-base';
5
-import {View} from 'react-native'
6
 import AppNavigator from './navigation/AppNavigator';
5
 import AppNavigator from './navigation/AppNavigator';
7
 import ThemeManager from './utils/ThemeManager';
6
 import ThemeManager from './utils/ThemeManager';
8
 import LocaleManager from './utils/LocaleManager';
7
 import LocaleManager from './utils/LocaleManager';
13
 import {clearThemeCache} from 'native-base-shoutem-theme';
12
 import {clearThemeCache} from 'native-base-shoutem-theme';
14
 import AsyncStorageManager from "./utils/AsyncStorageManager";
13
 import AsyncStorageManager from "./utils/AsyncStorageManager";
15
 import CustomIntroSlider from "./components/CustomIntroSlider";
14
 import CustomIntroSlider from "./components/CustomIntroSlider";
16
-import {Notifications} from 'expo';
15
+import {AppLoading} from 'expo';
17
 import NotificationsManager from "./utils/NotificationsManager";
16
 import NotificationsManager from "./utils/NotificationsManager";
18
 
17
 
19
 type Props = {};
18
 type Props = {};
38
     }
37
     }
39
 
38
 
40
     /**
39
     /**
41
-     * Loads FetchedData before components are mounted, like fonts and themes
42
-     * @returns {Promise}
40
+     * Updates the theme and clears the cache to force reloading the app colors. Need to edit shoutem theme for ti to work
43
      */
41
      */
44
-    async componentWillMount() {
42
+    updateTheme() {
43
+        this.setState({
44
+            currentTheme: ThemeManager.getCurrentTheme()
45
+        });
46
+        clearThemeCache();
47
+    }
48
+
49
+    /**
50
+     * Callback when user ends the intro. Save in preferences to avaoid showing back the slides
51
+     */
52
+    onIntroDone() {
53
+        this.setState({showIntro: false});
54
+        AsyncStorageManager.getInstance().savePref(AsyncStorageManager.getInstance().preferences.showIntro.key, '0');
55
+    }
56
+
57
+    async loadAssetsAsync() {
58
+        console.log('Starting loading assets...');
45
         // Wait for custom fonts to be loaded before showing the app
59
         // Wait for custom fonts to be loaded before showing the app
46
         await Font.loadAsync({
60
         await Font.loadAsync({
47
             'Roboto': require('native-base/Fonts/Roboto.ttf'),
61
             'Roboto': require('native-base/Fonts/Roboto.ttf'),
51
         ThemeManager.getInstance().setUpdateThemeCallback(() => this.updateTheme());
65
         ThemeManager.getInstance().setUpdateThemeCallback(() => this.updateTheme());
52
         await NotificationsManager.initExpoToken();
66
         await NotificationsManager.initExpoToken();
53
         console.log(AsyncStorageManager.getInstance().preferences.expoToken.current);
67
         console.log(AsyncStorageManager.getInstance().preferences.expoToken.current);
68
+    }
69
+
70
+    onLoadFinished() {
54
         // Only show intro if this is the first time starting the app
71
         // Only show intro if this is the first time starting the app
72
+        console.log('Finished loading');
55
         this.setState({
73
         this.setState({
56
             isLoading: false,
74
             isLoading: false,
57
             currentTheme: ThemeManager.getCurrentTheme(),
75
             currentTheme: ThemeManager.getCurrentTheme(),
61
     }
79
     }
62
 
80
 
63
     /**
81
     /**
64
-     * Updates the theme and clears the cache to force reloading the app colors. Need to edit shoutem theme for ti to work
65
-     */
66
-    updateTheme() {
67
-        this.setState({
68
-            currentTheme: ThemeManager.getCurrentTheme()
69
-        });
70
-        clearThemeCache();
71
-    }
72
-
73
-    /**
74
-     * Callback when user ends the intro. Save in preferences to avaoid showing back the slides
75
-     */
76
-    onIntroDone() {
77
-        this.setState({showIntro: false});
78
-        AsyncStorageManager.getInstance().savePref(AsyncStorageManager.getInstance().preferences.showIntro.key, '0');
79
-    }
80
-
81
-    /**
82
      * Renders the app based on loading state
82
      * Renders the app based on loading state
83
      */
83
      */
84
     render() {
84
     render() {
85
         if (this.state.isLoading) {
85
         if (this.state.isLoading) {
86
-            return <View/>;
86
+            return (
87
+                <AppLoading
88
+                    startAsync={this.loadAssetsAsync}
89
+                    onFinish={() => this.onLoadFinished()}
90
+                    onError={console.warn}
91
+                />
92
+            );
87
         }
93
         }
88
         if (this.state.showIntro) {
94
         if (this.state.showIntro) {
89
             return <CustomIntroSlider onDone={() => this.onIntroDone()}/>;
95
             return <CustomIntroSlider onDone={() => this.onIntroDone()}/>;

+ 1
- 1
app.json View File

10
       "android",
10
       "android",
11
       "web"
11
       "web"
12
     ],
12
     ],
13
-    "version": "0.0.9",
13
+    "version": "0.0.10",
14
     "orientation": "portrait",
14
     "orientation": "portrait",
15
     "primaryColor": "#be1522",
15
     "primaryColor": "#be1522",
16
     "icon": "./assets/android.icon.png",
16
     "icon": "./assets/android.icon.png",

Loading…
Cancel
Save