我的主要路线有一个 DrawerNavigator 配置
const App = DrawerNavigator(DrawerRoutes, {
initialRouteName: 'Main',
contentComponent: ({ navigation }) => <DrawerMenu navigation={navigation} routes={DrawerRoutes} />,
mode: Platform.OS === 'ios' ? 'modal' : 'card',
drawerWidth: Dimensions.get('window').width - (Platform.OS === 'android' ? 56 : 64),
drawerPosition: 'left',
})
我想根据应用程序的当前语言更改 drawerPosition 属性。 我已经尝试连接到 redux 但没有成功,因为它会为无效的 React 元素抛出错误。 如何即时更改 drawerNavigator 属性?
最佳答案
我最终得到了一个不太优雅的解决方案。
我复制了react-navigation的DrawerNavigator添加到我的项目中。
无法正常工作的导入被修复为指向原始的 react-navigation 项目,我在 DrawerView 组件的 drawerPosition 属性上实现了应用程序逻辑
const Drawer = I18nReader()(
({ i18n, ...restProps }) =>
<DrawerView
{...restProps}
useNativeAnimations={useNativeAnimations}
drawerWidth={drawerWidth}
contentComponent={contentComponent}
contentOptions={contentOptions}
drawerPosition={i18n.rtl ? 'right' : 'left'}
/>
)
const navigator = createNavigator(
drawerRouter,
routeConfigs,
config,
NavigatorTypes.DRAWER
)(Drawer)
关于react-native - 在 react 导航中动态更改 DrawerNavigator 的 drawerPosition 配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46303188/