import { createMaterialTopTabNavigator } from '#react-navigation/material-top-tabs';
const Tab = createMaterialTopTabNavigator();
function MyTabs() {
return (
<Tab.Navigator
initialRouteName="Feed"
screenOptions={{
tabBarActiveTintColor: '#e91e63',
tabBarLabelStyle: { fontSize: 12 },
tabBarStyle: { backgroundColor: 'powderblue' },
}}
>
<Tab.Screen
name="Feed"
component={Feed}
options={{ tabBarLabel: 'Home' }}
/>
<Tab.Screen
name="Notifications"
component={Notifications}
options={{ tabBarLabel: 'Updates' }}
/>
<Tab.Screen
name="Profile"
component={Profile}
options={{ tabBarLabel: 'Profile' }}
/>
</Tab.Navigator>
);
}
I am using the above code. I am trying to get active tab index and name. So i can do some condition base work. but not able to get tab index and name so any help here.
Hi~ Have you already solved it?
You just need to make a few modifications in your code.
your code
<Tab.Screen
name="Feed"
component={Feed}
options={{ tabBarLabel: 'Home' }}
/>
change to this code
<Tab.Screen
name="Feed"
options={{ tabBarLabel: 'Home' }}
>
{props => <Feed {...props} />}
</Tab.Screen>
In this way, you can check 'name' and 'key' as props in the component.
example:
route:
name: "Feed"
key: "Feed-your key code"
params: undefined
Symbol(CHILD_STATE): undefined
__proto__: Object
__proto__: Object
Hope this helps you!
Related
I have a screen with two routes pointing to it. These two routes are in a BottomTabNavigator. My problem is that the target screen is rendered twice. A different rendering for each route.
<Tab.Screen name="Home" component={ HomeScreen } options={{ title: 'Home' }} />
<Tab.Screen name="NewProduct" component={ HomeScreen } options={{ title: 'Neues', lazy:false }} />
Is there any way to do this without double rendering?
This was my solution:
<Tab.Screen name="Home" component={ HomeScreen } options={{ title: 'Home' }} />
<Tab.Screen
name="New"
component={HomeScreen}
options={({ navigation }) => ({
tabBarButton: (props) => (
<TouchableOpacity
style={{
}}
onPress={() => {
setNewProductInput(true);
navigation.navigate('Home');
}}
>
<Text>New</Text>
</TouchableOpacity>
),
})}
/>
export default function Navigation({ colorScheme }: { colorScheme:
ColorSchemeName }) {
return (
<NavigationContainer
linking= {LinkingConfiguration}
theme={colorScheme === 'dark' ? DarkTheme : DefaultTheme}>
<RootNavigator />
</NavigationContainer> ); }
function RootNavigator() {
return (
<Stack.Navigator screenOptions={{
headerShown: false}}
>
<Stack.Screen name="Root" component={BottomTabNavigator} options={{ headerShown: false
}} />
<Stack.Screen name="NotFound" component={NotFoundScreen} options={{ title: 'Oops!' }}
/>
<Stack.Group screenOptions={{ presentation: 'fullScreenModal' }}>
<Stack.Screen name="Modal" component={ModalScreen} />
<Stack.Screen name="Paywall1" component={Paywall1Screen} />
<Stack.Screen name="Paywall" component={PaywallScreen} />
<Stack.Screen name="WelcomeScreen" component={WelcomeScreen} />
</Stack.Group>
</Stack.Navigator>
);
}
const BottomTab = createBottomTabNavigator<RootTabParamList>();
function BottomTabNavigator() {
const colorScheme = useColorScheme();
return (
<BottomTab.Navigator
initialRouteName="HomeScreen"
screenOptions={{
headerShown: false,
tabBarActiveTintColor: Colors[colorScheme].tint,
}}>
<BottomTab.Screen
name="HomeScreen"
component={HomeScreen}
options={{
tabBarLabel: 'Today',
tabBarIcon: ({ color }) => <TabBarIcon name="home" color=
{color} />,
}}
/>
<BottomTab.Screen
name="Episodes"
component={EpisodesScreen}
options={{
title: 'Episodes',
tabBarIcon: ({ color }) => <TabBarFeatherIcon
name="headphones" color={color} />,
}}
/>
<BottomTab.Screen
name="TabThree"
component={TabThreeScreen}
options={{
title: 'Guides',
tabBarIcon: ({ color }) => <TabBarFeatherIcon name="bookmark" color={color} />,
}}
/>
<BottomTab.Screen
name="CommunityScreen"
component={CommunityScreen}
options={{
title: 'Community',
tabBarIcon: ({ color }) => <TabBarIcon name="users" color=
{color} />,
}}
/>
<BottomTab.Screen
name="ProfileScreen"
component={ProfileScreen}
options={{
title: 'Profile',
tabBarIcon: ({ color }) => <TabBarIcon name="user" color=
{color} />,
}}
/>
</BottomTab.Navigator>
);
}
Using EXPO version 43.0.1 with react-navigation/core 6.1.0 react-navigation/bottom-tabs 6.0.9
I need the bottomTabNavigator to show on all screens and not just the 5 i have listed in my bottomTabNavigator. nothing on here seems to help with this just the opposite of keeping them off the screens the user doesnt want them on.
For example if i'm on my Paywall screen i do not see my bottomTabs (this route is not included in the bottomTabNavigator)
At the current moment in your question you do not mention what version or the entire file for the component RootNavigator. At glance, if you're using React Navigation 6 it needs a NavigationContainer and I don't see that in your question, example with NavigationContainer:
import { NavigationContainer } from '#react-navigation/native'
import { createNativeStackNavigator } from '#react-navigation/native-stack'
const Stack = createNativeStackNavigator()
const RootNavigator = () => {
return (
<NavigationContainer>
<Stack.Navigator
screenOptions={{
headerShown: false,
}}
>
<Stack.Screen name='Root' component={BottomTabNavigator} options={{ headerShown: false }} />
<Stack.Screen name='NotFound' component={NotFoundScreen} options={{ title: 'Oops!' }} />
<Stack.Group screenOptions={{ presentation: 'fullScreenModal' }}>
<Stack.Screen name='Modal' component={ModalScreen} />
<Stack.Screen name='Paywall1' component={Paywall1Screen} />
<Stack.Screen name='Paywall' component={PaywallScreen} />
<Stack.Screen name='WelcomeScreen' component={WelcomeScreen} />
</Stack.Group>
</Stack.Navigator>
</NavigationContainer>
)
}
export default RootNavigator
I need to hide nav bar on top in specific screens. How to achieve?. i am using react-navigation/material-top-tabs
I need to hide nav bar on top in specific screens. How to achieve?. i am using react-navigation/material-top-tabs
I need to hide nav bar on top in specific screens. How to achieve?. i am using react-navigation/material-top-tabs
//page 1 <Stack.Navigator headerMode="none" initialRouteName="Connection">
<Stack.Screen
name="Connection"
component={UserScreen}
options={{ unmountOnBlur: true }}
/>
</Stack.Navigator>
//page2 <Tab.Navigator
// screenOptions={{ tabBarVisible: false }}
// screenOptions={({ route }) => ({
// tabBarVisible: false,
// })}
initialRouteName="UserTabStack"
tabBarOptions={{
labelStyle: {
fontWeight: "bold",
},
indicatorStyle: {
backgroundColor: "black",
},
}}
>
<Tab.Screen
name="UserTabStack"
// component={UserList}
component={UserTabStack}
options={{ tabBarLabel: "Userlist" }}
listeners={({ route }) => {
setTabPage(route.name);
}}
/>
<Tab.Screen
name="GroupList"
// component={GroupList}
component={GroupTabStack}
options={{ tabBarLabel: "GroupList" }}
listeners={({ route }) => {
setTabPage(route.name);
}}
/>
</Tab.Navigator> //page3 <Stack.Navigator headerMode="none" initialRouteName="UserList">
<Stack.Screen
name="UserList"
component={UserList}
options={{ unmountOnBlur: true }}
/>
<Stack.Screen
name="AddConnection"
component={AddUserScreen}
options={{ unmountOnBlur: true }}
/>
<Stack.Screen
name="Chat"
component={ChatScreen}
options={{ unmountOnBlur: true }}
/>
</Stack.Navigator>
set headerShown to false in Stack.Screen options
<Stack.Screen
name="UserList"
component={UserList}
options={{ unmountOnBlur: true, headerShown: false }}
/>
Per the React Navigation Docs, you can hide the tab bar on specific screens by changing your navigation structure. In their example:
function HomeTabs() {
return (
<Tab.Navigator>
<Tab.Screen name="Home" component={Home} />
<Tab.Screen name="Feed" component={Feed} />
<Tab.Screen name="Notifications" component={Notifications} />
</Tab.Navigator>
);
}
function App() {
return (
<Stack.Navigator>
<Stack.Screen name="Home" component={HomeTabs} />
<Stack.Screen name="Profile" component={Profile} />
<Stack.Screen name="Settings" component={Settings} />
</Stack.Navigator>
);
}
The tab navigator is inside the first screen, and is the first component in your app's navigator. The following components are the two components that you don't want the top bar to be shown on, so in this example, Settings and Profile.
I'm trying to get the Recipes header in the following image to display above the tab navigator (home and settings in the image below). Currently I have the tab navigator in a stack navigator. On the stack navigator I defined a title and headerTitle but neither are displaying. How can I get the header above? Thanks!
This is what it looks like currently:
I want to achieve something similar to this:
This is my stack nav code:
<NavigationContainer>
<Tab.Navigator
shifting={false}
labeled={false}
initialRouteName="Home"
activeColor="#32CA81"
barStyle={styles.navContainer}
screenOptions={{
headerShown: false,
}}
tabBarOptions={{
activeTintColor: '#e91e63',
}}
>
<Tab.Screen
name="Camera"
component={Camera}
options={{
tabBarLabel: "Camera",
tabBarIcon: ({ color }) => (
<MaterialIcons name="camera-alt" color={color} size={26} />
),
}}
/>
<Tab.Screen
name="Home"
component={Home}
options={{
title: "Recipes",
headerTitle: "Recipes",
tabBarLabel: "Recipes",
tabBarIcon: ({ color }) => (
<MaterialIcons name="restaurant-menu" color={color} size={26} />
),
}}
/>
<Tab.Screen
name='Saved'
component={SavedScreen}
options={{
shifting: true,
tabBarLabel: 'Saved',
tabBarIcon: ({color}) => (
<MaterialIcons name='favorite' color={color} size={26} />
),
}}
/>
</Tab.Navigator>
</NavigationContainer>
This is my tab nav code:
return (
<Tab.Navigator>
<Tab.Screen name="Home" component={Recipes} />
<Tab.Screen name="Settings" component={Recipes} />
</Tab.Navigator>
);
I ended up wrapping the component with the tabs, with a stack navigator. I put the text component and tabs on the same stack screen.
Learning React Native and I've run into a navigation issue using createBottomTabNavigator.
I have my screen displayed with 2 links on the bottom tab. Link 1 - Novels, Link 2 - Profile.
When I click on Link 2, I want to go to my profile screen (which it does) but I want to replace the bottom tab with a new one (which it doesn't).
I've tried using the tabPress event and I can see using console.log that it catches the event, but when I add the navigation param it stops working.
here's the relevant code:
const Stack = createStackNavigator();
const BottomTab = createBottomTabNavigator();
const headerTitle = "My Title";
function NovelsStack() {
return (
<Stack.Navigator screenOptions={{
headerStyle: {
backgroundColor: '#000',
},
headerTintColor: '#fff',
headerTitleStyle: {
fontWeight: 'bold',
fontSize: 16,
},
}}>
<Stack.Screen name="Home" component={HomeScreen} options={{ headerTitle: () => <HeaderTitle title={headerTitle} /> }} />
<Stack.Screen name="Novels" component={TabNavigation} options={{ headerTitle: () => <HeaderTitle title={headerTitle} /> }} />
<Stack.Screen name="Novel" component={SelectedNovelNavigation} options={{ headerTitle: () => <HeaderTitle /> }} />
<Stack.Screen name="Profile" component={ProfileNavigation} options={{ headerTitle: () => <HeaderTitle title={headerTitle} /> }} />
</Stack.Navigator>
);
}
function TabNavigation() {
return (
<BottomTab.Navigator
tabBarOptions={{
labelStyle: styles.mainTabBarLabels
}}
>
<BottomTab.Screen name="Novels" options={{ title: "Novels" }} component={NovelsScreen} />
{isAuthenticatedUser() ? (<BottomTab.Screen name="Profile" component={ProfileScreen} />)
: (<BottomTab.Screen name="Login" component={LoginScreen} listeners={({ navigation, route }) => ({
tabPress: e => {
// Prevent default action
console.log(navigation)
e.preventDefault();
},
})} />)
}
</BottomTab.Navigator>
);
}
function ProfileNavigation() {
return (
<BottomTab.Navigator
tabBarOptions={{
labelStyle: styles.novelsTabBarLabels
}}>
<BottomTab.Screen name="Profile" component={ProfileScreen} options={{ title: "Profile" }} />
</BottomTab.Navigator>
);
}
function SelectedNovelNavigation() {
return (
<BottomTab.Navigator
tabBarOptions={{
labelStyle: styles.novelsTabBarLabels
}}>
<BottomTab.Screen name="Novel" component={NovelScreen} />
<BottomTab.Screen name="Comments" component={CommentsScreen} options={{ title: "Comments" }} />
<BottomTab.Screen name="Ratings" component={RatingsScreen} options={{ title: "Ratings" }} />
<BottomTab.Screen name="Related" component={RelatedNovelsScreen} options={{ title: "Related" }} />
</BottomTab.Navigator>
)
}
What I want to happen is when the user presses the "Profile" tab on the TabNavigation Stack, that the navigation takes the user to show the ProfileNavigation where I can add additional profile tabs, but I just can't get that hooked up correctly. Been looking at the docs and other posts about it, but still stuck.
Thanks in advance for any help
As usual, once you reach out for help you get the answer. In the docs here (https://reactnavigation.org/docs/bottom-tab-navigator/) and here (https://reactnavigation.org/docs/stack-actions/#replace) I can customize the tabBar and use the navigation.replace.
The good ole docs, I was all around it, just didn't see it.