react native createbottomtabnavigator hide tab bar label - reactjs

I need to know how to hide the bottom label.
I've tried the following:
tabBarShowLabels: 'hidden', tabbarlabelvisible: false.
I also removed the tabbarlabel: 'Home' and it still shows
Any help would be appreciated or if someone could point me to the right direction.
import {createBottomTabNavigator} from 'react-navigation'
import Icon from 'react-native-vector-icons/Ionicons'
const Tabs = createBottomTabNavigator ({
Home:{
screen: Home,
navigationOptions:{
tabBarIcon: ({ focused, tintcolor }) => (
<Icon name="ios-home" size={24} />
)
}
},
Inbox:{screen: Inbox,
navigationOptions:{
tabBarIcon: ({ tintcolor }) => (
<Icon name="ios-mail" size={24} />
)
}
},
Search:{screen: Search,
navigationOptions:{
tabBarIcon: ({ tintcolor }) => (
<Icon name="ios-search" size={24} />
)
}
},
Favorites:{screen: Favorites,
navigationOptions:{
tabBarIcon: ({ tintcolor }) => (
<Icon name="ios-heart" size={24} />
)
}
},
Settings:{screen: Settings,
navigationOptions:{
tabBarIcon: ({ tintcolor }) => (
<Icon name="ios-settings" size={24} />
)
}
}
}
});
export default class App extends Component {
render() {
return <Tabs />
}
}

You have to define showLabel: false as the docs says, just as
const Tabs = createBottomTabNavigator ({
Home:{
screen: Home,
navigationOptions:{
tabBarIcon: ({ focused, tintcolor }) => (
<Icon name="ios-home" size={24} />
)
}
},
...
,
Settings:{screen: Settings,
navigationOptions:{
tabBarIcon: ({ tintcolor }) => (
<Icon name="ios-settings" size={24} />
)
}
}
}
}, {
tabBarOptions: { showLabel: false }
});

On the new versions of React Navigation, you just need to pass showLabel prop as false
<Tab.Navigator tabBarOptions={{ showLabel: false }}>

The above answer is perfect, But it messed the brackets a bit. So for a new bee like me, Here is the proper code.
const ProfileStack = createStackNavigator({
Profile: SettingsScreen
});
ProfileStack.navigationOptions = {
tabBarIcon: ({ focused }) => (
<TabBarIcon
focused={focused}
title={'Profile'}
name={focused ? 'tabIcon' : 'tabIconFocused'}
/>
),
tabBarOptions: { showLabel: false }
};

compatible with v6
<Tab.Navigator
screenOptions={() => ({
tabBarShowLabel: false,
....

for react-navigation v4, set the labeled property to false to display only the icons.
const Tabs = createBottomTabNavigator ({
Home:{
screen: Home,
navigationOptions:{
tabBarIcon: ({ focused, tintcolor }) => (
<Icon name="ios-home" size={24} />
)
}
},
...
,
Settings:{screen: Settings,
navigationOptions:{
tabBarIcon: ({ tintcolor }) => (
<Icon name="ios-settings" size={24} />
)
}
}
}
}, {labeled:false});

Use tabBarShowLabel property
tabBarShowLabel: false,
Code
<NavigationContainer>
<BottomTab.Navigator
screenOptions={{
activeTintColor: '#000',
inactiveTintColor: '#fff',
tabBarActiveTintColor: 'black',
tabBarInactiveTintColor: 'gray',
//this one
tabBarShowLabel: false,
}
<BottomTab.Screen
name="Home"
component={HomeScreen}
options={{
tabBarIcon: ({ focused }) => (
<Icon
name={focused ? 'home' : 'home-outline'}
size={24}
color={focused && 'black'}
/>
),
}}
/>
----
----
</BottomTab.Navigator>
</NavigationContainer>

Related

React Navigation - opening a modal from the tab bar

Using React Navigation (6), I've got bottom tabs set up as my main navigator:
export function TabNavigator() {
const getColor = ({ focused, color }) => (focused ? palette.blue : color)
return (
<Tab.Navigator screenOptions={{ headerShown: false }}>
<Tab.Screen
name="home"
component={HomeScreen}
options={{
tabBarLabel: "Home",
tabBarIcon: ({ size, ...rest }) => (
<Ionicons name="home-outline" color={getColor(rest)} size={size} />
),
}}
/>
<Tab.Screen
name="favourites"
component={FavouritesScreen}
options={{
tabBarLabel: "Favourites",
tabBarIcon: ({ size, ...rest }) => (
<Ionicons name="heart-outline" color={getColor(rest)} size={size} />
),
}}
/>
<Tab.Screen
name="about"
component={AboutYouScreen}
options={{
tabBarLabel: "About you",
tabBarIcon: ({ size, ...rest }) => (
<Ionicons name="person-outline" color={getColor(rest)} size={size} />
),
}}
/>
<Tab.Screen
name="bottomchat"
component={ChatNavigator}
options={{
tabBarLabel: "Check-in",
tabBarIcon: ({ size, ...rest }) => (
<Ionicons name="chatbubble-ellipses-outline" color={getColor(rest)} size={size} />
),
}}
/>
</Tab.Navigator>
)
}
With the last tab (the ChatNavigator), I want the screen it opens to be a full screen modal, hiding the bottom tab bar (the user can exit out if it via a back button at the top).
Is this possible?
As I was writing this question I found an answer which actually worked for me on this blog post
The solution:
Create the full screen modal in your parent stack
Pass in a mock component to the tab screen (this will never get called)
Add a listener to the tab component that prevents default and then navigates to the page of your choice
So for me:
const ChatBase = () => <View style={{ flex: 1, backgroundColor: "red" }} />
export function TabNavigator() {
const getColor = ({ focused, color }) => (focused ? palette.blue : color)
return (
<Tab.Navigator screenOptions={{ headerShown: false }}>
<Tab.Screen
name="home"
component={HomeScreen}
options={{
tabBarLabel: "Home",
tabBarIcon: ({ size, ...rest }) => (
<Ionicons name="home-outline" color={getColor(rest)} size={size} />
),
}}
/>
<Tab.Screen
name="favourites"
component={FavouritesScreen}
options={{
tabBarLabel: "Favourites",
tabBarIcon: ({ size, ...rest }) => (
<Ionicons name="heart-outline" color={getColor(rest)} size={size} />
),
}}
/>
<Tab.Screen
name="about"
component={AboutYouScreen}
options={{
tabBarLabel: "About you",
tabBarIcon: ({ size, ...rest }) => (
<Ionicons name="person-outline" color={getColor(rest)} size={size} />
),
}}
/>
<Tab.Screen
name="bottomchat"
/* Pass in a blank component as the base (this never gets shown) */
component={ChatBase}
options={{
tabBarLabel: "Check-in",
tabBarIcon: ({ size, ...rest }) => (
<Ionicons name="chatbubble-ellipses-outline" color={getColor(rest)} size={size} />
),
}}
listeners={({ navigation }) => ({
tabPress: (e) => {
e.preventDefault()
navigation.navigate("chat")
},
})}
/>
</Tab.Navigator>
)
}
In my root stack navigator, I've got a screen called chat that gets called:
export function MainNavigator() {
return (
<Stack.Navigator
screenOptions={{
cardStyle: { backgroundColor: "transparent" },
headerShown: false,
}}
>
<Stack.Screen name="main" component={TabNavigator} />
<Stack.Screen name="chat" component={ChatScreen} />
</Stack.Navigator>
)
}
Use listener/tabPress props with navigator, but navigator from TabNavigator component
export function TabNavigator( { navigation } ) { // <-- use this navitagor
.........
.........
<Tab.Screen
name="bottomchat"
component={ AnyComponent } // <-- ignored
options={{
tabBarLabel: "Check-in",
tabBarIcon: ({ size, ...rest }) => (
<Ionicons name="chatbubble-ellipses-outline" color={getColor(rest)} size={size} />
),
}}
listeners={() => ({
tabPress: (e) => {
e.preventDefault()
navigation.navigate("ChatComponent") // <-- Here you put the name where the chat component is declared
},
})}
/>
</Tab.Navigator>
)
}

Can hide one o the tabscreen element?

I am trying to hide one of the screens from Bottom Tab Navigator in React Native. It is just because I am using nested navigation and child navigator is tab navigator. I have to define the screen but I don't want to make it visible on the screen. What should I do?
Here is my first navigation stack. After sign in, navigate to 'Main'
const navigator = createStackNavigator({ Signup: {
screen: SignupScreen,
navigationOptions:{
headerShown:false
}, }, Signin: {
screen: SigninScreen,
navigationOptions:{
headerShown:false
}, }, Home: {
screen: HomeScreen,
navigationOptions:{
headerShown:false },
}, Main: {
screen: MainScreen,
navigationOptions:{
headerShown:false
},}, Partner: {
screen: PartnerScreen,
navigationOptions:{
headerShown:false
}, }, ProjectDetail: {
screen: ProjectDetail,
navigationOptions:{
headerShown:false
},}, });
And here is my Main screen codes.
<NavigationContainer style={{ backgroundColor: '#1f1f1f' }}>
<View style={[styles.container]}>
</View>
<Tab.Navigator
initialRouteName="Project"
tabBarOptions={{
activeTintColor: '#ED4C67',
inactiveTintColor: '#fafafa',
activeBackgroundColor: '#222',
inactiveBackgroundColor: '#222',
showLabel: false,
}}
screenProps={{ Username: this.state.Username }} >
<Tab.Screen
name='Project'
component={ProjectScreen}
style={display="none"}
options={{
tabBarIcon: ({ color, size }) => (
<Icon name='paperclip' color={color} size={size - 4} />
),
}}
/>
<Tab.Screen name="Partner" component={PartnerScreen}
options={{
tabBarIcon: ({ color, size }) => (
<Icon name='users' color={color} size={size - 4} />
),
}}
/>
<Tab.Screen name="Investor" component={InvestorScreen}
options={{
tabBarIcon: ({ color, size }) => (
<Icon name='bar-chart' color={color} size={size - 4} />
),
}} />
<Tab.Screen name="ProjectDetail" component={ProjectDetail}
options={{
tabBarIcon: ({ color, size }) => (
<Icon name='bar-chart' color={color} size={size - 4} />
),
}} />
</Tab.Navigator>
</NavigationContainer>
I want to navigate from 'PartnerScreen' to 'ProjectDetail'. But I can't use this.props.navigation.navigate or replace because of the nested navigation rules without a ProjectDetail screen in tabnavigator. So I thought that I can hide it.

React Native: createBottomTabNavigator screenOptions doesnt work

Hi am working on my tab navigator, so far so good until I tried to customize the tab navigator by adding icons and customized the colors:
import React from 'react';
import { NavigationContainer } from '#react-navigation/native';
import { createStackNavigator } from '#react-navigation/stack';
import { Ionicons } from '#expo/vector-icons';
import CategoriesScreen from '../screens/CategoriesScreen';
import CategoryMealsScreen from '../screens/CategoryMealsScreen';
import MealDetailScreen from '../screens/MealDetailScreen';
import FavoritesScreen from '../screens/FavoritesScreen';
import HeaderButton from '../components/HeaderButton';
import { HeaderButtons, Item } from 'react-navigation-header-buttons';
import { createBottomTabNavigator } from '#react-navigation/bottom-tabs';
import { CATEGORIES } from '../data/dummy-data';
import Colors from '../constants/colors';
const MealsNav = createStackNavigator();
const MealsNavigator = () => {
return (
<MealsNav.Navigator
mode="modal"
screenOptions={{
headerStyle: {
backgroundColor: Colors.primaryColor,
},
headerTintColor: '#fff',
headerTitleStyle: {
fontSize: 17
}
}}
>
<MealsNav.Screen
name="Categories"
component={CategoriesScreen}
options={{
title: 'Meals Categories'
}}
/>
<MealsNav.Screen
name="CategoryMeals"
component={CategoryMealsScreen}
options={({ route }) => {
const catId = route.params.categoryId;
const selectedCategory = CATEGORIES.find((cat) => cat.id === catId);
return {
title: selectedCategory.title,
};
}}
/>
<MealsNav.Screen
name="MealDetail"
component={MealDetailScreen}
options={{
title: 'Meal Detail',
headerRight: () => (
<HeaderButtons HeaderButtonComponent={HeaderButton}>
<Item
title='Favorite'
iconName='ios-star'
onPress={() => console.log('Mark as the favorite')}
/>
</HeaderButtons>
),
}}
/>
</MealsNav.Navigator>
);
};
const MealsFavTabNavigator = createBottomTabNavigator();
const MealsTabNav = () => {
return (
<NavigationContainer>
<MealsFavTabNavigator.Navigator>
<MealsFavTabNavigator.Screen
name="Meals"
component={MealsNavigator}
screenOptions={() => ({
tabBarIcon: (tabInfo) => {
return <Ionicons name="ios-restaurant" size={25} color={tabInfo.tintColor} />
}
})}
tabBarOptions={{
activeTintColor: 'tomato',
inactiveTintColor: 'black',
}}
/>
<MealsFavTabNavigator.Screen
name="Favorites"
component={FavoritesScreen}
screenOptions={({ route }) => ({
tabBarIcon: (tabInfo) => {
return <Ionicons name="ios-star" size={25} color={tabInfo.tintColor} />
}
})}
tabBarOptions={{
activeTintColor: 'tomato',
inactiveTintColor: 'black',
}}
/>
</MealsFavTabNavigator.Navigator>
</NavigationContainer>
);
};
export default MealsTabNav;
As you can see here, I tried to add a screenOptions:
const MealsFavTabNavigator = createBottomTabNavigator();
const MealsTabNav = () => {
return (
<NavigationContainer>
<MealsFavTabNavigator.Navigator>
<MealsFavTabNavigator.Screen
name="Meals"
component={MealsNavigator}
screenOptions={() => ({
tabBarIcon: (tabInfo) => {
return <Ionicons name="ios-restaurant" size={25} color={tabInfo.tintColor} />
}
})}
tabBarOptions={{
activeTintColor: 'tomato',
inactiveTintColor: 'black',
}}
/>
<MealsFavTabNavigator.Screen
name="Favorites"
component={FavoritesScreen}
screenOptions={({ route }) => ({
tabBarIcon: (tabInfo) => {
return <Ionicons name="ios-star" size={25} color={tabInfo.tintColor} />
}
})}
tabBarOptions={{
activeTintColor: 'tomato',
inactiveTintColor: 'black',
}}
/>
</MealsFavTabNavigator.Navigator>
</NavigationContainer>
);
};
The icons doesnt work even the colors doesnt work and there are no errors on the console. Any idea what am I doing wrong?
The screenOptions prop is used for navigators not screens.
When using for screens you will have to use 'options' not screenOptions
<MealsFavTabNavigator.Screen
name="Favorites"
component={FavoritesScreen}
options={({ route }) => ({
tabBarIcon: (tabInfo) => {
return <Ionicons name="ios-star" size={25} color={tabInfo.tintColor} />
}
})}
/>
Also the tabBarOptions should be moved to navigator
<MealsFavTabNavigator.Navigator
tabBarOptions={{
activeTintColor: 'tomato',
inactiveTintColor: 'black',
}}>

Can't show custom header in tabNavigator

I can't show my custom header with static navigation options. It's only TabNavigator on my Title. What should I do?
This is my HomeScreen Component;
export default class Home extends Component {
static navigationOptions = ({navigation}) => ({
title: 'MENEMENOYS',
headerLeft : (
<TouchableOpacity
onPress={() => {
AuthStore.LogOut().then(() => {
navigation.navigate('LoginPage');
});
}}>
<Icon
name="md-log-out"
size={30}
color={'white'}
style={{marginLeft:10}}
/>
</TouchableOpacity>
)
})
And this is my router : stack navigator with tab navigator.
const TabNavigator = createBottomTabNavigator(
{
Home: {
screen: Home,
navigationOptions: {
tabBarIcon: ({ tintColor }) => (
<Icon
name="md-home"
size={30}
color={tintColor}
style={styles.homeIcon}
/>
),
},
},
AddNewCar: {
screen: AddNewCar,
navigationOptions: {
tabBarIcon: ({ tintColor }) => (
<Icon
name="md-add-circle"
size={40}
color={tintColor}
style={styles.addIcon}
/>
),
},
},
OtoparkList: {
screen: OtoparkList,
navigationOptions: {
tabBarIcon: ({ tintColor }) => (
<IconAwesome name="car" size={30} color={tintColor} />
),
},
},
},
{
tabBarOptions: {
showLabel: false,
activeTintColor: '#41AB5F',
inactiveTintColor: 'white',
style: {
backgroundColor: '#1F202D',
borderTopColor: 'transparent',
},
},
},
);
const AppNavigator = createStackNavigator(
{
TabNavigator: {
screen: TabNavigator,
navigationOptions: {
}
},
LoginPage: {
screen: LoginPage,
navigationOptions: {
headerShown: false,
},
},
ParkingDetail: {
screen: ParkingDetail,
navigationOptions: {
headerShown: false,
},
},
Print: {
screen: Print,
navigationOptions: {
headerShown: false,
}
}
},
{
initialRouteName: 'LoginPage',
},
);
But my header is not shown. Only Header title:TabNavigator and default back button.
Where am i doing wrong ? Please help me. Thanks.
Hey in React navigation latest version 5.x syntax is changed try following
Take a look at doc here Header buttons
static navigationOptions = ({ navigation }) => {
return {
headerTitle: () =>(
<View>
<Text>MENEMENOYS</Text>
</View>
),
headerLeft: () => (
<TouchableOpacity
onPress={() => {
AuthStore.LogOut().then(() => {
navigation.navigate('LoginPage');
});
}}>
<Icon
name="md-log-out"
size={30}
color={'white'}
style={{marginLeft:10}}
/>
</TouchableOpacity>
),
};
};

React Navigation how to pass props to TabNavigator Stateless Functional Components

I am learning to use React Navigation and loving it, but can't figure out how to send props from my top level App Component down to my screen components. I could be (most probably) going about it completely the wrong way. Here is my code.
Main App Component
class App extends Component {
constructor(props) {
super(props);
this.state = {
signedIn: false,
checkedSignIn: false
};
}
componentWillMount() {
isSignedIn()
.then(res => this.setState({ signedIn: res, checkedSignIn: true }))
.catch(err => alert(err));
}
render() {
const { checkedSignIn, signedIn } = this.state;
if (!checkedSignIn) {
return null;
}
if (signedIn) {
console.log("yeah boi");
console.log(SignedOut);
return (
<Provider store={store}>
<SignedIn screenProps={(name = "TestName")} />
</Provider>
);
} else {
console.log("nah bro");
return (
<Provider store={store}>
<SignedOut />
</Provider>
);
}
}
}
Screen
export default ({ navigation }) =>
<View style={{ paddingVertical: 20 }}>
<Card title="John Doe">
<View
style={{
backgroundColor: "#bcbec1",
alignItems: "center",
justifyContent: "center",
width: 80,
height: 80,
borderRadius: 40,
alignSelf: "center",
marginBottom: 20
}}
>
<Text style={{ color: "white", fontSize: 28 }}>JD</Text>
</View>
<Button
title="SIGN OUT"
onPress={() =>
onSignOut().then(() => navigation.navigate("SignedOut"))} // NEW LOGIC
/>
</Card>
</View>;
Nav
export const SignedIn = TabNavigator({
Tasks: {
screen: Tasks,
navigationOptions: {
tabBarIcon: ({ tintColor }) =>
<SimpleLineIcons name="list" size={30} />
}
},
Home: {
screen: Home,
navigationOptions: {
tabBarIcon: ({ tintColor }) =>
<SimpleLineIcons name="home" size={30} />
}
},
Message: {
screen: Message,
navigationOptions: {
tabBarIcon: ({ tintColor }) =>
<SimpleLineIcons name="envelope-letter" size={30} />
}
},
Profile: {
screen: Profile,
navigationOptions: {
tabBarIcon: ({ tintColor }) =>
<SimpleLineIcons name="user" size={30} />
}
}
});
Can anyone tell me how I would pass props, such as my attempted {(name = "TestName")}, to the SignedIn SFC?
I am fairly new to react so please be gentle :)
Thanks
Sam
Got it sorted while still keeping the items stateless, using React Navigations screenProps parameter. Just had to fix my syntax in the Nav component and explicitly call screenProps in my screen. Here it is for reference:
Main App
class App extends Component {
constructor(props) {
super(props);
this.state = {
signedIn: false,
checkedSignIn: false
};
}
componentWillMount() {
isSignedIn()
.then(res => this.setState({ signedIn: res, checkedSignIn: true }))
.catch(err => alert(err));
}
render() {
const { checkedSignIn, signedIn } = this.state;
if (!checkedSignIn) {
return null;
}
if (signedIn) {
console.log("yeah boi");
console.log(SignedOut);
return (
<Provider store={store}>
<SignedIn screenProps={{ name: "TestName" }} />
</Provider>
);
} else {
console.log("nah bro");
return (
<Provider store={store}>
<SignedOut />
</Provider>
);
}
}
}
Screen
export default ({ navigation, screenProps }) =>
<View style={{ paddingVertical: 20 }}>
<Card title={screenProps.name}>
<View
style={{
backgroundColor: "#bcbec1",
alignItems: "center",
justifyContent: "center",
width: 80,
height: 80,
borderRadius: 40,
alignSelf: "center",
marginBottom: 20
}}
>
<Text style={{ color: "white", fontSize: 28 }}>JD</Text>
</View>
<Button
title="SIGN OUT"
onPress={() =>
onSignOut().then(() => navigation.navigate("SignedOut"))} // NEW LOGIC
/>
</Card>
</View>;
Nav
export const SignedIn = TabNavigator({
Tasks: {
screen: Tasks,
navigationOptions: {
tabBarIcon: ({ tintColor }) =>
<SimpleLineIcons name="list" size={30} />
}
},
Home: {
screen: Home,
navigationOptions: {
tabBarIcon: ({ tintColor }) =>
<SimpleLineIcons name="home" size={30} />
}
},
Message: {
screen: Message,
navigationOptions: {
tabBarIcon: ({ tintColor }) =>
<SimpleLineIcons name="envelope-letter" size={30} />
}
},
Profile: {
screen: Profile,
navigationOptions: {
tabBarIcon: ({ tintColor }) =>
<SimpleLineIcons name="user" size={30} />
}
}
});
Use store state to get data, set state of store in top level component,
use that state in your screen component
I think <SignedIn screenProps={(name = "TestName")} /> will rise a syntax error. It should be just <SignedIn name='TestName' />. The bigger problem is how you use the TabNavigator component. What if you try the following:
export const SignedIn = ({ name }) => TabNavigator({
Tasks: {
screen: Tasks,
navigationOptions: {
tabBarIcon: ({ tintColor }) =>
<SimpleLineIcons name={ name } size={30} />
}
},
Home: {
screen: Home,
navigationOptions: {
tabBarIcon: ({ tintColor }) =>
<SimpleLineIcons name={ name } size={30} />
}
},
Message: {
screen: Message,
navigationOptions: {
tabBarIcon: ({ tintColor }) =>
<SimpleLineIcons name={ name } size={30} />
}
},
Profile: {
screen: Profile,
navigationOptions: {
tabBarIcon: ({ tintColor }) =>
<SimpleLineIcons name={ name } size={30} />
}
}
});

Resources