我是否可以从CustomDrawerComponent内的DrawerNavigator的子项中获取道具?
当我打开抽屉时,我想在其中放入我的StackNavigator屏幕,而不仅仅是“ AppStackNavigator”。有简单的方法吗?
我的导航器:
const AppStackNavigator = createStackNavigator(
{
Início: {
screen: HomeScreen
},
Perfil: {
screen: ProfileScreen
},
Notificações: {
screen: NotificationScreen
},
'Criar Evento': {
screen: CreateEventScreen
},
EventScreen
},
StackNavigatorConfig()
)
const AppNavigator = createDrawerNavigator(
{
AppStackNavigator
},
{
contentComponent: Drawer,
drawerBackgroundColor: color.primary.main
}
)
const AppContainer = createAppContainer(AppNavigator)
我的CustomDrawerContentComponent:
export default (CustomDrawerContentComponent = props => {
return (
<ScrollView>
<TouchableOpacity onPress={() => props.navigation.closeDrawer()} style={styles.close}>
<EvilIcons style={{ color: color.primary.contrastLightText }} size={40} name="close" />
</TouchableOpacity>
<View style={styles.thumbImageContainer}>
<ThumbImage image={require('../assets/images/user.jpg')} />
<View style={styles.statusContainer}>
<TextApp>Luis Coimbra</TextApp>
<TextApp secondary>Apaixonado por Jesus</TextApp>
</View>
</View>
<SafeAreaView style={{ flex: 1 }} forceInset={{ top: 'always', horizontal: 'never' }}>
<DrawerItems {...props} {...itemsStyle} />
</SafeAreaView>
</ScrollView>
)
})
答案 0 :(得分:0)
使用props.navigation.state.routes [0] .routes.slice(-1)[0] .routeName,我可以设法获得活动的路由器,以便能够进行样式设置。如果您有更好的方法,我将很高兴阅读。
并非完全符合我的预期,但目前效果很好:
export default (CustomDrawerContentComponent = props => {
const activeRouterName = props.navigation.state.routes[0].routes.slice(-1)[0].routeName
return (
<ScrollView>
<TouchableOpacity onPress={() => props.navigation.closeDrawer()} style={styles.close}>
<EvilIcons style={{ color: color.dark.contrast }} size={40} name="close" />
</TouchableOpacity>
<View style={styles.thumbImageContainer}>
<ThumbImage source={require('../assets/images/user.jpg')} />
<View style={styles.statusContainer}>
<TextApp dark>Luis Coimbra</TextApp>
<TextApp secondary>Apaixonado por Jesus</TextApp>
</View>
</View>
<SafeAreaView
style={{ flex: 1, borderTopWidth: 2, borderTopColor: color.dark.contrast }}
forceInset={{ top: 'always', horizontal: 'never' }}
>
{['Início', 'Perfil', 'Notificações', 'Criar Evento'].map(routerName => (
<View key={routerName} style={routerName == activeRouterName && styles.activeView}>
<TextApp
onPress={() => props.navigation.navigate(routerName)}
style={{
color:
routerName == activeRouterName
? color.secondary()
: color.dark.contrast,
margin: 16,
fontWeight: 'bold'
}}
>
{routerName}
</TextApp>
</View>
))}
</SafeAreaView>
</ScrollView>
)
})
结果: