我正在使用 react-navigation用于路由目的。我想在一个组件上动态隐藏或显示标题。有什么办法吗?
我像这样动态更改 headerLeft 但找不到任何方法来为整个标题执行此操作。
static navigationOptions = ({ navigation }) => ({
headerRight: navigation.state.params ? navigation.state.params.headerRight : null
});
this.props.navigation.setParams({
headerRight: (
<View>
<TouchableOpacity onPress={() => blaa} >
<Text>Start</Text>
</TouchableOpacity>
</View>
)
});
我想要这样的东西 - 基于状态隐藏/显示标题:
this.props.navigation.setParams({
header: this.state.header
});
最佳答案
让它工作:
不知道为什么会这样但路过undefined
to header 将显示默认标题和 null
将隐藏标题。
我正在做这样的事情:
static navigationOptions = ({ navigation }) => ({
header: navigation.state.params ? navigation.state.params.header : undefined
});
和状态变化;
this.props.navigation.setParams({
header: null
});
关于react-native - 在 react-native 中动态隐藏/显示标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44776798/