Bottom Tab Bar styling not working on first time app launch - react-native
The issue is that the icons and text on the bottom nav bar don't high light (change to blue) when selected but only on initial app launch after install. Testing on Android simulator. Everything works after the second launch. It has something to do with focused not toggling or detected on first launch.
The Nav setup is fairly complex so I'll boil it down to the essential components:
MainNavigator:
const tabConfig = {
tabBarOptions: {
activeTintColor: Colors.APP_BLUE_CONTRAST,
showLabel: true,
},
tabBarComponent: TabBar,
}
const getInitialRoute = (isLoggedIn, isOnboarded) => {
if (isLoggedIn && !isOnboarded) {
return 'OnboardingScreen'
}
return isLoggedIn ? 'MainTabContainer' : 'LoginScreen'
}
const forFade = ({ current }) => {
const translateX = 0
const translateY = 0
return {
cardStyle: {
opacity: current.progress,
transform: [{ translateX }, { translateY }],
},
}
}
const getFilteredTabs = (tabs, screenProps) => {
const filteredTabs = Object.keys(tabs)
.filter((key) => {
if (key === 'Meditate' && !screenProps?.hasMeditate) {
return false
}
if (key === 'Sleep' && !screenProps?.hasSleep) {
return false
}
if (key === 'Move' && !screenProps?.hasMove) {
return false
}
if (key === 'Foundational' && !screenProps?.hasFoundational) {
return false
}
if (key === 'SEL' && !screenProps?.hasSEL) {
return false
}
if (key === 'Parent' && !screenProps?.hasParent) {
return false
}
if (key === 'Professional' && !screenProps?.hasProfessional) {
return false
}
if (key === 'Personal' && !screenProps?.hasPersonal) {
return false
}
return true
})
.reduce((tab, key) => {
const updatedTab = { ...tab }
updatedTab[key] = tabs[key]
return updatedTab
}, {})
return filteredTabs
}
const MainNavigator = (isLoggedIn, isOnboarded, accountScreenProps) => {
let MainTabContainer = null
if (accountScreenProps) {
const filteredTabs = getFilteredTabs(tabScreens, accountScreenProps)
MainTabContainer = createBottomTabNavigator(filteredTabs, tabConfig)
} else {
MainTabContainer = createBottomTabNavigator(tabScreens, tabConfig)
}
return createStackNavigator(
{
MainTabContainer: {
screen: MainTabContainer,
navigationOptions: {
gestureEnabled: false,
cardStyleInterpolator: forFade,
},
},
// ...and all the rest of the screens
and the TabScreens setup:
const styles = StyleSheet.create({
icon: {
height: 23,
width: 23,
resizeMode: 'contain',
},
tabContainer: {
height: tabBarHeight,
paddingVertical: 5,
},
label: {
fontFamily: regularFont,
fontSize: 13,
color: '#8C8D91',
textAlign: 'center',
},
ipadContainer: {
marginLeft: 20,
},
labelFocused: {
fontFamily: regularFont,
fontSize: 13,
color: colors.blueContrast,
textAlign: 'center',
},
})
const HomeTab = createStackNavigator(
{
HomeScreen: {
screen: (props) => (
<HomeController
{...props}
api={props.screenProps.api}
setShouldShowDailyTipManual={
props.screenProps.setShouldShowDailyTipManual
}
isEAP={props.screenProps.isEAP}
isMSA={props.screenProps.isMSA}
isBCBA={props.screenProps.isBCBA}
permissions={props.screenProps.permissions}
bannerCTA={props.screenProps.bannerCTA}
hasServices={props.screenProps.hasServices}
/>
),
},
},
{
headerMode: 'none',
},
)
const MeditateTab = createStackNavigator(
{
MeditateScreen: {
screen: (props) => (
<CoreCollectionController
{...props}
api={props.screenProps.api}
coreId="meditate"
/>
),
},
},
{
headerMode: 'none',
},
)
const SleepTab = createStackNavigator(
{
SleepScreen: {
screen: (props) => (
<CoreCollectionController
{...props}
api={props.screenProps.api}
coreId="sleep"
/>
),
},
},
{
headerMode: 'none',
},
)
const MoveTab = createStackNavigator(
{
MoveScreen: {
screen: (props) => (
<CoreCollectionController
{...props}
api={props.screenProps.api}
coreId="move"
/>
),
},
},
{
headerMode: 'none',
},
)
const FoundationalTab = createStackNavigator(
{
FoundationalScreen: {
screen: (props) => (
<CoreCollectionController
{...props}
api={props.screenProps.api}
coreId="foundational"
/>
),
},
},
{
headerMode: 'none',
},
)
const ParentTab = createStackNavigator(
{
ParentScreen: {
screen: (props) => (
<CoreCollectionController
{...props}
api={props.screenProps.api}
isBCBA={props.screenProps.isBCBA}
coreId="parent"
/>
),
},
},
{
headerMode: 'none',
},
)
const PersonalTab = createStackNavigator(
{
PersonalScreen: {
screen: (props) => (
<CoreCollectionController
{...props}
api={props.screenProps.api}
isBCBA={props.screenProps.isBCBA}
coreId="personal"
/>
),
},
},
{
headerMode: 'none',
},
)
const ProfessionalTab = createStackNavigator(
{
ProfessionalScreen: {
screen: (props) => (
<CoreCollectionController
{...props}
api={props.screenProps.api}
isBCBA={props.screenProps.isBCBA}
coreId="professional"
/>
),
},
},
{
headerMode: 'none',
},
)
const SELTab = createStackNavigator(
{
SELScreen: {
screen: (props) => (
<CoreCollectionController
{...props}
api={props.screenProps.api}
coreId="sel"
/>
),
},
},
{
headerMode: 'none',
},
)
const DiscoverTab = createStackNavigator(
{
DiscoverScreen: {
screen: (props) => (
<SearchController
{...props}
api={props.screenProps.api}
NavigationActions={NavigationActions}
/>
),
},
},
{
headerMode: 'none',
},
)
const TabLabel = ({ focused, label }) => {
const { t } = useTranslation('NativeComponents')
const { isMobile } = useLayout()
console.log('Tab Label: ', focused, label)
if (isIOS && !isMobile) {
return (
<View style={styles.ipadContainer}>
<Text style={focused ? styles.labelFocused : styles.label}>
{t(label)}
</Text>
</View>
)
}
return (
<Text style={focused ? styles.labelFocused : styles.label}>{t(label)}</Text>
)
}
const tabScreens = {
Home: {
screen: HomeTab,
navigationOptions: {
tabBarLabel: ({ focused }) => (
<TabLabel label="TabScreens.Home" focused={focused} />
),
tabBarIcon: ({ focused }) => (
<Image
resizeMode="contain"
source={focused ? homeActive : homeDefault}
style={styles.icon}
/>
),
tabBarTestIDProps: {
testID: 'Home',
accessibilityLabel: 'Navigation - Home',
},
tabBarOptions: {
activeTintColor: colors.blueContrast,
style: styles.tabContainer,
labelStyle: styles.label,
},
},
},
Meditate: {
screen: MeditateTab,
navigationOptions: {
tabBarLabel: ({ focused }) => (
<TabLabel label="TabScreens.Meditate" focused={focused} />
),
tabBarIcon: ({ focused }) => (
<Image
resizeMode="contain"
source={focused ? meditateActive : meditateDefault}
style={styles.icon}
/>
),
tabBarTestIDProps: {
testID: 'Meditate',
accessibilityLabel: 'Navigation - Meditate',
},
tabBarOptions: {
activeTintColor: colors.blueContrast,
style: styles.tabContainer,
labelStyle: styles.label,
},
},
},
Sleep: {
screen: SleepTab,
navigationOptions: {
tabBarLabel: ({ focused }) => (
<TabLabel label="TabScreens.Sleep" focused={focused} />
),
tabBarIcon: ({ focused }) => (
<Image
resizeMode="contain"
source={focused ? sleepActive : sleepDefault}
style={styles.icon}
/>
),
tabBarTestIDProps: {
testID: 'Sleep',
accessibilityLabel: 'Navigation - Sleep',
},
tabBarOptions: {
activeTintColor: colors.blueContrast,
style: styles.tabContainer,
labelStyle: styles.label,
},
},
},
Move: {
screen: MoveTab,
navigationOptions: {
tabBarLabel: ({ focused }) => (
<TabLabel label="TabScreens.Move" focused={focused} />
),
tabBarIcon: ({ focused }) => (
<Image
resizeMode="contain"
source={focused ? moveActive : moveDefault}
style={styles.icon}
/>
),
tabBarTestIDProps: {
testID: 'Move',
accessibilityLabel: 'Navigation - Move',
},
tabBarOptions: {
activeTintColor: colors.blueContrast,
style: styles.tabContainer,
labelStyle: styles.label,
},
},
},
Foundational: {
screen: FoundationalTab,
navigationOptions: {
tabBarLabel: ({ focused }) => (
<TabLabel label="TabScreens.Foundational" focused={focused} />
),
tabBarIcon: ({ focused }) => (
<Image
resizeMode="contain"
source={focused ? foundationalActive : foundational}
style={styles.icon}
/>
),
tabBarTestIDProps: {
testID: 'Foundational',
accessibilityLabel: 'Navigation - Foundational',
},
tabBarOptions: {
activeTintColor: colors.blueContrast,
style: styles.tabContainer,
labelStyle: styles.label,
},
},
},
SEL: {
screen: SELTab,
navigationOptions: {
tabBarLabel: ({ focused }) => (
<TabLabel label="TabScreens.SEL" focused={focused} />
),
tabBarIcon: ({ focused }) => (
<Image
resizeMode="contain"
source={focused ? selActive : sel}
style={styles.icon}
/>
),
tabBarTestIDProps: {
testID: 'SEL',
accessibilityLabel: 'Navigation - SEL',
},
tabBarOptions: {
activeTintColor: colors.blueContrast,
style: styles.tabContainer,
labelStyle: styles.label,
},
},
},
Parent: {
screen: ParentTab,
navigationOptions: {
tabBarLabel: ({ focused }) => (
<TabLabel label="TabScreens.Parenting" focused={focused} />
),
tabBarIcon: ({ focused }) => (
<Image
resizeMode="contain"
source={focused ? parentingActive : parenting}
style={styles.icon}
/>
),
tabBarTestIDProps: {
testID: 'Parent',
accessibilityLabel: 'Navigation - Parent',
},
tabBarOptions: {
activeTintColor: colors.blueContrast,
style: styles.tabContainer,
labelStyle: styles.label,
},
},
},
Personal: {
screen: PersonalTab,
navigationOptions: {
tabBarLabel: ({ focused }) => (
<TabLabel label="TabScreens.Personal" focused={focused} />
),
tabBarIcon: ({ focused }) => {
console.log('in personal tab: ', focused)
return (
<Image
resizeMode="contain"
source={focused ? meditateActive : meditateDefault}
style={styles.icon}
/>
)
},
tabBarTestIDProps: {
testID: 'Personal',
accessibilityLabel: 'Navigation - Personal',
},
tabBarOptions: {
activeTintColor: colors.blueContrast,
style: styles.tabContainer,
labelStyle: styles.label,
},
},
},
ProfessionalTab: {
screen: ProfessionalTab,
navigationOptions: {
tabBarLabel: ({ focused }) => (
<TabLabel label="TabScreens.Professional" focused={focused} />
),
tabBarIcon: ({ focused }) => (
<Image
resizeMode="contain"
source={focused ? professionalActive : professionalDefault}
style={styles.icon}
/>
),
tabBarTestIDProps: {
testID: 'Professional',
accessibilityLabel: 'Navigation - Professional',
},
tabBarOptions: {
activeTintColor: colors.blueContrast,
style: styles.tabContainer,
labelStyle: styles.label,
},
},
},
Discover: {
screen: DiscoverTab,
navigationOptions: {
tabBarLabel: ({ focused }) => (
<TabLabel label="TabScreens.Discover" focused={focused} />
),
tabBarIcon: ({ focused }) => (
<Image
resizeMode="contain"
source={focused ? searchActive : searchDefault}
style={styles.icon}
/>
),
tabBarTestIDProps: {
testID: 'Discover',
accessibilityLabel: 'Navigation - Discover',
},
tabBarOptions: {
activeTintColor: colors.blueContrast,
style: styles.tabContainer,
labelStyle: styles.label,
},
},
},
}
export default tabScreens
So on first launch, the tabs icons/text do not highlight but the routing works fine.
First launch clicking 'Personal':
All following launches:
Using the following versions:
"react-navigation": "4.4.4",
"react-navigation-stack": "^2.10.4",
"react-navigation-tabs": "^2.11.1",
Related
Can I connect createBottomTabNavigator to a redux store ? (React Native)
I have App.js looks like this const TabNavigationStack = createBottomTabNavigator( { Dashboard: { screen: Dashboard, navigationOptions: { tabBarLabel: () => null, tabBarIcon: ({ tintColor }) => ( <Icon style={{ fontSize: 35, color: tintColor }} name='dashboard' type='MaterialIcons' /> ) } }, Home: { screen: OrderStack, navigationOptions: { tabBarLabel: () => null, tabBarIcon: ({ tintColor }) => ( <Icon style={{ fontSize: 35, color: tintColor }} name='money' type='FontAwesome' /> ) } }, Notification: { screen: NotificationStack, navigationOptions: { tabBarLabel: () => null, tabBarIcon: ({ tintColor }) => ( <IconBadge MainElement={ <Icon style={{ fontSize: 35, color: tintColor }} name='notifications' type='MaterialIcons' /> } IconBadgeStyle={{ zIndex: 1 }} BadgeElement={ <Text style={{ color: '#FFFFFF', fontSize: 10 }}>0</Text> } Hidden={0} /> ) } }, Profile: { screen: Profile, navigationOptions: { tabBarLabel: () => null, tabBarIcon: ({ tintColor }) => ( <Icon style={{ fontSize: 35, color: tintColor }} name='person' type='Ionicons' /> ) } }, }, // router config { initialRouteName: 'Home', order: ['Dashboard', 'Home', 'Notification', 'Profile'], gesturesEnabled: false, navigationOptions: { header: null, tabBarVisible: true }, tabBarOptions: { activeTintColor: COLOR.PRIMARY_COLOR, inactiveTintColor: '#29333D' } } ) const CombinedStack = createSwitchNavigator( { AuthStack: AuthStack, TabNavigationStack: TabNavigationStack, }, { initialRouteName: 'AuthStack' } ) class App extends Component { render() { return ( <Root> <Provider store={store}> <CombinedStack ref={navigationRef => { NavigationService.setTopLevelNavigator(navigationRef) } } /> </Provider> </Root> ); } } export default App; Im planning to connect props in create navigator when the user login, I call an api which indicate the number of badge that connected in redux. I already tried const mapStateToProps = (state) => ({ badgeNumber: state.Notification }); const mapDispatchToProps = (dispatch) => ({ dispatch: dispatch }) const TabNavigationStack = connect(mapStateToProps)(createBottomTabNavigator)({.... but the I got error in props. BTW I'm using react-navigation 2
Move your IconBadge component into a separate javascript file ... and connect that component to redux store const AppIconWithBadge = ({ badgeNumber }) = { //... }; const mapStateToProps = (state) => ({ badgeNumber: state.Notification }); export default connect(mapStateToProps)(AppIconWithBadge); tabBarIcon: ({ tintColor }) => ( <AppIconWithBadge style={{ fontSize: 35, color: tintColor }} name='person' type='Ionicons' /> )
Call a Function in createbottomtabsnavigator
I am using react native and i want to call a function in tabs import {createBottomTabNavigator} from 'react-navigation-tabs'; const TabNavigator = createBottomTabNavigator( { Home:{ screen:CustomMapView, navigationOptions:{ tabBarLabel:'Home', tabBarIcon:({tintColor})=>( <Image source = {require("../../Images/react-logo.png")} style={{width : 30 , height:30}}/> ) } }, Profile11:{ screen:Profile11, navigationOptions:{ tabBarLabel:'Profile11', tabBarIcon:({tintColor})=>( <Image source = {require("../../Images/react-logo.png")} style={{width : 30 , height:30}}/> ) } }, Profile: { screen:ProfileScreen, navigationOptions:{ tabBarLabel:'Profile', tabBarIcon:({tintColor})=>( // <Icon name="ios-person" color={tintColor} size={25}/> <Image source = {require("../../Images/react-logo.png")} style={{width : 30 , height:30}}/> ) } }, }, { initialRouteName: "Home" }, ); As i am using above i want to set some contions on tabs like home if condition true run set CustomMapView as the screen if condition false any other screen will set like CustomMapView.js how can i do this
Check this example if you want to set a condition for rendering page: const MainApp = createBottomTabNavigator( { Home: HomeTab , Settings: SettingsTab , }, { defaultNavigationOptions: ({ navigation }) => ({ tabBarIcon: ({ focused, horizontal, tintColor }) => { const { routeName } = navigation.state; if (routeName === 'Home') { return ( <Image source={ require('./assets/home.png') } style={{ width: 20, height: 20, }} /> ); } else { return ( <Image source={ require('./assets/settings.png') } style={{ width: 20, height: 20 }} /> ); } }, }), tabBarOptions: { activeTintColor: '#FF6F00', inactiveTintColor: '#263238', }, }); And if you want to call a method on tab press, then refer this example : Profile: { screen:ProfileScreen, navigationOptions:{ tabBarLabel:'Profile', tabBarIcon:({tintColor})=>( // <Icon name="ios-person" color={tintColor} size={25}/> <Image source = {require("../../Images/react-logo.png")} style={{width : 30 , height:30}}/> ), tabBarOnPress: () => { this.openGallery() } } },
Get name of previous route to go back to
I have nested stacks in my app. With two different headers. I have a reset but this just send the user back to the home screen regardless. How can I get the previous route? resetForm() { const { dispatch } = this.props.navigation; const resetAction = StackActions.reset({ index: 0, actions: [NavigationActions.navigate({ routeName: "Drawer" })] }); this.props.navigation.dispatch(resetAction); } App Navigator: const config = { contentOptions: { activeTintColor: "#e91e63", inactiveTintColor: "#ffffff", itemStyle: { flexDirection: "row-reverse" } }, drawerWidth: 300, overlayColor: "#003366", drawerPosition: "right", drawerBackgroundColor: "#009999", transparentCard: true, cardStyle: { backgroundColor: "transparent", opacity: 1 }, transitionConfig: () => ({ containerStyle: { backgroundColor: "transparent" } }) }; const withHeader = ( screen: Function, routeName: string, Header ): StackNavigator => createStackNavigator( { [routeName]: { screen, navigationOptions: ({ routeName, props }) => ({ header: props => <Header {...props} /> }) } }, { initialRoute: "Home", transparentCard: true, cardStyle: { backgroundColor: "transparent", opacity: 1 }, transitionConfig: () => ({ containerStyle: { backgroundColor: "transparent" } }) } ); const routes = { VideoEpisodes: { screen: withHeader(VideoEpisodesScreen, "Video Episodes", DrawerHeader) }, TestYourself: { screen: withHeader(TestYourselfScreen, "Test Yourself", DrawerHeader) }, MyResults: { screen: withHeader(MyResultsScreen, "My Results", DrawerHeader) }, BookmarkedVideos: { screen: withHeader( BookmarkedVideosScreen, "Bookmarked Videos", DrawerHeader ) }, About: { screen: withHeader(AboutScreen, "About", DrawerHeader) } }; const NestedDrawer = createDrawerNavigator(routes, config); const MainStack = createStackNavigator( { Home: { screen: HomeScreen, navigationOptions: ({ props }) => ({ header: props => <BasicHeader {...props} /> }) }, Drawer: { screen: NestedDrawer, navigationOptions: ({ props }) => ({ header: () => null }) }, VideoPlayer: { screen: VideoPlayerScreen, navigationOptions: ({ props }) => ({ header: props => <BasicHeader {...props} /> }) } }, { initialRoute: "Home", transparentCard: true, cardStyle: { backgroundColor: "transparent", opacity: 1 }, transitionConfig: () => ({ containerStyle: { backgroundColor: "transparent" } }) } );
How can change height and position of createBottomTabNavigator
I have a createBottomTabNavigator on my project.by default tabs have specific height and bottom position . how can I change position and height of it my code: const Navigate=createBottomTabNavigator({ Home:{screen:Home,navigationOptions:{ tabBarLabel:'Home', tabBarIcon:({tintColor})=>( <Icon name="md-home" color={tintColor} size={25}/> ) } }, Camera:{screen:Camera,navigationOptions:{ tabBarLabel:'Profile', tabBarIcon:({tintColor})=>( <Icon name="md-add-circle" color={tintColor} size={25}/> ) } }, Profile: { screen:Profile, navigationOptions:{ tabBarLabel:'Profile', tabBarIcon:({tintColor})=>( <Icon name="md-person" color={tintColor} size={25}/> ) } }, } ,{ tabBarOptions: { activeTintColor: 'red', inactiveTintColor: 'cyan', activeBackgroundColor:'lightgreen', showLabel:false, keyboardHidesTabBar:false, tabStyle:{ backgroundColor:'orange', height:40, }, }, }, }, ); export default createAppContainer(Navigate);
You need to set the height in the style object, not the tabBarOptions. Refer to https://reactnavigation.org/docs/en/bottom-tab-navigator.html for the styles object. I did it like this in my app const navigatorConfig = { defaultNavigationOptions: ({ navigation }) => ({ tabBarIcon: ({ tintColor }) => { switch (routeName) { .... } style: { height: responsiveHeight(7.5), borderTopWidth: 0, }, }} enter code here
Drawer does not open on first touch
I have a header that should open a drawer once it is touched. However the current behaviour is that it shows immediately the Profile screen (the drawer does not open) on first touch. If you touch the header again then the drawer is actually shown. import ... const navigationOptions = (navigation) => { return { title: navigation.screenProps.t('app.title') } } const defaultNavigationOptionsWithHeader = ({ navigation }) => { return { headerStyle: { backgroundColor: Colors.backgroundColor, }, headerTintColor: Colors.main, headerTitleStyle: { fontWeight: 'bold' }, headerRight: <TouchableOpacity style={{ marginRight: 10 }} onPress={() => navigation.dispatch(DrawerActions.openDrawer())}> <Ionicons name={Platform.OS === 'ios' ? 'ios-menu' : 'md-menu'} size={40} color={Colors.main} /> </TouchableOpacity> } } const defaultNavigationOptionsWithoutHeader = ({ navigation }) => { return { headerStyle: { backgroundColor: Colors.backgroundColor, }, headerTintColor: Colors.main, headerTitleStyle: { fontWeight: 'bold' } } } const AuthStack = createStackNavigator( { Login: { screen: LoginScreen, navigationOptions: navigationOptions }, Registration: { screen: RegistrationScreen, navigationOptions: navigationOptions } }, { initialRouteName: 'Login', defaultNavigationOptions: defaultNavigationOptionsWithoutHeader }); const TabStack = createStackNavigator( { App: { screen: TabNavigator, navigationOptions: navigationOptions } }, { defaultNavigationOptions: defaultNavigationOptionsWithHeader } ); const MenuStack = createStackNavigator( { App: { screen: MenuNavigator, navigationOptions: navigationOptions } }, { defaultNavigationOptions: defaultNavigationOptionsWithHeader } ); const appNavigationOptions = (navigation) => { return { initialRouteName: 'Tab' } } const AppStack = createSwitchNavigator( { Tab: TabStack, Menu: MenuStack }, { defaultNavigationOptions: appNavigationOptions } ) export default createAppContainer(createSwitchNavigator( { AuthLoading: AuthLoadingScreen, Auth: AuthStack, App: AppStack }, { initialRouteName: 'AuthLoading', } )); Does anybody know what causes this issue? The menu navigator is defined as follows: import ... handleHome = (navigation) => { navigation.navigate('App') } handleLogout = (navigation) => { logout(); navigation.navigate('Auth') } const config = Platform.select({ web: { headerMode: 'screen' }, default: {}, }); const navigationOptions = (navigation) => { return { header: null } } const ProfileStack = createStackNavigator( { Map: { screen: ProfileScreen, navigationOptions: navigationOptions } }, config ); ProfileStack.navigationOptions = (navigation) => { return { drawerLabel: navigation.screenProps.t('loggedin.sidebar.profile'), drawerIcon: ({ focused }) => (<DrawerIcon focused={focused} name={ Platform.OS === 'ios' ? `ios-contact'}` : 'md-contact' } />) }; } ProfileStack.path = ''; const PreferencesStack = createStackNavigator( { Settings: { screen: PreferencesScreen, navigationOptions: navigationOptions } }, config ); PreferencesStack.navigationOptions = (navigation) => { return { drawerLabel: navigation.screenProps.t('loggedin.sidebar.preferences'), drawerIcon: ({ focused }) => (<DrawerIcon focused={focused} name={ Platform.OS === 'ios' ? `ios-settings'}` : 'md-settings' } />) } }; const LogoutStack = createStackNavigator( { Logout: { screen: () => null, navigationOptions: navigationOptions } }, config ); LogoutStack.navigationOptions = (navigation) => { return { drawerLabel: navigation.screenProps.t('button.logout'), drawerIcon: ({ focused }) => createDrawerIcon('log-out', focused) }; } const TabStack = createStackNavigator( { Logout: { screen: () => null, navigationOptions: navigationOptions } }, config ); TabStack.navigationOptions = (navigation) => { return { drawerLabel: navigation.screenProps.t('app.title'), drawerIcon: ({ focused }) => createDrawerIcon('home', focused) }; } createDrawerIcon = (icon, focused = false) => { return <DrawerIcon focused={focused} name={ Platform.OS === 'ios' ? 'ios-' + icon : 'md-' + icon } /> } const MenuDrawerItem = (props) => { return <TouchableOpacity onPress={props.onPress} > <View style={styles.item}> <View style={styles.iconContainer}> {createDrawerIcon(props.icon)} </View> <Text style={styles.label}>{props.text}</Text> </View> </TouchableOpacity > } const MenuDrawer = (props) => ( <ScrollView contentContainerStyle={{ flex: 1, flexDirection: 'column', justifyContent: 'space-between' }}> <SafeAreaView forceInset={{ top: 'always', horizontal: 'never' }}> <MenuDrawerItem onPress={() => this.handleHome(props.navigation)} text={props.screenProps.t('app.title')} icon={'home'} /> <DrawerItems {...props} /> </SafeAreaView> <MenuDrawerItem onPress={() => this.handleLogout(props.navigation)} text={props.screenProps.t('button.logout')} icon={'log-out'} /> </ScrollView> ); const menuNavigator = createDrawerNavigator({ ProfileStack, PreferencesStack }, { drawerPosition: 'right', contentComponent: props => <MenuDrawer {...props} />, contentOptions: { activeTintColor: Colors.main }, initialRouteName: 'ProfileStack' } ); menuNavigator.path = '' export default menuNavigator const styles = ...
That's probably you might have something other in focus. May be Keyboard, TextField, Or some other things which are in focus and when you click for the first time the focus gets removed and when you press for the second time the drawer gets opened. Try calling an alert instead of opening the drawer on button press and then debug that. That will troubleshoot the issue