【发布时间】:2018-04-02 11:49:06
【问题描述】:
我的 StackNavigator 的 navigationOptions 是:--
static navigationOptions = ({navigation}) => {
return ({
headerRight: (
(navigation.state.params.actionTitle)?
<TouchableOpacity style={{padding: 10}} onPress={() => navigation.state.params.onPressDelete()}>
<Text style={{
fontSize: 16,
color: Colors.primaryText
}}>{navigation.state.params.actionTitle}</Text>
</TouchableOpacity>:null
)
})
};
navigation.state.params.actionTitle 默认未定义。所以在页面上它不会显示 headerRight 视图。我想根据 redux 的一些网络响应显示 headerRight 视图。我正在处理 componentWillReceiveProps 部分中的 redux 数据。
但是从 componentWillReceiveProps 如果我尝试更改 actionTitle 则会发生递归并且整个 UI 被阻塞。通过递归,我的意思是 componentWillReceiveProps 被重复调用。我正在使用以下方式设置导航状态:--
componentWillReceiveProps(props){
this.props.navigation.setParams({
actionTitle : "Delete"
});
}
我在这里做错了什么?
【问题讨论】:
标签: react-native