Kureev / react-native-side-menu

Side menu component for React Native
MIT License
2.21k stars 436 forks source link

Allow external toggle function #368

Open traviisd opened 5 years ago

traviisd commented 5 years ago

I'm not sure if anyone else experiences this issue, but when the SideMenu is opened and closed via an external trigger, you have to tap the external button again in order for the toggle to work.

I thought this issue was related to https://github.com/facebook/react-native/issues/12784, but everything I tried still resulted in the "toggle" button needing to be pressed twice after close. After debugging, I narrowed it down to this package. When I remove this package, buttons work just fine.

The behavior seems to only happen after the SideMenu is open. The menu closes, but any onPress function does not fire after, until it's pressed again. The internal state of the component updates the isOpen prop on local state.

This proposed change allows an externalToggle (function) be passed in, which fires when the "overlay" component is pressed.

Feedback is greatly appreciated as I don't know if this is a good workaround and/or update to the package. Additionally I'm not well versed with TypeScript.

nickineering commented 4 years ago

I've seen weird stuff where it triggers the event twice, but was able to get it to work without this using just the isOpen and onChange props. onChange just updates the state which is used as isOpen. Then I can just change the state to toggle the menu, but normal menu operation works just fine.