Kureev / react-native-side-menu

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

Please add an example of controlling menu state through an external component. #63

Closed KevinGrandon closed 9 years ago

KevinGrandon commented 9 years ago

I have a button which I would like to control the menu with, but I'm not sure of the suggested way to open/collapse the menu from an external component. Is there a way to get the ref and call a .toggle() on the menu?

Edit - seems the solution is pretty simple, you just need something like:

<SideMenu
      ref='slideMenu'
      menu={menu}>

this.refs.slideMenu.toggleMenu();

I would still recommend putting something into the README about this.

jordangarcia commented 9 years ago

All children of the SideMenu are passed menuActions as props so if its a child / descendent it can use this.props.menuAction.toggleMenu

https://github.com/Kureev/react-native-side-menu/blob/master/index.js#L249-L253

KevinGrandon commented 9 years ago

Sup Jordan! Yeah, that works for me - I mainly needed to be able to control this from an external component, not a child, but I figured out how to do that. Might want to update the readme, but can probably close this.

Kureev commented 9 years ago

I really need to move it to context instead of this hack.