具有React-Redux和导航实验的无限循环

时间:2016-07-27 18:51:33

标签: react-native react-redux

当我使用react-redux时,我有一个似乎正在发生的无限循环。我使用Navigation Experimental来加载connectRouteScreen作为要通过NavigationCardStack渲染的场景。我正在使用RN 0.30。但也可以在0.31-rc.0中重现这一点

    [...]
    Use Navigation Experimental to transition and load connectRouteScreen as a Scene

    export default function connectRouteScreen(Scene, sceneProps){

      class RouteScreen extends React.Component{

        [...]

        render() {
          const { navigator, pathVariables } = this.props;

          return (
                <View style={styles.container}>
                    <Scene
                navigator={navigator}
              {...pathVariables.toJS()}
                />
                </View>);
        }
      }

        RouteScreen.propTypes = {...RouteScreenPropTypes};

        const routeScreenProperties = extractSceneRendererProps(sceneProps);

    /*return                <Scene
                navigator={routeScreenProperties.navigator}
              {...routeScreenProperties.pathVariables.toJS()}
                />;
    */

      return <RouteScreen
            {...routeScreenProperties}
        />;

    }

LoadingScreen作为“场景”加载。

    @connect(
      () => {return {}},
      (dispatch) => {
        return {
          loginActions: bindActionCreators(loginActions, dispatch),
        }
      })
    export default class LoadingScreen extends React.Component {

      constructor(props){
        super(props);
      }

      shouldComponentUpdate(nextProps){
        return false;
      }

      componentDidMount(){

        const { navigator } = this.props;

        this.props.loginActions.executeLoginFlow();

      }

        render() {
        const Animatable = require('react-native-animatable');
            return (
          <Animatable.View
            animation="pulse"
            easing="ease-out"
            iterationCount="infinite"
            style={localStyle.container}>
            <Icon name="logo" style={localStyle.iconStyle} size={150}/>
          </Animatable.View>
            );
        }

    };

所以,如果我直接返回场景而不是RouteScreen,没问题。 如果我删除@connect语法并转义this.props.loginActions ...,没问题。 如果我返回RouteScreen并删除它所做的一切,只返回Scene =&gt;无限循环。

有人有任何建议如何解决这个问题吗?

0 个答案:

没有答案