React Native:-如何通过控件在所有页面上使用通用的抽屉和工具栏 [英] React Native:-How to use a common drawer and toolbar across all pages with control

查看:120
本文介绍了React Native:-如何通过控件在所有页面上使用通用的抽屉和工具栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是React Native的新手.
我想为android和ios都制作一个抽屉和工具栏.
我在有导航器的主页上编写了抽屉和工具栏的代码.

I am a newbie in React Native.
I wanna make a drawer and toolbar for android and ios both.
I wrote the code of drawer and toolbar in my mainpage where I have navigator.

例如.

<Drawer>
  <Toolbar />
  <Navigator />
</Drawer>

所以我在所有内页中都有抽屉和工具栏.但是现在的问题是我如何控制抽屉和工具栏.
就像如果我要在一页上不显示抽屉功能,而是要根据应用程序内的页面在工具栏上显示/隐藏选项一样.

So I got drawer and toolbar in all inner pages. But now the question is how do I have control over drawer and toolbar.
Like If I want one page where I dont want to show the drawer feature and I want to show/hide options on toolbar according to pages inside the application.

任何帮助将不胜感激.

实现上述目标的任何其他更好的方法.

Any other better way to achieve the above.

谢谢

推荐答案

如果您使用的是redux(或其他具有单个位置来保持应用状态的东西),则可以使这些对象引用状态树中的项目.例如,您可以在状态(store.navigationState.currentScene)内创建一个属性,并使Toolbar.subtitle指向该状态.

If you're using redux (or something else alike that has a single place to keep your app state) you can make these objects references items inside your state tree. For instance, you could create a property inside your state (store.navigationState.currentScene) and make your Toolbar.subtitle points to that.

现在,每次导航到另一个场景时,您都可以更新currentScene,并且工具栏的字幕也将更改.

Now, everytime you navigate to a different scene, you could update your currentScene and the subtitle of your toolbar would also change.

这篇关于React Native:-如何通过控件在所有页面上使用通用的抽屉和工具栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆