wix react native navigation v2 | how to push new screen to current screen from side drawer component

我们两清 提交于 2019-12-04 12:54:55
terreb

Ok, figured out. Hopefully this will help someone else also struggling with this. In my drawer component I have a global listener:

constructor( props: Props ) {
    super( props )

    Navigation.events().registerComponentDidAppearListener( ( { componentId } ) => {
        // only spy on tabs we don't need other screens
        if (componentId === 'searchScreen' || componentId === 'secondScreen') {
            this.setState({
                activeComponentId: componentId
            })
        }
}

Then when I need to open a screen I already have the active component id and can safely push new screen onto it.

openMenuItem( screenName ) {
    // close drawer
    Navigation.mergeOptions( 'sideDrawer', {
        sideMenu: {
            right: {
                visible: false
            }
        }
    } )

    // open menu item
    Navigation.push( this.state.activeComponentId, {
        component: { name: screenName }
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!