Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Status of React Navigation drawer? (open or closed)

I'm building a drawer with React Navigation and want to perform some logic if the user closes the drawer. I don't see anything obvious in the documentation that will allow me to do this. Is anyone aware of a way to do this?

like image 957
callmetwan Avatar asked Jun 15 '17 18:06

callmetwan


People also ask

What is the difference between react navigation and react navigation?

TL;DR: React Navigation has a declarative API with built-in hooks, while React Native Navigation has imperative APIs with a community library for Hooks. React has changed how we think about interface development.

Is react navigation deprecated?

This version has been deprecated This version of React Navigation is no longer supported.


1 Answers

Now in react navigation 5 you can directly access the status of your drawer using this approach :

useIsDrawerOpen() is a Hook to detect if the drawer is open in a parent navigator.

For exemple in your view you can test if your drawer is open or not directly using this approach :

import { useIsDrawerOpen } from '@react-navigation/drawer';

const MainContainer = () => {
   return (
    <View style={(useIsDrawerOpen()) ? styles.conatinerOpenStyle : styles.containerClosedStyle}>
        <Text>{console.log("Test drawer  "+useIsDrawerOpen())}</Text>

    </View>
);}
like image 142
Ahlem Jarrar Avatar answered Oct 16 '22 12:10

Ahlem Jarrar