You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In many applications, you need to load data from API before displaying any content.
7
-
To do that, we built a solid navigation based on a splash screen to load data before the content shows, and [inline require](https://reactnative.dev/docs/ram-bundles-inline-requires#inline-requires) to improve performance.
7
+
To do that, we built a solid navigation based on a splash screen to load data before the content shows.
8
8
9
9
---
10
10
@@ -25,93 +25,48 @@ const App = () => (
25
25
)
26
26
```
27
27
28
-
What is new here is into the `ApplicationNavigator` component :
28
+
Nothing new into the `Navigators/Application` component too :
So the root navigator is a stack with two screens :
72
-
- the splash screen (`IndexStartupContainer`),
73
-
- a second navigator (`MainNavigator`).
74
-
75
-
The main goal of the `ApplicationNavigator` is to only have one screen (the `IndexStartupContainer`) to load.
76
-
And, when the application finish loading, then fetch and display the `MainNavigator`.
77
-
In other words, when `ApplicationNavigator` is mounted, it only can display the `IndexStartupContainer` because the `MainNavigator` isn't loaded and imported yet.
78
-
In the `StartupContainer`, the redux action which is used to load data on init application is trigger and when the action is finish, the state `state.startup.initialize.loading` turns `true`.
79
-
when this state is true, in the useEffect the `MainNavigator` navigator is imported , the navigation navigate and reset to a screen of the `MainNavigator`.
80
-
81
-
To conclude, all new screens have to be added to `MainNavigator`. The `ApplicationNavigator` increase startup performance thanks to inline require and provides a splash screen to load your data.
57
+
It just contains some requirement like the `SafeAreaView` for ios,
58
+
the `NavigationContainer` bound with a ref to use utils contained in `Navigators/utils`
82
59
83
60
## How to load data before app open ❓
84
61
85
-
To have a great separation of concerns, all API call are make into Services. In the above section, it said that in `IndexStartupContainer`, a redux action is triggered. This action is `InitializeStartupAction` :
62
+
In `StartupContainer`, the `init` function is where you can crete asynchronous tasks like fetching data
86
63
87
64
```javascript
88
-
useEffect(() => {
89
-
dispatch(InitStartup.action())
90
-
}, [dispatch])
91
-
```
92
-
93
-
In redux, triggering an action lead to an associated reducer and in most cases the action pass trough a middleware.
94
-
All the logic can be found at `Stores/Startup/Init.js`.
// Here you can add asynchronous/synchronous tasks
68
+
navigateAndSimpleReset('Main')
113
69
}
114
70
```
115
71
116
-
All stores are based on redux-toolkit to simplify the process of API calls by using the `createAsyncThunk` function (hidden by the `buildAction` action which is a store builder function).
117
-
So, to load data on splash screen you just have to add dispatched action in the buildAction like `FetchOne` and `DefaultTheme` in the above example.
72
+
This function is called when the StartupContainer is mounted.
0 commit comments