After a lot of research I have found the solution of Emmie to hide the tab bar on some screens. React navigation 5 hide tab bar from stack navigator However, I am facing two problems.
- On the one hand, Emmie's solution works well when first rendering the app, but if I later "save again" the .js it crashes, showing the error "undefined is not an object (evaluating '_this._getTabBarVisibility').
- Secondly, this will sound stupid (I'm new to programming) but I don't know how to simultaneously have the tabBarIcon function. Currently the app only reads the first set of options, which sets the TabBarVisible. Therefore it doesn't render the icon for the 'Wallet' Screen
Here is my simplified code:
import * as React from 'react';
import { createBottomTabNavigator} from '@react-navigation/bottom-tabs'
import Ionicons from 'react-native-vector-icons/Ionicons'
import { createStackNavigator } from '@react-navigation/stack';
import WalletScreen from '../Screens/WalletScreen.js'
import SettingsScreen from '../Screens/SettingsScreen.js'
import BusinessScreenTab from './BusinessScreenTab'
const Tab = createBottomTabNavigator();
const Stack = createStackNavigator();
function WalletStack (){
return(
<Stack.Navigator
initialRouteName='Wallet'
headerMode='none'>
<Stack.Screen name='Wallet' component={WalletScreen}/>
<Stack.Screen name='Business' component={BusinessScreenTab} />
</Stack.Navigator>
)}
_getTabBarVisibility = (route) => {
const routeName = route.state
? route.state.routes[route.state.index].name
: '';
if (routeName === 'Business') {
return false;
}
return true;
}
export default function MainAppTab () {
return(
<Tab.Navigator
initialRouteName='Purchase'
tabBarOptions={{
keyboardHidesTabBar: 'true',
showLabel: 'false',
}}
>
<Tab.Screen name='Wallet'
component={WalletStack}
options={({ route}) => ({
tabBarVisible: this._getTabBarVisibility(route),
})}
options={{
tabBarIcon: ({color,size}) => (
<Ionicons name='ios-filing' color={color} size={size}/>),
}}
/>
<Tab.Screen name='Settings'
component={SettingsScreen}
options={{
tabBarIcon: ({color,size}) => (
<Ionicons name='ios-settings' color={color} size={28}/>),
}}/>
</Tab.Navigator>
)
}
Thanks in advance!