mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-04-29 04:45:19 +08:00
feat: add lazy option. fixes #23
This commit is contained in:
committed by
satyajit.happy
parent
93b45f22b9
commit
2a80c11691
@@ -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<Props, State> {
|
||||
static defaultProps = {
|
||||
lazy: true,
|
||||
};
|
||||
|
||||
static getDerivedStateFromProps(nextProps, prevState) {
|
||||
const { index } = nextProps.navigation.state;
|
||||
|
||||
@@ -87,7 +92,7 @@ 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;
|
||||
|
||||
@@ -95,7 +100,7 @@ class TabNavigationView extends React.PureComponent<Props, State> {
|
||||
<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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user