React-native-router-flux: How to customize drawer button

Created on 19 Aug 2016  Â·  9Comments  Â·  Source: aksonov/react-native-router-flux

Version

  • react-native-router-flux v3.34.0
  • react-native v0.31.0

I'm trying to use an Ionicon from react-native-vector-icons as the menu button.

renderMenuButton = () => {
        return (
            <TouchableOpacity style={styles.leftButtonContainer}>
                <Ionicon name="ios-menu" size={30} color="#EF5C30"/>
            </TouchableOpacity>
        );
    };

...

<Scene key="dashboard" component={Dashboard} title="DASHBOARD" type='replace' leftButton={this.menuButton}/>

Actual behaviour

Button renders correctly but does not open drawer.
Using drawerImage={this.menuButton()} does not render button though functionality is still there.

Most helpful comment

@aksonov Thanks! It works now!

@berkayk
In Drawer component:
componentDidMount() { Actions.refresh({key: 'drawer', ref: this.refs.navigation}); }

In Button component:
onPress={() => {Actions.get('drawer').ref.toggle()}}

All 9 comments

The drawerImage property accepts only image path. It renders that inside an <Image> component.
If you want to use custom drawer icon component you need to provide renderLeftButton property.

<Scene 
    key="dashboard" 
    component={Dashboard} 
    title="DASHBOARD" 
    type='replace' 
    renderLeftButton={this.menuButton}
/>

Yes, that does render the custom button, but how can I attach drawer toggle action?

renderLeftButton={() => <MenuButton press={() => { Actions.refresh({key: "drawer", open: true})}} />}

I am not sure if this is the best way to do but it works. "drawer" is the key of the main container that has Drawer as the component. If there is a better way, please share with me :)

Better way is to get reference to drawer directly and call its methods: Actions.get(‘drawer’).ref.switch()
and set Actions.refresh({ref:this.refs.drawer’) within comonentDidMount of Drawer component.

On 22 Aug 2016, at 20:39, Berkay Kaya [email protected] wrote:

renderLeftButton={() => }

I am not sure if this is the best way to do but it works. "drawer" is the key of the main container that has Drawer as the component. If there is a better way, please share with me :)

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub https://github.com/aksonov/react-native-router-flux/issues/1078#issuecomment-241508407, or mute the thread https://github.com/notifications/unsubscribe-auth/ABQpcUgfHGaOuUlKPqmzJNHmeF-IgSchks5qiezJgaJpZM4JotPY.

Can you give a short example?

@aksonov Thanks! It works now!

@berkayk
In Drawer component:
componentDidMount() { Actions.refresh({key: 'drawer', ref: this.refs.navigation}); }

In Button component:
onPress={() => {Actions.get('drawer').ref.toggle()}}

Thanks @wildQueequeg It worked! I also understood how to use refs in react-native-router-flux.
Cheers :+1:

My entire screen with header moves down when I add drawer sidemenu. Where could be the issue?

Has Actions.get() been deprecated as a method of Actions? It's not listed in the API.
When I try it I get:

_reactNativeRouterFlux.Actions.get is not a function
... .get is undefined

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rafaelcorreiapoli picture rafaelcorreiapoli  Â·  3Comments

xnog picture xnog  Â·  3Comments

jgibbons picture jgibbons  Â·  3Comments

wootwoot1234 picture wootwoot1234  Â·  3Comments

vinayr picture vinayr  Â·  3Comments