componentWillReceiveProps(nextProps: Props): void { if (nextProps.navigationState !== this.props.navigationState) { this.setState({ scenes: NavigationScenesReducer( this.state.scenes, nextProps.navigationState, this.props.navigationState ), }); } }
constructor(props: Props, context: any) { super(props, context); // The initial layout isn't measured. Measured layout will be only available // when the component is mounted. const layout = { height: new Animated.Value(0), initHeight: 0, initWidth: 0, isMeasured: false, width: new Animated.Value(0), }; this.state = { layout, position: new Animated.Value(this.props.navigationState.index), scenes: NavigationScenesReducer([], this.props.navigationState), }; }
constructor(props: Props, context: any) { super(props, context); // The initial layout isn't measured. Measured layout will be only available // when the component is mounted. const layout = { height: new Animated.Value(0), initHeight: 0, initWidth: 0, isMeasured: false, width: new Animated.Value(0), }; this.state = { layout, position: new Animated.Value(this.props.navigationState.index), // This `progress` is a adummy placeholder value to meet the values // as `NavigationSceneRendererProps` requires. progress: new Animated.Value(1), scenes: NavigationScenesReducer([], this.props.navigationState), }; }
routes.forEach((nextState) => { scenes = NavigationScenesReducer(scenes, nextState, prevState); prevState = nextState; });
componentWillReceiveProps(nextProps: Props): void { const nextScenes = NavigationScenesReducer( this.state.scenes, nextProps.navigationState, this.props.navigationState ); if (nextScenes === this.state.scenes) { return; } const nextState = { ...this.state, scenes: nextScenes, }; const { position, progress, } = nextState; progress.setValue(0); this._prevTransitionProps = this._transitionProps; this._transitionProps = buildTransitionProps(nextProps, nextState); // get the transition spec. const transitionUserSpec = nextProps.configureTransition ? nextProps.configureTransition( this._transitionProps, this._prevTransitionProps, ) : null; const transitionSpec = { ...DefaultTransitionSpec, ...transitionUserSpec, }; const {timing} = transitionSpec; delete transitionSpec.timing; const animations = [ timing( progress, { ...transitionSpec, toValue: 1, }, ), ]; if (nextProps.navigationState.index !== this.props.navigationState.index) { animations.push( timing( position, { ...transitionSpec, toValue: nextProps.navigationState.index, }, ), ); } // update scenes and play the transition this.setState(nextState, () => { nextProps.onTransitionStart && nextProps.onTransitionStart( this._transitionProps, this._prevTransitionProps, ); Animated.parallel(animations).start(this._onTransitionEnd); }); }