Skip to content

Commit

Permalink
feat: add lazy option. fixes facebook#23
Browse files Browse the repository at this point in the history
  • Loading branch information
satya164 committed Aug 18, 2019
1 parent 93b45f2 commit 2a80c11
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand All @@ -19,6 +20,10 @@ type State = {
};

class TabNavigationView extends React.PureComponent<Props, State> {
static defaultProps = {
lazy: true,
};

static getDerivedStateFromProps(nextProps, prevState) {
const { index } = nextProps.navigation.state;

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

render() {
const { navigation, renderScene } = this.props;
const { navigation, renderScene, lazy } = this.props;
const { routes } = navigation.state;
const { loaded } = this.state;

return (
<View style={styles.container}>
<View style={styles.pages}>
{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;
}
Expand Down

0 comments on commit 2a80c11

Please sign in to comment.