【发布时间】: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