0

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

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks! worked to hide the header... but how do I restore it when pressing back button? Code has been modified on the question....
You're welcome! I'm glad I could help you!
0

To make it visible again I solved setting 'undefined' to header...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.