From 2a80c116919be9606c9f564ee82e83851b0928f0 Mon Sep 17 00:00:00 2001 From: Satyajit Sahoo Date: Thu, 24 May 2018 14:13:56 +0200 Subject: [PATCH] feat: add lazy option. fixes #23 --- .../src/navigators/createBottomTabNavigator.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/bottom-tabs/src/navigators/createBottomTabNavigator.js b/packages/bottom-tabs/src/navigators/createBottomTabNavigator.js index e83106637b3456..383a44e1d0d714 100644 --- a/packages/bottom-tabs/src/navigators/createBottomTabNavigator.js +++ b/packages/bottom-tabs/src/navigators/createBottomTabNavigator.js @@ -10,6 +10,7 @@ import BottomTabBar, { type TabBarOptions } from '../views/BottomTabBar'; import ResourceSavingScene from '../views/ResourceSavingScene'; type Props = InjectedProps & { + lazy?: boolean, tabBarComponent?: React.ComponentType<*>, tabBarOptions?: TabBarOptions, }; @@ -19,6 +20,10 @@ type State = { }; class TabNavigationView extends React.PureComponent { + static defaultProps = { + lazy: true, + }; + static getDerivedStateFromProps(nextProps, prevState) { const { index } = nextProps.navigation.state; @@ -87,7 +92,7 @@ class TabNavigationView extends React.PureComponent { }; render() { - const { navigation, renderScene } = this.props; + const { navigation, renderScene, lazy } = this.props; const { routes } = navigation.state; const { loaded } = this.state; @@ -95,7 +100,7 @@ class TabNavigationView extends React.PureComponent { {routes.map((route, index) => { - if (!loaded.includes(index)) { + if (lazy && !loaded.includes(index)) { // Don't render a screen if we've never navigated to it return null; }