Skip to content

Commit 2a80c11

Browse files
committed
feat: add lazy option. fixes facebook#23
1 parent 93b45f2 commit 2a80c11

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

packages/bottom-tabs/src/navigators/createBottomTabNavigator.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import BottomTabBar, { type TabBarOptions } from '../views/BottomTabBar';
1010
import ResourceSavingScene from '../views/ResourceSavingScene';
1111

1212
type Props = InjectedProps & {
13+
lazy?: boolean,
1314
tabBarComponent?: React.ComponentType<*>,
1415
tabBarOptions?: TabBarOptions,
1516
};
@@ -19,6 +20,10 @@ type State = {
1920
};
2021

2122
class TabNavigationView extends React.PureComponent<Props, State> {
23+
static defaultProps = {
24+
lazy: true,
25+
};
26+
2227
static getDerivedStateFromProps(nextProps, prevState) {
2328
const { index } = nextProps.navigation.state;
2429

@@ -87,15 +92,15 @@ class TabNavigationView extends React.PureComponent<Props, State> {
8792
};
8893

8994
render() {
90-
const { navigation, renderScene } = this.props;
95+
const { navigation, renderScene, lazy } = this.props;
9196
const { routes } = navigation.state;
9297
const { loaded } = this.state;
9398

9499
return (
95100
<View style={styles.container}>
96101
<View style={styles.pages}>
97102
{routes.map((route, index) => {
98-
if (!loaded.includes(index)) {
103+
if (lazy && !loaded.includes(index)) {
99104
// Don't render a screen if we've never navigated to it
100105
return null;
101106
}

0 commit comments

Comments
 (0)