-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Combining Router and navigation Drawer #92
Comments
It is interesting question, have you tried set Drawer as 'footer' prop for Router? |
+1 |
Any progress on this? I am trying to use react-native-side-menu module with this router-flux. Actually it only works until i try to call any Actions. My SideMenu combined with router-flux:
It works up to the point when i try calling any actions from the Side Menu, where unfortunately nothing happens. A Button in my Side Menu, which should call Home Screen:
Any ideas why Actions won´t work? |
Try {()=>Actions.home()} because Actions.home may not defined during compile time... |
Okay nice, it fixed it thanks. Now when i try to put my Side Menu over a nested Router, something like:
It throws me this error when i try to call an Action: And the NavigationBar loses it´s Styling... |
SideMenu should pass its 'router' prop to his children, otherwise router hierarchy would be broken. |
Worked, thanks! |
Hi @BigPun86 can you share your code? I'm trying to build similar logic with a nested tabbar. @sibeliusseraphini |
An example would be helpful. |
+1 |
It took me awhile but I got to the bottom of this. My top level render looks like this.
My drawer's render function looks like this.
|
Hey there. This is how i use the Drawer/SideMenu. In my Main Router i setup as usual my routes. Then i have a nested router Dashboard where i need the Drawer/SideMenu
In my Dashboard component i implemented the SideMenu:
|
@BigPun86 do you have a repo for this ? How does the navigator know to render your scene in ?! |
Thank you @BigPun86, your solution is working for me.
Router.js export default class Routes extends React.Component {
render() {
return (
<Router>
<Route component={SessionScreen} name='session' type='replace' hideNavBar={true} initial={true} />
<Route component={AuthScreen} name='auth' type='replace' />
<Route name='main' hideNavBar={true} type='reset'>
<SideDrawer>
<Router>
<Route component={PlaceScreen} name='place' title='Place' />
<Route component={ItemScreen} name='item' title='Item' />
...
</Router>
</SideDrawer>
</Route>
</Router>
)
}
} SideDrawer.js (I'm using 'react-native-drawer') import Drawer from 'react-native-drawer'
class SideDrawer extends React.Component {
render() {
return (
<Drawer
type="overlay"
content={<SideDrawerContent />}
tapToClose={true}
openDrawerOffset={0.2}
panCloseMask={0.2}
closedDrawerOffset={-3}
styles={{ drawer: drawerStyle, main: mainStyle }}
tweenHandler={(ratio) => ({ main: { opacity: (2 - ratio) / 2 } })}
>
{React.Children.map(this.props.children, c => React.cloneElement(c, {
route: this.props.route
}))}
</Drawer>
)
}
} Be careful of #172 that you can fix by adding in componentWillUnmount() {
// Fix https://github.com/aksonov/react-native-router-flux/issues/172
Actions.currentRouter = null
} |
@mmazzarolo nice example. I tried yours which works for me too even better than mine. But how do you pass the schema to the children? I tried this:
This is what worked to pass the navigationBarStyle, but i am not sure if passing the schema would be nicer...:
|
Thank you @BigPun86! const hideNavBar = Platform.OS === 'android'
const paddingTop = Platform.OS === 'android' ? 0 : 8
export default class Routes extends React.Component {
render() {
return (
<Router>
<Schema
name='boot'
sceneConfig={Navigator.SceneConfigs.FadeAndroid}
hideNavBar={true}
type='replace'
/>
<Schema
name='main'
sceneConfig={Navigator.SceneConfigs.FadeAndroid}
hideNavBar={hideNavBar}
/>
<Route schema='boot' component={SessionScreen} name='session' initial={true} />
<Route schema='boot' component={AuthScreen} name='auth' />
<Route name='main' hideNavBar={true} type='reset'>
<SideDrawer>
<Router
sceneStyle={styles.scene}
navigationBarStyle={styles.navigationBar}
titleStyle={styles.title}
barButtonIconStyle={styles.barButtonIcon}
barButtonTextStyle={styles.barButtonText}
>
<Route schema='main' component={PlaceScreen} name='place' title='Places' />
<Route schema='main' component={PaymentScreen} name='payment' title='Payment' header={Toolbar} />
</Router>
</SideDrawer>
</Route>
</Router>
)
}
} The router above is working for me, hope it helps. |
thanks @mmazzarolo for the well-structured code. That ended up working for me better than my hackish implementation of the drawer!!! |
@mmazzarolo Good work! Could you please add this as section to README? |
hey @aksonov got a quick moment to hop onto Gitter? |
Thanks @MITDelian, but I just stolen and implemented the idea from @GarrettSmith's comment. |
@mmazzarolo |
Sorry for bringing this up again! If I wrap a Router in the I can't seem to access the context anymore and therefore not open/close the sidebar. Any ideas? @mmazzarolo |
Not sure what u mean exactly...But this is how i implemented my Router with SideMenu (react-native-drawer)
The main thing is to give your router and sidedrawer a ref and you can than acces the trigger for opening closing from anywhere like this:
|
Hmm yeah that is strange you see.. My Main Component:
My SideDrawer:
And my 'home' component where I try to open and close the drawer:
But if I click the TouchableOpacity I get a cannot read property open of undefined. Any ideas? |
@davidfloegel do you have Discord? So we could solve it there.... |
Just got an account! davidfloegel is my username! |
Hi, I have used react-native-router-flux and react-native-drawer together. Can anybody help me to show drawer only for dashboard screen not for login. |
There is some way to use react-native-router-flux and react-native-side-menu together, using the latest version of both? Seems like all these answers are outdated. This is my code. It works at the main Scene, but as you go to the others it everything goes blank (the side bar actually still works at that part).
|
Hi!
I'm trying to create a navigation drawer that will point his text elements to jump between screens.
For the matter, I'm using react-native-drawer by root-two.
Do you have any example or can give me some direction of how to combine those two? I can't seem to figure that out.
Thanks!
The text was updated successfully, but these errors were encountered: