Reputation: 185
I'll like to hide the navigation header when clicked on the icon, the code bellow hides the header but do not restore it when search back button is pressed ....
Here is the code:
static navigationOptions = ({ navigation }) => {
const {params} = navigation.state;
return {
title: 'Chats',
titleStyle: {
color: '#ffffff',
},
tintColor: '#ffffff',
headerTintColor: '#ffffff',
headerStyle: {
backgroundColor: "#E6A919"
},
header: navigation.state.params ? navigation.state.params.header : undefined,
headerTitleStyle: {
color: '#ffffff'
},
headerRight: () =>
<TouchableOpacity
onPress={
() => {
navigation.setParams({ header: null });
navigation.setParams({ showSearch: true });
}
}
>
<Icon
style={{ width: 24, height: 24, margin: 15, color: '#ffffff', backgroundColor: 'transparent'}}
name={"search"}
/>
</TouchableOpacity>
}
}
onBackPressed = () => {
console.log("Back pressed!");
this.props.navigation.setParams({ showSearch: false });
this.props.navigation.setParams({ header: true });
this.resetSearchText();
};
What can I do?
Thanks
Upvotes: 0
Views: 184
Reputation: 185
To make it visible again I solved setting 'undefined' to header...
Upvotes: 0
Reputation: 602
This post answers your question.
You're doing right, you just need to add the conditional expression now to return the header only when the navigation.state.params.header
is different of undefined.
Upvotes: 1