Adding padding to react-native bottomTabNavigator - react-native

I am trying to figure out how to add some top and bottom padding around my bottom tabs navigator in my react native app. So far any changes I make have no effect. For instance, I tried adding padding: 20 to my style within screenOptions, but this made no difference.
This is my relevant code:
export const ClientScreen = (props) => {
const Tab = createBottomTabNavigator();
return (
<Tab.Navigator
screenOptions={{
headerShown: true,
headerStyle: {
backgroundColor: Colors.primary,
},
headerTintColor: Colors.light,
title: `${props.client?.firstName} ${props.client?.lastName}`,
tabBarActiveTintColor: Colors.light,
tabBarInactiveTintColor: Colors.lightInactive,
tabBarActiveBackgroundColor: Colors.primary,
tabBarInactiveBackgroundColor: Colors.primary,
headerLeft: () => (
<Feather
name='chevron-left'
size={24}
onPress={() => props.navigation.goBack()}
color={styles.colors.textInverse}
style={styles.layout.padding.horizontal}
/>
),
}}
initialRouteName={'Sessions'}
>
<Tab.Screen
name='Sessions'
component={SessionsTab}
initialParams={props}
options={{
tabBarLabel: 'SESSIONS',
tabBarIcon: ({ color, size }) => <FontAwesome name='street-view' color={color} size={size} />,
}}
/>
<Tab.Screen
name='Chart'
component={ChartTab}
initialParams={props}
options={{
tabBarLabel: 'CHARTS',
tabBarIcon: ({ color, size }) => <FontAwesome name='id-badge' color={color} size={size} />,
}}
/>
<Tab.Screen
name='Goals'
component={GoalsTab}
initialParams={props}
options={{
tabBarLabel: 'GOALS',
tabBarIcon: ({ color, size }) => <FontAwesome name='trophy' color={color} size={size} />,
}}
/>
</Tab.Navigator>
);
};

based on the react-native-navigation docs you need to use the option tabBarStyle here's a the docs
or just add this:
<Tab.Navigator
screenOptions={{
tabBarStyle: { padding: 20 },
}}
>

Related

How to change bottom tab navigation color according to active route?

I started to learn ReactNative and I'm trying to change bottom tab navigation color according to active route but I couldn't find how I can make it. I tried setting state but I couldn't find where I can get focused route to set a state variable.
const Tab = createMaterialBottomTabNavigator();
const MyTabs = () => {
return (
<Tab.Navigator
initialRouteName="Home"
activeColor="#f0edf6"
inactiveColor="#3e2465"
tabBarOptions={{
style: {
backgroundColor: "red",
}
}}
>
<Tab.Screen
name="Home"
component={WelcomePage}
options={{
tabBarLabel: "Home",
tabBarIcon: ({ color }) => (
<MaterialCommunityIcons name="home" color={color} size={26} />
),
}}
/>
<Tab.Screen
name="Account"
component={AuthScreen}
options={{
tabBarLabel: "Account",
tabBarIcon: ({ color }) => (
<MaterialCommunityIcons name="account" color={color} size={26} />
),
}}
/>
</Tab.Navigator>
);
export default function App() {
return (
<NavigationContainer>
<MyTabs />
</NavigationContainer>
);
}
}
I found how to change background:
<Tab.Screen
name="Home"
component={WelcomePage}
options={({route}) => ({
tabBarStyle: {
backgroundColor: "#fc03cf"
},
tabBarIcon: ({ color, size }) => (
<MaterialCommunityIcons name="home" color={color} size={26} />
),
})}
/>
You can simpy do this also
tabBarOptions={{
activeTintColor: 'red',
inactiveTintColor: 'green',}}
Try this.
const Tab = createMaterialBottomTabNavigator();
const MyTabs = () => {
return (
<Tab.Navigator
initialRouteName="Home"
activeColor="#f0edf6"
inactiveColor="#3e2465"
tabBarOptions={{
style: {
backgroundColor: "red",
}
}}
>
<Tab.Screen
name="Home"
component={WelcomePage}
options={{
tabBarLabel: "Home",
tabBarIcon: ({ color,focused }) => (
<MaterialCommunityIcons name="home" color={focused?'red':'blue'} size={26} />
),
}}
/>
<Tab.Screen
name="Account"
component={AuthScreen}
options={{
tabBarLabel: "Account",
tabBarIcon: ({ color,focused }) => (
<MaterialCommunityIcons name="account" color={focused?'red':'blue'} size={26} />
),
}}
/>
</Tab.Navigator>
);
export default function App() {
return (
<NavigationContainer>
<MyTabs />
</NavigationContainer>
);
}
}

Why do i get this error in my home page during navivation load on the chat screen and updates

Found screens with the same name nested inside one another. Check:
This is the main code that brings the error. The error is in some of the screens.
how do i get rid though its a warning in react-native and appears on the navigation part. Why do i get this error in my home page during navivation load on the chat screen and updates
Home, Home > Home,
Home > Home, Home > Home > Home,
Home > Updates, Home > Updates > Updates,
Home > Profile, Home > Profile > Profile
import React from 'react' 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';
import Updates from '../screens/Updates';
const HomeStack = createNativeStackNavigator();
const DetailsStack = createNativeStackNavigator();
const MinistriesStack = createNativeStackNavigator();
const ChatScreenStack = createNativeStackNavigator();
const ProfileStack = 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="Updates"
component={DetailsStackScreen}
options={{
tabBarLabel: 'Updates',
tabBarColor: '#d02860',
tabBarIcon: ({ color }) => (
<Icon name="ios-aperture" color={color} size={26} />
),
}}
/>
<Tab.Screen
name="Ministries"
component={MinistriesStackScreen}
options={{
tabBarLabel: 'Ministries',
tabBarColor: '#d02860',
tabBarIcon: ({ color }) => (
<Icon name="ios-aperture" color={color} size={26} />
),
}}
/>
<Tab.Screen
name="Chat"
component={ChatStackScreen}
options={{
tabBarLabel: 'Chat',
tabBarColor: '#1f65ff',
tabBarIcon: ({ color }) => (
<Icon name="notifications" color={color} size={26} />
),
}}
/>
<Tab.Screen
name="Profile"
component={ProfileStackScreen}
options={{
tabBarLabel: 'Profile',
tabBarColor: '#694fad',
tabBarIcon: ({ color }) => (
<Icon name="person" 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="Updates" component={Updates} options={{
headerLeft: () => (
<Icon.Button name="ios-menu" size={25} backgroundColor="#1f65ff" onPress={() => navigation.openDrawer()}></Icon.Button>
)
}} />
</DetailsStack.Navigator>
);
const ProfileStackScreen = ({navigation}) => (
<ProfileStack.Navigator screenOptions={{
headerStyle: {
backgroundColor: '#1f65ff',
},
headerTintColor: '#fff',
headerTitleStyle: {
fontWeight: 'bold'
}
}}>
<ProfileStack.Screen name="Profile" component={ProfileScreen} options={{
headerLeft: () => (
<Icon.Button name="ios-menu" size={25} backgroundColor="#1f65ff" onPress={() => navigation.openDrawer()}></Icon.Button>
)
}} />
</ProfileStack.Navigator>
);
const MinistriesStackScreen = ({navigation}) => (
<MinistriesStack.Navigator screenOptions={{
headerStyle: {
backgroundColor: '#1f65ff',
},
headerTintColor: '#fff',
headerTitleStyle: {
fontWeight: 'bold'
}
}}>
<MinistriesStack.Screen name="Ministries" component={Ministries} options={{
headerLeft: () => (
<Icon.Button name="ios-menu" size={25} backgroundColor="#1f65ff" onPress={() => navigation.openDrawer()}></Icon.Button>
)
}} />
</MinistriesStack.Navigator>
);
const ChatStackScreen = ({navigation}) => (
<ChatScreenStack.Navigator screenOptions={{
headerStyle: {
backgroundColor: '#1f65ff',
},
headerTintColor: '#fff',
headerTitleStyle: {
fontWeight: 'bold'
}
}}>
<ChatScreenStack.Screen name="Chat" component={ChatScreen} options={{
headerLeft: () => (
<Icon.Button name="ios-menu" size={25} backgroundColor="#1f65ff" onPress={() => navigation.openDrawer()}></Icon.Button>
)
}} />
</ChatScreenStack.Navigator>
);`
this is the end of the code

How to play a Lottie animation only once in LottieView in material-bottom-tabs

I am making an app i have made a bottom navigation bar.I have used material-bottom-tabs.
I added Lottie animation But when i click on tab the tab animate.it animates contentiously.
Here is the code
const Tab = createMaterialBottomTabNavigator();
export const Mytabs = () => {
return (
<Tab.Navigator
activeColor="#B32626"
sceneAnimationEnabled
inactiveColor="#f0edf6"
style={style.nav}
barStyle={{
backgroundColor: "black",
position: "absolute",
overflow: "hidden",
margin: 20,
borderRadius: 30,
}}
>
<Tab.Screen
name="Home"
component={Home}
options={{
tabBarLabel: "Home",
tabBarColor: "green",
tabBarIcon: ({ focused, color, size }) => (
<LottieView
autoPlay={focused}
source={require("../assets/lottieicons/Homeicon.json")}
/>
),
}}
/>
<Tab.Screen
name="Search"
component={Search}
options={{
tabBarLabel: "Search",
tabBarIcon: ({ focused, color, size }) => (
// <Icon name="search" color={color} size={26} />
<LottieView
autoPlay={focused}
source={require("../assets/lottieicons/searchicon.json")}
/>
),
}}
/>
<Tab.Screen
name="Favourite"
component={Favourite}
options={{
tabBarLabel: "Favourite",
tabBarIcon: ({ focused, color, size }) => (
// <Icon name="bookmark" color={color} size={26} />
<LottieView
autoPlay={focused}
source={require("../assets/lottieicons/Bookmarkicon.json")}
/>
),
}}
/>
</Tab.Navigator>
);
};
I added loop={false} but then it is not animating even a single time it only animate when app starts.
Here is the changed code:
const Tab = createMaterialBottomTabNavigator();
export const Mytabs = () => {
return (
<Tab.Navigator
activeColor="#B32626"
sceneAnimationEnabled
inactiveColor="#f0edf6"
style={style.nav}
barStyle={{
backgroundColor: "black",
position: "absolute",
overflow: "hidden",
margin: 20,
borderRadius: 30,
}}
>
<Tab.Screen
name="Home"
component={Home}
options={{
tabBarLabel: "Home",
tabBarColor: "green",
tabBarIcon: ({ focused, color, size }) => (
<LottieView
autoPlay={focused}
loop={false}
source={require("../assets/lottieicons/Homeicon.json")}
/>
),
}}
/>
<Tab.Screen
name="Search"
component={Search}
options={{
tabBarLabel: "Search",
tabBarIcon: ({ focused, color, size }) => (
// <Icon name="search" color={color} size={26} />
<LottieView
autoPlay={focused}
loop={false}
source={require("../assets/lottieicons/searchicon.json")}
/>
),
}}
/>
<Tab.Screen
name="Favourite"
component={Favourite}
options={{
tabBarLabel: "Favourite",
tabBarIcon: ({ focused, color, size }) => (
// <Icon name="bookmark" color={color} size={26} />
<LottieView
autoPlay={focused}
loop={false}
source={require("../assets/lottieicons/Bookmarkicon.json")}
/>
),
}}
/>
</Tab.Navigator>
);
};
Please help me solve this.
I want the tab to animate only once when focused on it

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;