1
votes

I am using the following components in creating a React Native app:

For the drawer, I would like it to close when I press on a link to navigate to a new scene.

My drawer content is defined like so, using react-native-router-flux 'Actions':

<ListItem>
    <Text onPress={Actions.treatments}>Treatments</Text>
</ListItem>

The navigation part works, but where I'm lost is how to trigger the drawer to close upon pressing one of the links. How could I accomplish this?

2

2 Answers

1
votes

Found the answer after some trial and error:

<ListItem>
    <Text onPress={() => { Actions.treatment(); this.context.drawer.close(); }}>Treatment</Text>
</ListItem>

In my case, closing the drawer required context. In other cases, it might be as simple as drawer.close();

0
votes

my solution pass props from drawer to {this.drawer.close() }/> and then, in Menupanel Component use this.props.closePanel() .

<Drawer
        type="overlay"
        side="right"  
        tapToClose={true}
        openDrawerOffset={0.2}
        ref={(ref) => this._drawer = ref}
        content={<ControlPanel  closePanel={ ()=>{this.drawer.close() } />}
        >
        </Home>
</Drawer>