Remove oval shape when active when using material bottom tabs - react-native

I'm using #react-navigation/material-bottom-tabs and have an issue with the tab icons in the bottom tab navigator. The problem is an oval shape, as the background shows up when that tab is selected.
This is what it looks like:
So far I didn't find any way to remove it.
import React, { Component } from "react";
import { StatusBar } from "expo-status-bar";
import { StyleSheet, Text, View } from "react-native";
import HomeScreen from "./Screens/Home";
import NotificationScreen from "./Screens/Notifications";
import ProfileScreen from "./Screens/Profile";
import SearchScreen from "./Screens/Search";
import { createMaterialBottomTabNavigator } from "#react-navigation/material-bottom-tabs";
import { NavigationContainer } from "#react-navigation/native";
import MaterialCommunityIcons from "react-native-vector-icons/MaterialCommunityIcons";
const Tab = createMaterialBottomTabNavigator();
export default function App() {
return (
<NavigationContainer>
<Tab.Navigator
shifting={true}
initialRouteName="Home"
activeColor="#fff"
inactiveColor="#333"
barStyle={{ backgroundColor: "tomato" }}
labeled={true}
>
<Tab.Screen
name="Home"
component={HomeScreen}
options={{
tabBarIcon: ({ color, size }) => (
<MaterialCommunityIcons name="home" color={color} size={26} />
),
tabBarColor: "blue",
}}
/>
<Tab.Screen
name="Notifications"
component={NotificationScreen}
options={{
tabBarIcon: ({ color, size }) => (
<MaterialCommunityIcons name="heart" color={color} size={26} />
),
}}
/>
<Tab.Screen
name="Profile"
component={ProfileScreen}
options={{
tabBarIcon: ({ color, size }) => (
<MaterialCommunityIcons
name="account-circle"
color={color}
size={26}
/>
),
}}
/>
<Tab.Screen
name="Search"
component={SearchScreen}
options={{
tabBarIcon: ({ color }) => (
<MaterialCommunityIcons name="magnify" color={color} size={26} />
),
}}
/>
</Tab.Navigator>
</NavigationContainer>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#fff",
alignItems: "center",
justifyContent: "center",
},
});
I have tried many ways to remove it, but I haven't found anything that works.

Related

The action 'NAVIGATE' with payload {"name":"ChatScreen"} was not handled by any navigator. Do you have a screen named 'ChatScreen'?

here is my App.js which is the entry point. i get the error The action 'NAVIGATE' with payload {"name":"ChatScreen"} was not handled by any navigator.
Do you have a screen named 'ChatScreen'?
If you're trying to navigate to a screen in a nested navigator, see https://reactnavigation.org/docs/nesting-navigators#navigating-to-a-screen-in-a-nested-navigator.
This is a development-only warning and won't be shown in production. and i have the ChatScreen in screens directory
import react from 'react';
import { NavigationContainer } from '#react-navigation/native';
import { createDrawerNavigator } from '#react-navigation/drawer';
import MainTabScreen from './scr/components/MainTabScreen';
import { DrawerContent } from './scr/components/DrawerContent';
const Drawer = createDrawerNavigator();
export default function App() {
return (
<NavigationContainer>
{/* screenOptions={{headerStyle:{
backgroundColor: '#009387',
},
headerTintColor: '#fff',
headerTitleStyle:{
fontWeight: 'bold'
} */}
<Drawer.Navigator drawerContent={props => <DrawerContent {...props} />}>
<Drawer.Screen
options={{
headerShown: false
}}
name='md' component={MainTabScreen} />
{/* <Drawer.Screen name="Products" component={Products} /> */}
</Drawer.Navigator>
</NavigationContainer>
);
}
here is my MainTbScreen.js which contains the navigation
import { createMaterialBottomTabNavigator } from '#react-navigation/material-bottom-tabs'
import Icon from 'react-native-vector-icons/Ionicons'
import HomeScreen from '../screens/Homescreen'
import Ministries from '../screens/Ministries'
import ProfileScreen from '../screens/ProfileScreen'
import { createNativeStackNavigator } from '#react-navigation/native-stack'
import ChatScreen from '../screens/ChatScreen';
const HomeStack = createNativeStackNavigator();
const DetailsStack = createNativeStackNavigator();
const Tab = createMaterialBottomTabNavigator();
const MainTabScreen = () => (
<Tab.Navigator
initialRouteName="Home"
activeColor="#fff"
>
<Tab.Screen
name="Home"
component={HomeStackScreen}
options={{
tabBarLabel: 'Home',
tabBarColor: '#009387',
tabBarIcon: ({ color }) => (
<Icon name="home" color={color} size={26} />
),
}}
/>
<Tab.Screen
name="Notifications"
component={DetailsStackScreen}
options={{
tabBarLabel: 'Chat',
tabBarColor: '#1f65ff',
tabBarIcon: ({ color }) => (
<Icon name="Messagebox" color={color} size={26} />
),
}}
/>
<Tab.Screen
name="Chat"
component={ChatScreen}
options={{
tabBarLabel: 'Profile',
tabBarColor: '#694fad',
tabBarIcon: ({ color }) => (
<Icon name="person" color={color} size={26} />
),
}}
/>
<Tab.Screen
name="Profile"
component={ProfileScreen}
options={{
tabBarLabel: 'Profile',
tabBarColor: '#d02860',
tabBarIcon: ({ color }) => (
<Icon name="ios-aperture" color={color} size={26} />
),
}}
/>
</Tab.Navigator>
);
export default MainTabScreen;
const HomeStackScreen = ({navigation}) => (
<HomeStack.Navigator screenOptions={{
headerStyle: {
backgroundColor: '#009387',
},
headerTintColor: '#fff',
headerTitleStyle: {
fontWeight: 'bold'
}
}}>
<HomeStack.Screen name="Home" component={HomeScreen} options={{
title:'Overview',
headerLeft: () => (
<Icon.Button name="ios-menu" size={25} backgroundColor="#009387" onPress={() => navigation.openDrawer()}></Icon.Button>
)
}} />
</HomeStack.Navigator>
);
const DetailsStackScreen = ({navigation}) => (
<DetailsStack.Navigator screenOptions={{
headerStyle: {
backgroundColor: '#1f65ff',
},
headerTintColor: '#fff',
headerTitleStyle: {
fontWeight: 'bold'
}
}}>
<DetailsStack.Screen name="Details" component={Ministries} options={{
headerLeft: () => (
<Icon.Button name="ios-menu" size={25} backgroundColor="#1f65ff" onPress={() => navigation.openDrawer()}></Icon.Button>
)
}} />
</DetailsStack.Navigator>
);
You are navigating using ChatScreen but this is not the name that you have defined in the Screen inside the navigator's name prop.
Either, do
<Tab.Screen
name="ChatScreen"
component={ChatScreen}
options={{
tabBarLabel: 'Profile',
tabBarColor: '#694fad',
tabBarIcon: ({ color }) => (
<Icon name="person" color={color} size={26} />
),
}}
/>
or navigation.navigate("Chat") while leaving name="Chat".

react native why my navigation shows me 2 headers?

I want to custom my header. The Problem is, it shows me two headers. My custom header and the Tab Header "Home".
import * as React from 'react';
import { StyleSheet, Text, View, TouchableOpacity, Image } from 'react-native';
import { NavigationContainer } from '#react-navigation/native';
import { createNativeStackNavigator } from '#react-navigation/native-stack';
import {
BottomTabBar,
createBottomTabNavigator,
} from '#react-navigation/bottom-tabs';
import { Entypo, FontAwesome5 } from '#expo/vector-icons';
import Home from '../screens/Home';
import News from '../screens/News';
import Weapons from '../screens/stack/Weapons';
import HeaderHome from '../shared/headerHome';
const Stack = createNativeStackNavigator();
const Tab = createBottomTabNavigator();
const TabBar = () => (
<Tab.Navigator
tabBar={(props) => {
return (
<View>
<BottomTabBar {...props} />
</View>
);
}}
screenOptions={{
tabBarStyle: [{ display: 'flex' }],
tabBarShowLabel: true,
tabBarLabelStyle: {
paddingBottom: 6,
color: '#333',
},
}}>
<Tab.Screen
name="Home"
component={Home}
options={{
tabBarIcon: ({ color, focused }) => (
<Entypo name="home" size={24} color={focused ? '#37bfff' : '#888'} />
),
}}
/>
<Tab.Screen
name="News"
component={News}
options={{
tabBarIcon: ({ color, focused }) => (
<Entypo
name="newsletter"
size={24}
color={focused ? '#37bfff' : '#888'}
/>
),
}}
/>
</Tab.Navigator>
);
const Navigation = () => (
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen
name="HomeScreen"
component={TabBar}
options={{
header: () => <HeaderHome />,
}}
/>
</Stack.Navigator>
</NavigationContainer>
);
const styles = StyleSheet.create({
navigator: {
borderTopWidth: 0,
backgroundColor: 'transparent',
elevation: 30,
height: 60,
},
});
export default Navigation;
You can add a option to hide the Tab.Navigator's header. Add headerShown: false to the screenOptions of Tab.Navigator as shown below
<Tab.Navigator
tabBar={(props) => {
return (
<View>
<BottomTabBar {...props} />
</View>
);
}}
screenOptions={{
tabBarStyle: [{ display: 'flex' }],
tabBarShowLabel: true,
tabBarLabelStyle: {
paddingBottom: 6,
color: '#333',
},
headerShown: false, // <--- Here
}}>
Check out the working example for your scenario here
On the other hand, if you want to hide the Stack.Navigator's header, you can do as shown below
<Stack.Navigator screenOptions={{ headerShown: false }}>

Hide Tab Bar on invoking keyboard for createMaterialTopTabNavigator as a Bottom Tab Navigator implementation

Heyy everyone, I was using the React Navigation 5 createMaterialTopTabNavigator for a Bottom Navigation setup as I needed the swipe transition that Material Top Navigator offers as well, but unlike createBottomTabNavigator, the Material Top doesn't have a keyboardHidesTabBar so that I can make sure that tab bar is hidden when the keyboard opens, but thats something I'm trying to achieve (https://material.io/components/bottom-navigation#placement).
Any other way to get something like this done?
Here's the current snack to play around: https://snack.expo.io/qTDqLo1eb
Here's the code:
import * as React from 'react';
import { Text, View, TextInput } from 'react-native';
import { NavigationContainer } from '#react-navigation/native';
import { createMaterialTopTabNavigator } from '#react-navigation/material-top-tabs';
import { MaterialCommunityIcons } from '#expo/vector-icons';
function HomeScreen() {
const [text, onChangeText] = React.useState("Useless Text");
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>Home!</Text>
<TextInput
onChangeText={onChangeText}
value={text}
/>
</View>
);
}
function SettingsScreen() {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>Settings!</Text>
</View>
);
}
const Tab = createMaterialTopTabNavigator();
export default function App() {
return (
<NavigationContainer>
<Tab.Navigator tabBarPosition='bottom'
tabBarOptions={{
// style: { position: 'absolute', bottom:0 },
activeTintColor: '#e91e63',
inactiveTintColor: '#ee11ff',
showIcon: true,
indicatorStyle:{
height:0
}
}}>
<Tab.Screen
options={{
tabBarLabel: 'Home',
tabBarIcon: ({ color, size }) => (
<MaterialCommunityIcons name="home" color={color} size={24} />
),
}} name="Home" component={HomeScreen} />
<Tab.Screen
options={{
tabBarLabel: 'Profile',
tabBarIcon: ({ color, size }) => (
<MaterialCommunityIcons name="account" color={color} size={24} />
),
}} name="Settings" component={SettingsScreen} />
</Tab.Navigator>
</NavigationContainer>
);
}

React-Native How to change the overall background color of the Tabbar on the focused other tabs

I want to change tabbar BackgroundColor.
I have 5 tabs on bottom navigation.
first, When I touch home tab. I want to change Tabbar's backgroundcolor is 'transparent'
second, When I touch others(four) tab. I want to change Tabbar's backgroundcolor is 'white'
also I want to change activeTintColor By other tab.
Here is my Code, and Screen shot(I want to make this Screen shot).
Now my home screen. Home Screen shot
I want this other screen. screen shot
import { View } from 'react-native';
import { createBottomTabNavigator } from '#react-navigation/bottom-tabs';
import MyHomeStack from './HomeStack';
import MyProfileStack from './ProfileStack';
import InformScreen from '../screens/InformScreen';
import SearchScreen from '../screens/SearchScreen';
import UploadScreen from '../screens/UploadScreen';
import CustomIcon from '../components/CustomIcon';
const Tab = createBottomTabNavigator();
function MainTabStack(){
return (
<Tab.Navigator
initialRouteName="Home"
labelStyle={{ fontSize: 12 }}
tabBarOptions={{
style: {
height: '9%',
backgroundColor: 'transparent',
position:'absolute',
bottom:0,
elevation:0
},
activeTintColor: '#000000',
showLabel: false,
}}>
<Tab.Screen
name="Home"
component={MyHomeStack}
options={{
tabBarIcon: ({ color, size }) => (
<CustomIcon name="nav_home" color={color} size={size}/>
)
}}
/>
<Tab.Screen
name="Search"
component={SearchScreen}
options={{
tabBarColor:'red',
tabBarIcon: ({ color, size }) => (
<CustomIcon name="nav_store" color={color} size={size} />
),
}}
/>
<Tab.Screen
name="Upload"
component={UploadScreen}
options={{
tabBarIcon: ({ color, size }) => (
<CustomIcon name="nav_upload" color={color} size={28} />
),
}}
listeners={({ navigation }) => ({
tabPress: event => {
event.preventDefault();
navigation.navigate('UploadScreen');
},
})}
/>
<Tab.Screen
name="Inform"
component={InformScreen}
options={{
tabBarIcon: ({ color, size }) => (
<CustomIcon name="nav_closet" color={color} size={size} />
),
}}
/>
<Tab.Screen
name="mypage"
component={MyProfileStack}
options={{
tabBarIcon: ({ color, size }) => (
<CustomIcon name="mypage" color={color} size={size} />
),
}}
/>
</Tab.Navigator>
);
}
export default MainTabStack;
Inside the tabbar options, have you tried changing the backgroundColor to your desired color of choice dynamically.
constructor(props){
this.tabIndex=0;
}
<Tab.Navigator
initialRouteName="Home"
labelStyle={{ fontSize: 12 }}
screenOptions={({ route }) => ({
if (route.name === 'Home') {
this.tabIndex=4;
} else if (route.name === 'Settings') {
this.tabIndex=5;
}
})}
tabBarOptions={{
style: {
height: '9%',
backgroundColor: this.tabIndex==4?"#fff":"transparent",
//backgroundColor: 'transparent',
position:'absolute',
bottom:0,
elevation:0
},
activeTintColor: '#000000',
showLabel: false,
}}>
<Tab.Screen name="Home" component={HomeScreen} />
<Tab.Screen name="Settings" component={SettingsScreen} />
</Tab.Navigator>

How to change the active tab color with more than 2 colors in react-navigation

I need to change the tab icons background color to red in home screen, yellow in the another tab(list)
blue in the another tab (section) while I am clicking on the particular tab
In my app it have three footer tabs.
I need to change color for each tab with different color.
How can I achieve this?
const HomeTabNavigator = createBottomTabNavigator({
ListScreen,
HomeScreen,
SectionScreen,
}, {
initialRouteName: 'HomeScreen',
tabBarOptions: {
activeTintColor: 'red',
style: {
paddingTop: 5,
height: 65
}
}
});
You can set activeBackgroundColor and inactiveBackgroundColor using with tabBarOptions
But all tab are the same.
For make different, you have to customize its Tab components.
React Navigation v5 documents for tabBar Props.
Here's doc tabBar
const MyTabBar = ({state, descriptors, navigation}) => {
return (
<View style={{flexDirection: 'row'}}>
<View style={{backgroundColor: 'red'}}>
<Text>One Tab</Text>
</View>
<View style={{backgroundColor: 'yellow'}}>
<Text>Second Tab</Text>
</View>
<View style={{backgroundColor: 'blue'}}>
<Text>Third Tab</Text>
</View>
</View>
);
}
And Router file
<Tab.Navigator tabBar={props => <MyTabBar {...props} />}>
</Tab.Navigator>
EDIT:
for react-navigation v3;
const TabBarComponent = (props) => (<BottomTabBar {...props} />);
const TabScreens = createBottomTabNavigator(
{
tabBarComponent: props =>
<TabBarComponent
{...props}
style={{ borderTopColor: '#605F60' }}
/>,
},
);
Doc v3 tabBarComponent
import {createMaterialBottomTabNavigator} from '#react-navigation/material-bottom-tabs';
import Icon from 'react-native-vector-icons/Ionicons';
const Tab = createMaterialBottomTabNavigator();
const BottomTabScreen = () => (
<Tab.Navigator activeColor="#fff">
<Tab.Screen
name="Home"
initialRouteName="Home"
component={HomeScreen}
options={{
tabBarLabel: 'Home',
tabBarColor: '#3333cc',
tabBarIcon: ({color}) => (
<Icon name="ios-home" color={color} size={26} />
),
}}
/>
<Tab.Screen
name="Notifications"
component={UpdateScreen}
options={{
tabBarLabel: 'Updates',
tabBarColor: '#196619',
tabBarIcon: ({color}) => (
<Icon name="ios-notifications" color={color} size={26} />
),
}}
/>
<Tab.Screen
name="Profile"
component={ProfileScreen}
options={{
tabBarLabel: 'Profile',
tabBarColor: '#e67300',
tabBarIcon: ({color}) => (
<Icon name="ios-person" color={color} size={26} />
),
}}
/>
<Tab.Screen
name="Explore"
component={ExploreScreen}
options={{
tabBarLabel: 'Explore',
tabBarColor: '#751a2e',
tabBarIcon: ({color}) => (
<Icon name="ios-aperture" color={color} size={26} />
),
}}
/>
</Tab.Navigator>
);
export default BottomTabScreen;