gpt4 book ai didi

react-native - Drawer Navigator 中的动态导航项

转载 作者:行者123 更新时间:2023-12-03 22:18:30 25 4
gpt4 key购买 nike

我想从 api 的响应中填充 DrawerNavigator。如何动态加载抽屉项目?

例如

    'someName1': { screen: (props) => <someView {...props} viewId='someId2' /> },
'someName2': { screen: (props) => <someView {...props} viewId='someId2' /> },

最佳答案

我是这样解决的——

在渲染方法中-

const Nav = DrawerNavigator(this.getNavItems(this.state.drawerSource.navItems));

const AppNavigator = (StackNavigator(
{
Drawer: { screen: Nav },
},
{
initialRouteName: "Drawer",
headerMode: "none",
})
);

return (<AppNavigator />);

getNavItems(navItems) {
return navItems.reduce((routes, navItem) => {
routes[navItem.id] = this.getNavItem(navItem);

return routes;
}, {});
}

getNavItem(navItem) {
return {
screen: (props) => <MyScreen {...props} id={navItem.id} />,
navigationOptions: {
***any navigation properties
}
}
}

关于react-native - Drawer Navigator 中的动态导航项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48573487/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com