Skip to content

Commit 0b50fe1

Browse files
authored
update React Native and its dependencies + RTKQuery (#236)
1 parent 6abe8ec commit 0b50fe1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+2811
-5124
lines changed

.github/workflows/CI.yml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@ on:
88
- '*'
99

1010
jobs:
11-
install-lint-test-type:
11+
install-lint-test:
1212
runs-on: ubuntu-latest
1313
steps:
1414
- uses: actions/checkout@v2
1515
- name: Install yarn dependencies
1616
run: |
1717
cd template
1818
yarn install
19-
yarn add -D typescript @types/jest @types/react @types/react-native @types/react-test-renderer @types/fbemitter @types/react-redux
2019
- name: Run linters
2120
run: |
2221
cd template
@@ -28,8 +27,3 @@ jobs:
2827
cd template
2928
cp src/Config/index.example.js src/Config/index.js
3029
yarn test
31-
- name: Run type check
32-
run: |
33-
cd template
34-
cp plugins/typescript/template/tsconfig.dev.json plugins/typescript/template/tsconfig.json
35-
yarn type-check

documentation/docs/3_Guides/3_1_Theme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ It helps with variables and reusable classes to create harmony between applicati
1111
The boilerplate provides a custom hook called `useTheme` and you can use it like the example bellow:
1212

1313
```jsx
14-
import { useTheme } from '@/Theme'
14+
import { useTheme } from '@/Hooks'
1515

1616
const Brand = ({ height = 200, width = 200, mode = 'contain' }) => {
1717
const {

documentation/docs/3_Guides/3_2_ThemesAndDarkMode.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,15 @@ That's it ! now you can use the `ChangeTheme` action to set the theme in a conta
8989
import React, { useState } from 'react'
9090
import { useDispatch, useSelector } from 'react-redux'
9191
import { View, Button } from 'react-native'
92-
import { useTheme } from '@/Theme'
93-
import ChangeTheme from '@/Store/Theme/ChangeTheme'
92+
import { useTheme } from '@/Hooks'
93+
import { changeTheme } from '@/Store/Theme'
9494

9595
const IndexExampleContainer = () => {
9696
const { Common, Fonts, Gutters, Layout } = useTheme()
9797
const dispatch = useDispatch()
9898

9999
const changeTheme = ({ theme, darkMode }) => {
100-
dispatch(ChangeTheme.action({ theme, darkMode }))
100+
dispatch(changeTheme({ theme, darkMode }))
101101
}
102102

103103
return (

documentation/docs/3_Guides/3_3_SplashScreenLoadingData.md

Lines changed: 19 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: Splash screen & loading data 💾
44
---
55

66
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.
88

99
---
1010

@@ -25,93 +25,48 @@ const App = () => (
2525
)
2626
```
2727

28-
What is new here is into the `ApplicationNavigator` component :
28+
Nothing new into the `Navigators/Application` component too :
2929

3030
```jsx
3131
const Stack = createStackNavigator()
3232

33-
let MainNavigator
34-
3533
// @refresh reset
3634
const ApplicationNavigator = () => {
3735
const { Layout, darkMode, NavigationTheme } = useTheme()
3836
const { colors } = NavigationTheme
39-
const [isApplicationLoaded, setIsApplicationLoaded] = useState(false)
40-
const applicationIsLoading = useSelector((state) => state.startup.loading)
41-
42-
useEffect(() => {
43-
if (MainNavigator == null && !applicationIsLoading) {
44-
MainNavigator = require('@/Navigators/Main').default
45-
setIsApplicationLoaded(true)
46-
}
47-
}, [applicationIsLoading])
4837

4938
return (
5039
<SafeAreaView style={[Layout.fill, { backgroundColor: colors.card }]}>
5140
<NavigationContainer theme={NavigationTheme} ref={navigationRef}>
5241
<StatusBar barStyle={darkMode ? 'light-content' : 'dark-content'} />
53-
<Stack.Navigator headerMode={'none'}>
54-
<Stack.Screen name="Startup" component={IndexStartupContainer} />
55-
{isApplicationLoaded && (
56-
<Stack.Screen
57-
name="Main"
58-
component={MainNavigator}
59-
options={{
60-
animationEnabled: false,
61-
}}
62-
/>
63-
)}
42+
<Stack.Navigator screenOptions={{ headerShown: false }}>
43+
<Stack.Screen name="Startup" component={StartupContainer} />
44+
<Stack.Screen
45+
name="Main"
46+
component={MainNavigator}
47+
options={{
48+
animationEnabled: false,
49+
}}
50+
/>
6451
</Stack.Navigator>
6552
</NavigationContainer>
6653
</SafeAreaView>
6754
)
6855
}
6956
```
70-
71-
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`
8259

8360
## How to load data before app open ❓
8461

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
8663

8764
```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`.
95-
96-
```javascript
97-
import { buildAction, buildReducers } from '@/Store/builder'
98-
import FetchOne from '@/Store/User/FetchOne'
99-
100-
export default {
101-
initialState: { loading: false, error: null },
102-
action: buildAction('startup/init', async (args, { dispatch }) => {
103-
// Timeout to fake waiting some process
104-
// Remove it, or keep it if you want display a beautiful splash screen ;)
105-
await new Promise((resolve) => setTimeout(resolve, 1000))
106-
// Here we load the user 1 for example, but you can for example load the connected user
107-
await dispatch(FetchOne.action(1))
108-
await dispatch(DefaultTheme.action({ theme: 'default', darkMode: null }))
109-
// Navigate and reset to the main navigator
110-
navigateAndSimpleReset('Main')
111-
}),
112-
reducers: buildReducers({ itemKey: null }), // We do not want to modify some item by default
65+
const init = async () => {
66+
await setDefaultTheme({ theme: 'default', darkMode: null })
67+
// Here you can add asynchronous/synchronous tasks
68+
navigateAndSimpleReset('Main')
11369
}
11470
```
11571

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

Comments
 (0)