有没有任何解决方案来更新来自其他组件的react-native-router-flux中的Drawer

问题描述 投票:0回答:1

我正在尝试在react-native-router-flux中创建一个动态抽屉。我的意思是当我更改场景时,抽屉可以检测到现在激活的场景,并且可以通过新数据更新自己。我的抽屉里有一个组件,可以在App.js中调用

<Drawer
    key={'drawer'}
    contentComponent = {() => <DrawerLayout language={this.state.language} />}
    drawerPosition= {this.state.rightOrLeft}

    <Stack key={'root'} hideNavBar>
        <Scene key={'splash'} component={Splash} initial/>
        <Scene key={'login'} component={Login} />
        <Scene key={'home'} component={Home} />
        <Scene key={'about'} component={About} />
    </Stack>
</Drawer>

我希望我能正确解释我的梦想!

react-native drawer react-native-router-flux
1个回答
1
投票

如果您正在使用redux,您可以保留状态并从商店获取当前场景并使用它。

如果你没有使用redux,你仍然可以在没有它的情况下使用它。一种选择是执行以下操作:

  1. 在DrawerNavigator中使用contentComponent并从单独的js文件中获取内容。 contentComponent: props => <SideBar {...props} />
  2. 现在,您需要将App.js名称中的全局变量声明为currentScene,并将您的主页设置为默认值。
  3. 现在让我们加入sideBar.js中的所有内容,点击每个菜单项将全局变量值更改为所选菜单。
  4. 根据SideBar.js中当前场景的值更改menuItems List。

一个很好的例子是反应原生基地厨房水槽示例app。一旦熟悉它,就按照以下四个步骤阅读其中的代码,您就完成了。

https://github.com/GeekyAnts/NativeBase-KitchenSink

© www.soinside.com 2019 - 2024. All rights reserved.