我在抽屉导航器中使用堆栈导航器。我想要做的是,我需要知道activeItem(活动屏幕),以便将其显示为活动状态。
StackNavigator
const stackNav = StackNavigator({
homeComponent: { screen: HomeScreen },
serviceScreen: { screen: ServiceScreen },
serviceDetailScreen: { screen: ServiceDetailScreen },
selectVehicleScreen: { screen: SelectVehileScreen },
addEditVehicle: { screen: AddVehicle },
dateTimeScreen: { screen: DateTimeScreen },
reviewScreen: { screen: ReviewScreen },
notesScreen: { screen: NotesScreen },
}, {
headerMode: 'none'
});
DrawerNavigator
const DrawerStack = DrawerNavigator({
appointment: {
screen: stackNav,
},
}, {
headerMode: 'none',
gesturesEnabled: false,
contentComponent: DrawerContainer
});
export default DrawerStack;
答案 0 :(得分:2)
你能做的是
在您的上下文中,只有一个屏幕可以处于活动状态,即约会屏幕。
如果您想知道如果约会屏幕是聚焦的,那么您应该检查DrawerContainer组件内的道具。它会给你activeItemKey
,即约会。
然后您只需检查DrawerComponent
是否
this.props.activeItemKey === 'appointment' ? { color: '#000' } : { color: '#fff' }]}
您也可以从DrawerNavigator传递activeTintColor
道具,如下所示
您可以找到其他DrawerNavigatorConfigs
here
const DrawerStack = DrawerNavigator({
appointment: {
screen: stackNav,
},
}, {
headerMode: 'none',
gesturesEnabled: false,
contentComponent: DrawerContainer,
contentOptions: {
activeTintColor: '#e91e63',
itemsContainerStyle: {
marginVertical: 0,
},
iconContainerStyle: {
opacity: 1
}
}
});
export default DrawerStack;