Browse Source

Fix crash on app start

Arnaud Vergnet 1 year ago
parent
commit
f5233c53f8

+ 3
- 3
App.tsx View File

@@ -55,7 +55,7 @@ type StateType = {
55 55
   currentTheme: ReactNativePaper.Theme | undefined;
56 56
 };
57 57
 
58
-export default class App extends React.Component<null, StateType> {
58
+export default class App extends React.Component<{}, StateType> {
59 59
   navigatorRef: {current: null | NavigationContainerRef};
60 60
 
61 61
   defaultHomeRoute: string | null;
@@ -64,8 +64,8 @@ export default class App extends React.Component<null, StateType> {
64 64
 
65 65
   urlHandler: URLHandler;
66 66
 
67
-  constructor() {
68
-    super(null);
67
+  constructor(props: {}) {
68
+    super(props);
69 69
     this.state = {
70 70
       isLoading: true,
71 71
       showIntro: true,

+ 5
- 1
src/navigation/MainNavigator.tsx View File

@@ -284,5 +284,9 @@ type PropsType = {
284 284
 };
285 285
 
286 286
 export default function MainNavigator(props: PropsType) {
287
-  return <MainStackComponent createTabNavigator={() => TabNavigator(props)} />;
287
+  return (
288
+    <MainStackComponent
289
+      createTabNavigator={() => <TabNavigator {...props} />}
290
+    />
291
+  );
288 292
 }

+ 48
- 40
src/navigation/TabNavigator.tsx View File

@@ -142,7 +142,7 @@ function HomeStackComponent(
142 142
   defaultData: {[key: string]: string},
143 143
 ) {
144 144
   let params;
145
-  if (initialRoute != null) {
145
+  if (initialRoute) {
146 146
     params = {data: defaultData, nextScreen: initialRoute, shouldOpen: true};
147 147
   }
148 148
   const {colors} = useTheme();
@@ -255,45 +255,53 @@ type PropsType = {
255 255
   defaultHomeData: {[key: string]: string};
256 256
 };
257 257
 
258
-export default function TabNavigator(props: PropsType) {
259
-  let defaultRoute = 'home';
260
-  if (!props.defaultHomeRoute) {
261
-    defaultRoute = AsyncStorageManager.getString(
262
-      AsyncStorageManager.PREFERENCES.defaultStartScreen.key,
263
-    ).toLowerCase();
258
+export default class TabNavigator extends React.Component<PropsType> {
259
+  defaultRoute: string;
260
+  createHomeStackComponent: () => any;
261
+
262
+  constructor(props: PropsType) {
263
+    super(props);
264
+    this.defaultRoute = 'home';
265
+    if (!props.defaultHomeRoute) {
266
+      this.defaultRoute = AsyncStorageManager.getString(
267
+        AsyncStorageManager.PREFERENCES.defaultStartScreen.key,
268
+      ).toLowerCase();
269
+    }
270
+    this.createHomeStackComponent = () =>
271
+      HomeStackComponent(props.defaultHomeRoute, props.defaultHomeData);
264 272
   }
265
-  const createHomeStackComponent = () =>
266
-    HomeStackComponent(props.defaultHomeRoute, props.defaultHomeData);
267 273
 
268
-  return (
269
-    <Tab.Navigator
270
-      initialRouteName={defaultRoute}
271
-      tabBar={(tabProps) => <CustomTabBar {...tabProps} />}>
272
-      <Tab.Screen
273
-        name="services"
274
-        component={ServicesStackComponent}
275
-        options={{title: i18n.t('screens.services.title')}}
276
-      />
277
-      <Tab.Screen
278
-        name="proxiwash"
279
-        component={ProxiwashStackComponent}
280
-        options={{title: i18n.t('screens.proxiwash.title')}}
281
-      />
282
-      <Tab.Screen
283
-        name="home"
284
-        component={createHomeStackComponent}
285
-        options={{title: i18n.t('screens.home.title')}}
286
-      />
287
-      <Tab.Screen
288
-        name="planning"
289
-        component={PlanningStackComponent}
290
-        options={{title: i18n.t('screens.planning.title')}}
291
-      />
292
-      <Tab.Screen
293
-        name="planex"
294
-        component={PlanexStackComponent}
295
-        options={{title: i18n.t('screens.planex.title')}}
296
-      />
297
-    </Tab.Navigator>
298
-  );
274
+  render() {
275
+    return (
276
+      <Tab.Navigator
277
+        initialRouteName={this.defaultRoute}
278
+        tabBar={(tabProps) => <CustomTabBar {...tabProps} />}>
279
+        <Tab.Screen
280
+          name="services"
281
+          component={ServicesStackComponent}
282
+          options={{title: i18n.t('screens.services.title')}}
283
+        />
284
+        <Tab.Screen
285
+          name="proxiwash"
286
+          component={ProxiwashStackComponent}
287
+          options={{title: i18n.t('screens.proxiwash.title')}}
288
+        />
289
+        <Tab.Screen
290
+          name="home"
291
+          component={this.createHomeStackComponent}
292
+          options={{title: i18n.t('screens.home.title')}}
293
+        />
294
+        <Tab.Screen
295
+          name="planning"
296
+          component={PlanningStackComponent}
297
+          options={{title: i18n.t('screens.planning.title')}}
298
+        />
299
+        <Tab.Screen
300
+          name="planex"
301
+          component={PlanexStackComponent}
302
+          options={{title: i18n.t('screens.planex.title')}}
303
+        />
304
+      </Tab.Navigator>
305
+    );
306
+  }
299 307
 }

+ 2
- 2
src/screens/About/AboutDependenciesScreen.tsx View File

@@ -53,8 +53,8 @@ const LIST_ITEM_HEIGHT = 64;
53 53
 export default class AboutDependenciesScreen extends React.Component<{}> {
54 54
   data: Array<ListItemType>;
55 55
 
56
-  constructor() {
57
-    super({});
56
+  constructor(props: {}) {
57
+    super(props);
58 58
     this.data = generateListFromObject(packageJson.dependencies);
59 59
   }
60 60
 

+ 2
- 2
src/screens/Amicale/AmicaleContactScreen.tsx View File

@@ -38,8 +38,8 @@ class AmicaleContactScreen extends React.Component<{}> {
38 38
   // Dataset containing information about contacts
39 39
   CONTACT_DATASET: Array<DatasetItemType>;
40 40
 
41
-  constructor() {
42
-    super({});
41
+  constructor(props: {}) {
42
+    super(props);
43 43
     this.CONTACT_DATASET = [
44 44
       {
45 45
         name: i18n.t('screens.amicaleAbout.roles.interSchools'),

+ 2
- 2
src/screens/Home/ScannerScreen.tsx View File

@@ -55,8 +55,8 @@ const styles = StyleSheet.create({
55 55
 type PermissionResults = 'unavailable' | 'denied' | 'blocked' | 'granted';
56 56
 
57 57
 class ScannerScreen extends React.Component<{}, StateType> {
58
-  constructor() {
59
-    super({});
58
+  constructor(props: {}) {
59
+    super(props);
60 60
     this.state = {
61 61
       hasPermission: false,
62 62
       scanned: false,

Loading…
Cancel
Save