Remove icon from tab navigator that nested in drawer navigator - react-native

I make drawer.navigator that nested tab.navigator, Then show an icon that I didn't add to the code! and tried to remove it but couldn't...!! Does anybody have an idea?
<NavigationContainer>
<Drawer.Navigator>
<Drawer.Screen name="Home">
{()=>
<Tab.Navigator screenOptions={{
***// I try this but didn't work.***
// tabBarIcon: ()=>{return null}
tabBarIcon: ({focused,color,size})=>
{
***// I do what in here???***
},
tabBarIconStyle:{
// I try this too but didn't work.
display: 'none',
},
tabBarStyle: {
borderTopColor: 'rgba(0, 0, 0, .2)',
},
tabBarLabelStyle: {
fontSize: 13,
// I use one of this then run code! one time I use two of this! but didn't
worked!!
textAlignVertical: 'center',
justifyContent: 'center',
},
tabBarLabelPosition: 'beside-icon'
}}
>
<Tab.Screen name="Todos"
options={{
headerShown: false,
}}>
{ ()=>
<Home
todos={todos}
pressHandler={pressHandler}
submitHandler={submitHandler}
/>}
</Tab.Screen>
<Tab.Screen name='CompleteTodos' options={{headerShown: false}}>
{()=>
<CompleteTodos
todos={todos}
pressHandler={pressHandler}
/>}
</Tab.Screen>
</Tab.Navigator>
}
</Drawer.Screen>
<Drawer.Screen name="About" component={About} />
<Drawer.Screen name="Settings" component={Settings} />
</Drawer.Navigator>
</NavigationContainer>
with no options
with display: none. BUT THE LABEL DIDN't CENTERED!!

You can completely replace the tab component for a custom made by you.
As noted in the React Navigation docs:
tabBarButton: props => <TouchableOpacity {...props} />
You can find further information on how to fully customized your navigation here: https://reactnavigation.org/docs/bottom-tab-navigator

Related

Independent stack navigation outside tab and drawer navigation in React-Native

I use
react-native:0.68.2
react-navigation/bottom-tabs:6.3.1
react-navigation/drawer:6.4.1
react-navigation/native:6.0.10
react-navigation/stack:6.2.1
And I have next navigation structure:
<Drawer.Navigator>
<Tab.Navigator>
<Stack.Navigator>
<Screen1>
<Screen2>
</Stack.Navigator>
</Tab.Navigator>
</Drawer.Navigator>
It looks like drawer slide menu from left side and bottom tabs on the main screen. You can see short video of it by next link
What do I want
I want to open new screen from Screen1 like independent screen (without tabs and drawer). It looks like new Activity in Android or new view controller in iOS.
you need to try this
const TabStack = () => {
return (
<Tab.Navigator
initialRouteName="LiveRate"
screenOptions={{
tabBarActiveBackgroundColor: colors.activeTabColor,
tabBarInactiveBackgroundColor: colors.inactiveTabColor,
tabBarStyle: {
backgroundColor: '#f46023',
height:60
},
}}>
<Tab.Screen
name="LiveRate"
component={LiveRateScreen}
options={{
tabBarLabel: () => {
return (<Text style={{color:'white', fontSize:12, marginBottom:5}}>Live Rate</Text>)
},
headerShown: false,
tabBarIcon: ({ focused }) => (
<Image
source={
focused
? Images.liverate
: Images.liverate
}
style={{
width: 30,
height: 30,
resizeMode:'contain'
// padding:5
}}
/>
),
}}
/>
<Tab.Screen
name="AboutUs"
component={AboutUsScreen}
options={{
tabBarLabel: () => {
return (<Text style={{color:'white', fontSize:12, marginBottom:5}}>About Us</Text>)
},
headerShown: false,
tabBarIcon: ({ focused, color, size }) => (
<Image
source={
focused
? Images.aboutus
: Images.aboutus
}
style={{
width: 30,
height: 30,
resizeMode:'contain'
// padding:5
}}
/>
),
}}
/>
<Tab.Screen
name="booking"
component={BookingNumberScreen}
options={{
tabBarLabel: () => {
return (<Text style={{color:'white', fontSize:12, marginBottom:5}}>Booking Number</Text>)
},
headerShown: false,
tabBarIcon: ({ focused, color, size }) => (
<Image
source={
focused
? Images.booking
: Images.booking
}
style={{
width: 30,
height: 30,
resizeMode:'contain'
}}
/>
),
}}
/>
<Tab.Screen
name="notification"
component={NotificationScreen}
options={{
tabBarLabel: () => {
return (<Text style={{color:'white', fontSize:12, marginBottom:5}}>Notification</Text>)
},
headerShown: false,
tabBarIcon: ({ focused, color, size }) => (
<Image
source={
focused
? Images.notificationbell
: Images.notificationbell
}
style={{
width: 30,
height: 30,
resizeMode:'contain'
}}
/>
),
}}
/>
</Tab.Navigator>
);
};
const NavigationUtil = () => {
return (
<NavigationContainer ref={navigationRef}>
<Stack.Navigator initialRouteName="SlpashScreen">
<Stack.Screen
name="tabStack"
component={TabStack} <----- you also pass your drawer stack
options={{headerShown: false}}
/>
<Stack.Screen
name="Registration"
component={RegistrationScreen}
options={{headerShown: false}}
/>
<Stack.Screen
name="SlpashScreen"
component={SlpashScreen}
options={{headerShown: false}}
/>
</Stack.Navigator>
</NavigationContainer>
);
};
this is my code
hop it's working

whenever I am trying to navigate to another page, react-navigation is pushing me to the previous page

I find difficulty navigating to another page using react-native-navigation,
the workflow which I am looking for is A -> B and then when I press any button in B should go to A,
what is happening whenever I am clicking the button in A it is going to B but without clicking any button it is redirecting me to A again, the same issue happens in the bottom tab navigator too.
this is my code for stack and bottom tab navigator,
function MyTabs() {
const isDarkMode = useColorScheme() === 'dark';
return (
<Tab.Navigator
screenOptions={({ route }) => ({
headerShown: false,
tabBarShowLabel: false,
gestureEnabled: false,
tabBarStyle: {
backgroundColor: isDarkMode ? Color.Black : Color.White,
borderTopWidth: 1,
borderColor: isDarkMode ? Color.White : Color.White,
height: 80,
},
tabBarIcon: ({ focused }) => (
<View>
{route.name === 'Profile' ? (
<MaterialIcons
name="person"
size={30}
color={isDarkMode ? (focused ? Color.White : Color.DarkGrey) : (focused ? Color.Black : Color.LightGrey)}
style={{
textAlign: 'center',
marginTop: 10
}}
/>
) : (
<Image
source={Images.Explore}
resizeMode="contain"
style={{
width: 30,
height: 30,
tintColor: isDarkMode ? (focused ? Color.White : Color.DarkGrey) : (focused ? Color.Black : Color.LightGrey),
marginTop: 8
}}
/>
)}
</View>
),
tabBarLabelStyle: {
fontSize: 15,
}
})}
>
<Tab.Screen name="Explore" component={Explore} />
<Tab.Screen name="Profile" component={Profile} />
</Tab.Navigator>
);
}
const Stack = createNativeStackNavigator();
export default function App() {
return (
<NavigationContainer>
<Stack.Navigator
initialRouteName="Splash"
screenOptions={{
headerShown: false,
}}
>
<Stack.Screen name="Splash" component={Splash} options={{ headerShown: false }} />
<Stack.Screen name="Login" component={Login} options={{ headerShown: false }} />
<Stack.Screen name="Register" component={Register} options={{ headerShown: false }} />
<Stack.Screen name="BottomTabs" component={MyTabs} options={{ headerShown: false, gestureEnabled: false, }} />
</Stack.Navigator>
</NavigationContainer>
);
}
I thing you need to know this
click here

How to inject NativeID to React Navigation material-top-tabs?

I am using #react-navigation/material-top-tabs to display tabs in my application. How can I inject NativeID to tabs to have an access to them with e.g. Selenium?
The only way that I found was using tabBar property, creating custom tabs and adding NativeID to TouchableOpacity. Is there more simple way?
<NavigationContainer>
<Tab.Navigator tabBar={(props) => <MyTabBar {...props} />} >
<Tab.Screen name="Home" component={HomeScreen} />
<Tab.Screen name="Settings" component={SettingsScreen} />
<Tab.Screen name="Profile" component={ProfileScreen} />
</Tab.Navigator>
</NavigationContainer>
function MyTabBar({ state, descriptors, navigation, position }) {
return (
<View style={{ flexDirection: 'row', paddingTop: 20 }}>
{
state.routes.map((route, index) => {
// ....
return (
<TouchableOpacity nativeID={"tab_"+label} >
<Animated.Text style={{ opacity }}>{label}</Animated.Text>
</TouchableOpacity>
);
})}
</View>
);
}

How to solve navigation.navigate error when set TouchableOpacity in StackScreen header options?

I want to add a button(icon) on stack header(on right side). On-click it goes to that page but it's not working. It appears 'undefined is not an object (evaluating 'navigation.navigate')'.
Below is my code:
<Stack.Navigator>
<Stack.Screen name="Page1" component={Page1} />
<Stack.Screen
name="Page2"
component={Page2}
options={{
headerRight: () => (
<View>
<TouchableOpacity
onPress={() => navigation.navigate('Page3')}>
<Image source={require('../assets/image.png')} />
</TouchableOpacity>
</View>
)
}}
/>
<Stack.Screen name="Page4" component={Page4} />
<Stack.Screen name="Page5" component={Page5} />
</Stack.Navigator>
You can pass the navigation from the options to the headerRight:
options={({navigation}) => ({
headerRight: () => (
...
),
})}
or useNavigation():
const navigation = useNavigation();
EDIT 2:
fixed your snack code and its working fine:
You had to add a stackScreen called 'MyorderStack' because you're trying to navigate to that.
<NavigationContainer independent={true}>
<Stack.Navigator screenOptions={{ headerTintColor: 'blue' }}>
<Stack.Screen name="Global Page" component={AppNavigator} options={{ headerShown: false }} />
<Stack.Screen name="DetailOne" component={DetailOne} options={({navigation}) => ({ headerBackTitleVisible: false, title: 'Global Page',
headerRight: () => (
<View style={{flexDirection: 'row',justifyContent: 'flex-end',width: '50%'}}>
<View style={{ marginRight: 10 }}>
<TouchableOpacity onPress={() => navigation.navigate('MyorderStack')}>
<Image source={require('./assets/shop.png')} style={styles.Image} />
</TouchableOpacity>
</View>
</View>
), headerTitleAlign:'center', headerTintColor:colors.primary
})}
/>
<Stack.Screen name="DetailTwo" component={DetailTwo} options={{headerBackTitleVisible: false, headerTitleAlign: 'center', title: 'Global Page', headerTintColor: colors.primary}} />
<Stack.Screen name="MyorderStack" component={MyorderStack} options={{headerBackTitleVisible: false, headerTitleAlign: 'center', title: 'Global Page', headerTintColor: colors.primary}} />
</Stack.Navigator>
</NavigationContainer>
Navigation is only defined within the screen's components. In your case, you can try useNavigation hook to navigate to different screen. Import it like:
import { useNavigation } from '#react-navigation/native';
and declare it like:
const navigation = useNavigation();
Then you it to your TouchableOpacity prop like onPress={() => navigation.navigate('Page3')}.
Hope this works for you. Thanks

Redirecting to a Stack navigator page from bottomTabNavigator

I have a project with a Stack and bottomTab navigator and I want to redirect to a stack navigator page from the bottomTabNavigator
Here is the code for my project:
Routes.js i.e Stack Navigator
<UserContext.Provider value={{userDetails, setUserDetails}}>
<Stack.Navigator
headerMode="screen"
screenOptions={{
header: ({scene, previous, navigation}) => {
const {options} = scene.descriptor;
const title =
options.headerTitle !== undefined
? options.headerTitle
: options.title !== undefined
? options.title
: scene.route.name;
return <Header title={title} />;
},
}}>
{userDetails ? (
<>
<Stack.Screen
name="home"
options={{title: 'Home'}}
component={BottomTabNavigator}
/>
<Stack.Screen
name="library"
component={Library}
options={() => ({
headerTitle: 'My Library',
})}
/>
<Stack.Screen
name="bookDetails"
component={BookDetails}
options={{title: 'Book Details'}}
/>
<Stack.Screen
name="reviews"
component={AllReviews}
options={{headerTitle: 'View all Reviews'}}
/>
</>
) : (
<Stack.Screen name="Login" component={Login} />
)}
</Stack.Navigator>
</UserContext.Provider>
bottomTabNavigator.js:
<Tab.Navigator
tabBarOptions={{activeTintColor: 'green', style: {height: tabBarHeight}}}>
<Tab.Screen
name={'Home'}
component={Home}
options={{
tabBarIcon: ({color}) => (
<AntDesign name="home" size={27} color={color} />
),
}}
/>
<Tab.Screen
name={'Search'}
component={Home}
options={{
tabBarIcon: ({color}) => (
<AntDesign name="search1" size={25} color={color} />
),
}}
/>
<Tab.Screen
name={'My Library'}
component={Library}
options={{
tabBarIcon: ({color}) => {
return (
<View
style={{
position: 'absolute',
bottom: 7,
height: 65,
width: 65,
borderRadius: 65,
backgroundColor: 'green',
justifyContent: 'center',
alignItems: 'center',
shadowColor: '#000',
shadowOffset: {
width: 0,
height: 5,
},
shadowOpacity: 0.37,
shadowRadius: 7.49,
elevation: 12,
}}>
<AntDesign name="book" size={40} color={'white'} />
</View>
);
},
}}
/>
<Tab.Screen
name={'Browse'}
component={Home}
options={{
tabBarIcon: ({color}) => (
<AntDesign name="earth" size={25} color={color} />
),
}}
/>
<Tab.Screen
name={'More'}
component={More}
options={{
tabBarIcon: ({color}) => (
<Feather name="more-horizontal" size={30} color={color} />
),
}}
/>
</Tab.Navigator>
What I want to do is when I tap on My Library in the tabNavigator the headerTitle still says home, I want it to say ""
Here is how I tried to achieve this:
useLayoutEffect(() => {
navigation.setOptions({headerTitle: 'My Library'});
}, [navigation, route]);
Any help is appreciated
Thanks
I tried doing it automatically but I couldn't figure it out, but what I did was use my custom header component on each screen and hardcode the title of the screen, so the process may not be as efficient as letting react navigation do all the work, but it works fine for me
One workaround you can use is to hide the header in the Home Component of your Stack navigator. You can then create custom headers for each of the tab screens.