React Native - 识别活动屏幕。抽屉导航器

时间:2018-04-26 10:44:35

标签: reactjs react-native redux react-navigation

我在抽屉导航器中使用堆栈导航器。我想要做的是,我需要知道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;

1 个答案:

答案 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;