Skip to content

Commit

Permalink
MainScreenWithTabs: Use router static, pass navigation prop.
Browse files Browse the repository at this point in the history
This is the recommended thing to do when it's necessary to defy
react-navigation's warnings [1] against "explicitly rendering more
than one navigator". In the upcoming react-navigation v2 -> v3
upgrade, this would otherwise produce a crashing error; see
discussion [2].

[1] https://reactnavigation.org/docs/2.x/common-mistakes/#explicitly-rendering-more-than-one-navigator
[2] https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/Dynamic.20routes.20in.20react-navigation/near/1008268
  • Loading branch information
chrisbobbe committed Sep 17, 2020
1 parent 88350af commit f4b8253
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/main/MainScreenWithTabs.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
/* @flow strict-local */
import React, { PureComponent } from 'react';
import { View } from 'react-native';
import type { NavigationScreenProp } from 'react-navigation';

import type { ThemeData } from '../styles';
import styles, { ThemeContext } from '../styles';
import { OfflineNotice, ZulipStatusBar } from '../common';
import MainTabs from './MainTabs';

export default class MainScreenWithTabs extends PureComponent<{||}> {
type Props = $ReadOnly<{|
navigation: NavigationScreenProp<>,
|}>;

export default class MainScreenWithTabs extends PureComponent<Props> {
static router = MainTabs.router;

static contextType = ThemeContext;
context: ThemeData;

Expand All @@ -16,7 +23,7 @@ export default class MainScreenWithTabs extends PureComponent<{||}> {
<View style={[styles.flexed, { backgroundColor: this.context.backgroundColor }]}>
<ZulipStatusBar />
<OfflineNotice />
<MainTabs />
<MainTabs navigation={this.props.navigation} />
</View>
);
}
Expand Down

0 comments on commit f4b8253

Please sign in to comment.