【问题标题】:how to create dynamic drawer menu navigation using react-native如何使用 react-native 创建动态抽屉菜单导航
【发布时间】:2020-01-11 11:31:12
【问题描述】:

我想使用 react-native 创建一个动态抽屉菜单导航。所有菜单项都从一个 json 文件中列出。

提前致谢!

【问题讨论】:

标签: react-native react-native-navigation


【解决方案1】:

考虑到 boostrap:

render() {
    return (
        <div>
            { this.state.dynamicDrawer
                &&
                    <div className="btn-group-vertical" data-toggle="buttons">
                    <button type="button" className="btn btn-primary">Button</button>
                    <button type="button" className="btn btn-primary">Button</button>
                    <button type="button" className="btn btn-primary">Button</button>
                    <button type="button" className="btn btn-primary">Button</button>
                    <button type="button" className="btn btn-primary">Button</button>
                    <button type="button" className="btn btn-primary">Button</button>
                    </div>
            }
        </div>
)
}

然后在打开关闭时更改状态或以不同方式切换它,在这里你应该为 btn-group-vertical 添加一个类,使整个东西固定在左上角 100% 高度和一些填充或任何你想要的。

为了使列表动态包含一个

this.state.buttons.map(button => { return (<button type="button" className="btn btn-primary">{button}</button>)})

这里有一些本地信息:https://facebook.github.io/react-native/docs/drawerlayoutandroid

render: function() {
  var navigationView = (
    <View style={{flex: 1, backgroundColor: '#fff'}}>
        { 
        this.state.dynamicTexts.map(dynamicText => { return (
          <Text style={{margin: 10, fontSize: 15, textAlign: 'right'}}>{]{dynamicText}</Text>
        )}
        }
    </View>
  );
  return (
    <DrawerLayoutAndroid
      drawerWidth={300}
      drawerPosition={DrawerLayoutAndroid.positions.Left}
      renderNavigationView={() => navigationView}>
      <View style={{flex: 1, alignItems: 'center'}}>
       <Text style={{margin: 10, fontSize: 15, textAlign: 'right'}}>Hello</Text>
       <Text style={{margin: 10, fontSize: 15, textAlign: 'right'}}>World!</Text>
      </View>
</DrawerLayoutAndroid>
  );
},

方法 openDrawer()

openDrawer();

打开抽屉。

closeDrawer()

closeDrawer();

我相信您可以使用这些组件一起构建它:)

祝你好运!

【讨论】:

  • 问题是关于 react-native
  • 除了样式和标签之外它仍然可以工作,只是需要稍微调整一下。使用视图标签等,如果原生不存在 Boostrap,只需创建一些样式,应该不是问题。技术部分是一样的。
  • 对不起,我问的是 react native。
  • @RabithaN 是的,正如你所见,我已经扩展了答案以包括 react native...
猜你喜欢
  • 1970-01-01
  • 2021-03-19
  • 1970-01-01
  • 2021-07-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-04-07
相关资源
最近更新 更多