mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-02-11 09:20:54 +08:00
feat: add lazy option. fixes #23
This commit is contained in:
@@ -14,9 +14,10 @@
|
||||
"prop-types": "^15.6.0",
|
||||
"react": "16.0.0",
|
||||
"react-native": "0.50.4",
|
||||
"react-lifecycles-compat": "^3.0.4",
|
||||
"react-native-paper": "^1.2.4",
|
||||
"react-native-safe-area-view": "^0.7.0",
|
||||
"react-native-tab-view": "^0.0.74",
|
||||
"react-native-tab-view": "^0.0.78",
|
||||
"react-navigation": "^2.0.0-rc.8"
|
||||
},
|
||||
"devDependencies": {
|
||||
@@ -27,6 +28,8 @@
|
||||
},
|
||||
"main": "App.js",
|
||||
"resolutions": {
|
||||
"**/hoist-non-react-statics": "2.5.0"
|
||||
"**/react-lifecycles-compat": "3.0.4",
|
||||
"**/hoist-non-react-statics": "2.5.0",
|
||||
"**/react-native-tab-view": "0.0.78"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,11 +16,6 @@ module.exports = {
|
||||
return [...dependencies, ...peerDependencies];
|
||||
},
|
||||
getBlacklistRE() {
|
||||
return blacklist([
|
||||
glob(`${path.resolve(__dirname, '..')}/node_modules/*`),
|
||||
glob(`${__dirname}/node_modules/*/{${dependencies.join(',')}}`, {
|
||||
extended: true,
|
||||
}),
|
||||
]);
|
||||
return blacklist([glob(`${path.resolve(__dirname, '..')}/node_modules/*`)]);
|
||||
},
|
||||
};
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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