Grey Background on clicking Drawer Items in React Native app - react-native

Problem: Grey Background when clicking/Long Press on items.
Requirement: How to change grey background to orange color when I press items?
<Drawer.Navigator
drawerContent={(props)=><CustomDrawer {...props}/>}
screenOptions={
{
drawerStyle:{
width:300,
borderBottomEndRadius:15,
},
drawerLabelStyle:{
fontSize:18,
marginLeft:-10,
},
drawerItemStyle:{
marginLeft:0,
marginRight:0,
paddingLeft:10
},
drawerActiveBackgroundColor:'orange',
drawerActiveTintColor:'black',
}
}
>

<Drawer.Navigator
drawerContentOptions={{
activeTintColor: 'red',
activeBackgroundColor: 'grey',
inactiveTintColor: 'blue',
inactiveBackgroundColor: 'white',
labelStyle:{
fontSize: 15,
marginLeft:5
}
}}>
</Drawer.Navigator>
also follow the link
https://github.com/react-navigation/react-navigation/issues/9079

I suggest you to try this.
<Drawer.Navigator
screenOptions={{
drawerActiveBackgroundColor: ‘orange’
drawerActiveTintColor: ‘fff’
drawerInactiveTintColor: ‘#333’
}}
>

Related

How to modify "selected tab" bottom border color on TopTabNavigator

I'm working on a react-native app using react-navigations createMaterialTopTabNavigator. I've read through the docs, but I cannot seem to find what props I need to modify to change the bottom border color of the active tab.
Does anyone have any advice?
FWIW here is my current Navigator code:
const TopTab = createMaterialTopTabNavigator()
function ProgressNavigator() {
const themes = useThemes()
return (
<TopTab.Navigator
screenOptions={{
tabBarStyle: {
backgroundColor: themes.lightBackground,
},
tabBarLabelStyle: {
paddingTop: 10,
fontSize: 14,
fontWeight: "bold",
},
tabBarActiveTintColor: themes.secondary.color,
tabBarInactiveTintColor: "#FFF",
}}
>
<TopTab.Screen name="Table" component={ProgressTable} />
<TopTab.Screen name="Chart" component={ProgressChart} />
</TopTab.Navigator>
)
}
Use tabBarIndicatorStyle to style an indicator. Below example sets label (and possible icon) and indicator to red.
<Tab.Navigator
screenOptions={{
tabBarIndicatorStyle: {
backgroundColor: 'red'
},
tabBarActiveTintColor: 'red',
}}>
...
</Tab.Navigator>

How to add an indicator under the active bottom tab?

I need to add an indicator for the active tab I tried to add a borderBottom with tabStyle but we can't check focused with that.
Using react-navigation v5 and createBottomTabNavigator for bottom tabs.
Here's my code:
<BottomTab.Navigator
tabBarOptions={{
activeTintColor: colors.brown,
labelPosition: 'below-icon',
}}>
<BottomTab.Screen
name="Home"
component={HomeTabNav}
options={{
tabBarLabel: 'Home',
tabBarIcon: ({focused}) => {
return focused ? (
<HomeSelectedIcon height={ms(24)} width={ms(24)} />
) : (
<HomeIcon height={ms(24)} width={ms(24)} />
);
},
}}
/>
...
</BottomTab.Navigator>
);
};
Thanks in advance!
I figured it out myself by making a custom tabbar icon if someone needs to achieve this using the bottom-tab bar only.
Here's the code.
<BottomTab.Navigator
tabBarOptions={{
activeTintColor: colors.brown,
showLabel: false,
tabStyle: styles.tabStyle,
style: styles.tabContainerStyle,
}}>
<BottomTab.Screen
name="Home"
component={HomeTabNav}
options={{
tabBarLabel: 'Home',
tabBarIcon: ({focused}) => {
return focused ? (
<View style={styles.labelFocusedContainer}>
<HomeSelectedIcon height={24} width={24} />
<Text style={styles.labelFocusedStyle}>Home</Text>
</View>
) : (
<View style={styles.labelContainer}>
<HomeIcon height={24} width={24} />
<Text style={styles.labelStyle}>Home</Text>
</View>
);
},
}}
/>
...
</BottomTab.Navigator>
const styles = StyleSheet.create({
labelContainer: {
alignItems: 'center',
width: '100%',
},
labelFocusedContainer: {
alignItems: 'center',
width: '100%',
borderBottomWidth: 3,
borderBottomColor: colors.brown,
},
labelFocusedStyle: {
textAlign: 'center',
marginVertical: 8,
color: colors.brown,
backgroundColor: 'transparent',
fontSize: 10,
},
labelStyle: {
textAlign: 'center',
marginVertical: 8,
color: colors.veryDarkgray,
backgroundColor: 'transparent',
fontSize: 10,
},
});
But the best and easy way to do this is by using createMaterialTopTabNavigator and using these props.
tabBarPosition="bottom"
tabBarOptions={{
showIcon: true,
pressOpacity: 1,
iconStyle: styles.iconStyle,
showLabel: true,
activeTintColor: colors.brown,
indicatorStyle: {
borderWidth: 2,
borderColor: colors.brown,
},
This does not seem to be possible / easily achievable with bottom-tabs, but you could use the material version - #react-navigation/material-top-tabs and configure it to match your needs, specifically using tabBarPosition="bottom" and tabBarOptions={{ indicatorStyle: { backgroundColor } }}.
You can check more options in the docs: https://reactnavigation.org/docs/material-top-tab-navigator/#tabbaroptions
import * as React from 'react';
import { Text, View } from 'react-native';
import { NavigationContainer } from '#react-navigation/native';
import { createMaterialTopTabNavigator } from '#react-navigation/material-top-tabs';
const Tabs = createMaterialTopTabNavigator();
export default function App() {
return (
<NavigationContainer>
<Tabs.Navigator tabBarPosition="bottom" tabBarOptions={{ indicatorStyle: { backgroundColor: 'red' } }}>
<Tabs.Screen name="screen 1" component={View} />
<Tabs.Screen name="screen 2" component={View} />
</Tabs.Navigator>
</NavigationContainer>
);
}
The best answer would be to use the tabBarButton prop to override and add your own custom styles to the container of the tab button.
https://reactnavigation.org/docs/bottom-tab-navigator#tabbarbutton
const CustomTabButton = (props) => (
<Pressable
{...props}
style={
props.accessibilityState.selected
? [props.style, styles.activeTab]
: props.style
}
/>
)
styles.activeTab is the custom style you want to add, be careful to spread the props.style to get the default styles from the library like width, padding, height etc
props.accessibilityState.selected will add styles according to condition if you want styles for all the tabs you can remove the condition.
Inside screeenOptions prop on navigator or the option props of each screen.
tabBarButton: CustomTabButton
Using material top tab is not a good solution because it does not support well with a keyboard. But bottom tabs do work well with the keyboard.

React Native add border Radius to active tab bar

I want to implement a top border radius to the active tab bar navigator to be like below image.
My code below is implementing a border radius to the whole createBottomTabNavigator but not as I expected above
<Tab.Navigator
tabBarOptions={{
showLabel:false,
activeBackgroundColor: COLORS.reddish,
inactiveBackgroundColor: COLORS.transparent,
style:{
position:'absolute',
bottom:0,
right:0,
left:0,
elevation:0,
height:55,
borderTopRightRadius: 20,
borderTopLeftRadius: 20,
},
}}
>
<Tab.Screen
name="Home"
component={Home}
options={{
tabBarIcon:({focused })=> (
<View style={{
alignItems:'center',
justifyContent:'center',
}}>
<Image
source={icons.home}
resizeMode='contain'
style={{
width:30,
height:30,
tintColor:focused?COLORS.white: COLORS.reddish
}}
/>
<Text style={{
color:focused?COLORS.white:COLORS.reddish,
}}>HOME</Text>
</View>
)
}}
/>
//code for other Tab.Screen
</Tab.Navigator>
Kindly assist
I was able to figure out after going through React Navigation documentation.
To styles an individual tab I've added tabStyle in tabBarOptions props as seen in below code.
<Tab.Navigator
tabBarOptions={{
showLabel:false,
activeBackgroundColor: COLORS.reddish,
inactiveBackgroundColor: COLORS.transparent,
tabStyle:{ //Add this
borderTopRightRadius:20,//add border top right radius
borderTopLeftRadius:20,//add border top left radius
paddingVertical:3
},
style:{
position:'absolute',
bottom:0,
right:0,
left:0,
elevation:0,
height:60,
},
}}
>
The results are as per below just as I wanted
Thank you #Ankit Patel.
I have not tried your method but i'll definitely try it
I Added border radius to each tab item like this :
<Tab.Navigator
screenOptions={{
tabBarActiveBackgroundColor: 'red',
headerShown: false,
tabBarItemStyle: {
borderRadius: 200,
},
}}
tabBarOptions={{
tabStyle: {
borderTopRightRadius: 8,
borderTopLeftRadius: 8,
backgroundColor: colors.white,
},
}}
activeBackgroundColor: COLORS.reddish, First remove this and
<View style={{
alignItems:'center',
borderTopRightRadius: 20,
borderTopLeftRadius: 20,
backgroungColor:focused?COLORS.reddish: COLORS.white
justifyContent:'center',
}}>
in Tab.screen View Change this

React Native Bottom Tab bar like on Instagram

I have searched a lot about Navigation in React Native. I saw a lot of possibilities but I never found something like on Instagram. I did found a Bottom Tab bar Navigation, but there is always:
a) An animation
b) A Text
c) A color
d) .........
But I never found a bar like this. Do I have to use React Navigation for Nativgation or is it just helpful? What if I don't use it? :) And how could I do a menu bar like this (I think you all know how Instagram Navigation works):
Btw. I don't use expo :)
I use import { createMaterialTopTabNavigator } from '#react-navigation/material-top-tabs'; because I was having many problems with the #react-navigation/bottom-tabs.
To use on bottom you can do this:
const Tab = createMaterialTopTabNavigator();
...
<Tab.Navigator
initialRouteName="Home"
tabBarPosition="bottom"
lazy={true}
tabBarOptions={{
activeTintColor: colors.orange,
inactiveTintColor: 'gray',
showIcon: true,
indicatorStyle: { backgroundColor: 'transparent' },
labelStyle: {
fontFamily: 'GothamRounded-Bold',
fontSize: widthPercentageToDP('3%'),
bottom: 1.5,
alignSelf: 'flex-start'
},
activeTintColor: colors.orange,
inactiveTintColor: colors.greyLight,
style: {
elevation: 5,
shadowColor: '#000',
shadowOpacity: 0.2,
shadowOffset: {
height: 1,
width: 0
},
position: 'absolute',
width: widthPercentageToDP('100%'),
zIndex: 8,
borderTopColor: 'transparent',
bottom: keyboard,
justifyContent: 'center'
},
upperCaseLabel: false
}}>
...
And then you can customize as you want
To change icon I do this:
<Tab.Screen
name="Home"
component={Home}
options={{
tabBarIcon: ({ focused }) => (
<FastImage
source={focused ? homeOrange : homeGrey}
style={{ flex: 1, width: null, height: null }}
resizeMode="contain"
/>
),
tabBarLabel: 'Home'
}}
/>

How to horizontally center TopTabNavigator in React Native?

I've been struggling to apply the proper styling so that my Top Tab Navigator is horizontally centered on the screen. I've tried applying AlignItems: center to the different style props but that does not seem to work. Any tips?
Here is the documentation I have been following: https://reactnavigation.org/docs/material-top-tab-navigator/
import React from "react";
import { createMaterialTopTabNavigator } from "#react-navigation/material-top-tabs";
import Creators from "../../screens/Creators/Creators";
import Feed from "../../screens/Feed/Feed";
import Profile from "../../screens/Profile/Profile";
const Tab = createMaterialTopTabNavigator();
function TabNav() {
return (
<Tab.Navigator
tabBarOptions={{
labelStyle: {
fontSize: 12,
color: "white",
},
tabStyle: {
width: 100,
height: 40,
marginTop: 50,
},
indicatorStyle: {
backgroundColor: "white",
},
style: {
backgroundColor: "#03182d",
},
}}
>
<Tab.Screen name="Creators" component={Creators} />
<Tab.Screen name="Feed" component={Feed} />
<Tab.Screen name="Profile" component={Profile} />
</Tab.Navigator>
);
}
export default TabNav;
remove tabStyle and it will work perfectly like this
<Tab.Navigator
tabBarOptions={{
labelStyle: {
fontSize: 12,
color: "white",
},
//remove this
//tabStyle: {
// width: 100,
// height: 40,
// marginTop: 50,
},
indicatorStyle: {
backgroundColor: "white",
},
style: {
backgroundColor: "#03182d",
},
}}
>
<Tab.Screen name="Creators" component={Creators} />
<Tab.Screen name="Feed" component={Feed} />
<Tab.Screen name="Profile" component={Profile} />
</Tab.Navigator>
or remove only width as it is smudging your tabs