【问题标题】:React Native NavigationExperimental Redux renderScene is executed just once and does not refresh updated propsReact Native NavigationExperimental Redux renderScene 只执行一次,不会刷新更新的 props
【发布时间】:2016-05-26 10:17:29
【问题描述】:

我正在尝试在 React Native 中实现 NavigationExperimental。 我有一个 onChangeTab 函数,它通过 Redux 将标题发送到 AppContainer。 我让它工作了,但由于某种原因,renderOverlay 正在重新渲染和更新标题,但 renderScene 只执行一次。

请看下面代码中的cmets:

class AppContainer extends React.Component {    
  render() {
    return (
      <NavigationCardStack
        navigationState={this.props.navigationState}
        onNavigate={this.props.onNavigate}
        renderOverlay={props => {
           // Here title updates and executes every time I change to another tab. 
           console.log(props.navigationState.title, 'title');
           return (
               <Text>{props.navigationState.title || 'Title'}</Text>
           )
        }}
        renderScene={(props) => {
          // Here does not change because it is executed just one.
          console.log(props.navigationState.title, 'title');
              return (
                <View>
                  <View style={styles.appbar}>
                    <Text style={styles.title}>{props.navigationState.title || 'Title'}</Text>
                  </View>
                  <View>
                    <TabsView />
                  </View>
                </View>
              )
        }}
      />
    )
  }
}

const mapStateToProps = (state) => {
  // Here title updates every time I change to another tab.
  console.log(state.navigationState.title);
  return {
    navigationState: state.navigationState
  }
}

const mapDispatchToProps = (dispatch) => {
  return {
    onNavigate: (action) => {
      if (action.type && (
        action.type === NavigationRootContainer.getBackAction().type ||
        action.type === NavigationCard.CardStackPanResponder.Actions.BACK.type)
      ) {
        dispatch(navigatePop())
      } else {
        dispatch(navigatePush(action))
      }
    }
  }
}

export default connect(
  mapStateToProps,
  mapDispatchToProps
)(AppContainer)

这是我的减速器:

function navigationState(state = initialNavState, action) {
    switch (action.type) {
        case TITLE_PUSH:
            return {
                ...state,
                title: action.title
            }
        ...

【问题讨论】:

    标签: reactjs react-native redux react-redux


    【解决方案1】:

    github上有问题。

    https://github.com/facebook/react-native/issues/7720

    由于最近提交了 react native repo,如果你的 navigationState 没有改变,他不会重新渲染。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-07
      • 1970-01-01
      • 2017-10-20
      • 1970-01-01
      • 1970-01-01
      • 2017-11-04
      • 1970-01-01
      • 2021-08-23
      相关资源
      最近更新 更多