According to this doc
with the example
that gives this result :
why do I have always this result, with exactly the same code:
And the highlight on the tap doesn't work as well.
I checked all the dependencies and everything, it doesn't change.
Tips: I have the same result as this doc shows, why is that different ?
Here are my dependencies:
"dependencies": {
"#react-native-async-storage/async-storage": "^1.17.11",
"#react-navigation/material-bottom-tabs": "^6.2.10",
"#react-navigation/native": "^6.1.1",
"#react-navigation/native-stack": "^6.9.7",
"#react-navigation/stack": "^6.3.10",
"react": "18.1.0",
"react-native": "0.70.6",
"react-native-gesture-handler": "^2.8.0",
"react-native-paper": "^5.1.0",
"react-native-safe-area-context": "^4.4.1",
"react-native-screens": "^3.18.2",
"react-native-vector-icons": "^9.2.0"
},
You have to do some changes for same design. Enable shifting and labeled. Add tabBarColor in each Tab.screen.
function MyTabs() {
return (
<Tab.Navigator
initialRouteName="Feed"
activeColor="white"
labelStyle={{ fontSize: 12 }}
shifting={true}
labeled={true}
>
<Tab.Screen
name="Feed"
component={Feed}
options={{
tabBarLabel: 'Home',
tabBarColor: 'red',
tabBarIcon: ({ color }) => (
<MaterialCommunityIcons name="home" color={color} size={26} />
),
}}
/>
<Tab.Screen
name="Notifications"
component={Notifications}
options={{
tabBarLabel: 'Updates',
tabBarColor: 'blue',
tabBarIcon: ({ color }) => (
<MaterialCommunityIcons name="bell" color={color} size={26} />
),
}}
/>
<Tab.Screen
name="Profile"
component={Profile}
options={{
tabBarLabel: 'Profile',
tabBarColor: 'green',
tabBarIcon: ({ color }) => (
<MaterialCommunityIcons name="account" color={color} size={26} />
),
}}
/>
</Tab.Navigator>
);
}
I just changed all version, to previous and its working fine now:
react-native init datingapp --version 0.68.1
npm install #react-navigation/native#6.0.10
npm install react-native-screens#3.13.1
npm install react-native-safe-area-context#4.3.1
npm install react-native-paper#4.12.1
npm install react-native-vector-icons#9.1.0
npm install #react-navigation/material-bottom-tabs#6.2.1
npm install #react-native-async-storage/async-storage
npm install jotai
npm install #react-navigation/native-stack#6.6.2
npm install react-native-gesture-handler#2.6.1
npm install react-native-safe-area-context#4.3.1
npm install react-native-screens
Just set the background color that you want :
<Tab.Navigator
initialRouteName="Home"
activeColor="#f0edf6"
inactiveColor="#3e2465"
barStyle={{ backgroundColor: '#694fad' }}
>
{/* ... */}
</Tab.Navigator>
Related
I have a project that has stack and tab navigation in it. There is a strange problem it in which is: The tabs and screens are not touchable sometimes, although the screen is always scrollable is there is any ScrollView in that screen.
Note: The project was running fine for last 2 years but I recently(last month) migrated from mac intel to mac m1 chip using migration assistant.
This problem started appearing from the last week.
The Structure of the Project:
The Screen MainScreen is imported and called in app.js
MainScreen checks for the token and calls MainNavigation, which is
another screen
In MainNavigation I have 4 tabs like <Tab.Screen name="Dashboard"
component={DashboardStack}/>
Used import {createBottomTabNavigator} from
'#react-navigation/bottom-tabs'
Then there are 4 other screens each one for one tab like:
DashboardStack
Used import {createStackNavigator} from '#react-navigation/stack'
And inside DashboardStack file, I have all the files that will be for
Dashboard
Package.json
"react": "16.13.1",
"react-native": "0.63.4",
"#react-navigation/bottom-tabs": "^5.11.2",
"#react-navigation/native": "^5.8.10",
"#react-navigation/stack": "^5.12.8",
"react-native-safe-area-context": "^3.4.1",
"react-native-screens": "^2.16.1",
MainNavigation screen
function DashboardStack({navigation, route}) {
return <DashboardNavigation navigation={navigation} route={route} driverId={driverId} globalSettings={props.globalSettings} handleLogout={props.handleLogout}/>
}
return(
<NavigationContainer>
<Tab.Navigator tabBarOptions={{ showLabel: false, style:{bottom:5}}}
screenOptions={({route}) => ({tabBarIcon: ({focused}) => handleNavIcon(route.name, focused)})}
>
<Tab.Screen name="Dashboard" component={DashboardStack}/>
<Tab.Screen name="Billing" component={BillingStack} />
<Tab.Screen name="Rental" component={RentalStack} />
<Tab.Screen name="Support" component={SupportStack} />
<Tab.Screen name="Account" component={AccountStack} />
</Tab.Navigator>
</NavigationContainer>
)
DashboardNavigation.js
<DashboardStack.Navigator options={{ headerShown: true, }} screenOptions={{ headerBackTitleVisible: false, headerTitleAlign: "center", headerRight: () => <NotificationIcon driverId={props && props.driverId && props.driverId} navigation={props.navigation}/> }}>
<DashboardStack.Screen name="Dashboard" children={() => <Dashboard driverId={props.driverId} globalSettings={props.globalSettings} handleLogout={props.handleLogout} />} />
<DashboardStack.Screen name="Current Documents" component={carDocs} options={{ headerBackImage: () => <MaterialIcons size={Platform.OS == "ios" ? 30 : 25} name="arrow-back" style={{ paddingLeft: 10 }} /> }}></DashboardStack.Screen>
<DashboardStack.Screen name="Notifications" component={NotificationListScreen} options={{ headerBackImage: () => <MaterialIcons size={Platform.OS == "ios" ? 30 : 25} name="arrow-back" style={{ paddingLeft: 10 }} /> }}></DashboardStack.Screen>
<DashboardStack.Screen name="Notification Detail" component={NotificationDetailScreen} options={{ headerBackImage: () => <MaterialIcons size={Platform.OS == "ios" ? 30 : 25} name="arrow-back" style={{ paddingLeft: 10 }} /> }}></DashboardStack.Screen>
<DashboardStack.Screen name="Under Construction" component={ComingSoon} options={{ headerBackImage: () => <MaterialIcons size={Platform.OS == "ios" ? 30 : 25} name="arrow-back" style={{ paddingLeft: 10 }} /> }}></DashboardStack.Screen>
<DashboardStack.Screen name="Make a Payment" component={makePayment} options={{ headerBackImage: () => <MaterialIcons size={30} name="arrow-back" style={{ paddingLeft: 10 }} /> }}></DashboardStack.Screen>
<DashboardStack.Screen name="Verify Phone Number" component={VerifyPhoneNumber} options={{ headerBackImage: () => <MaterialIcons size={30} name="arrow-back" style={{ paddingLeft: 10 }} /> }}></DashboardStack.Screen>
</DashboardStack.Navigator>
The initial navigation works fine, but when I press return or press the same tab (to go back), the app is closed.
I use React Navigation v6+ and navigators like Stack and Material Bottom Tabs.
Main Navigation
<Tab.Navigator
initialRouteName='TabMovie'
activeColor="#f0edf6"
keyboardHidesNavigationBar={true}
inactiveColor="#000000"
shifting={true}
barStyle={{
borderWidth: 0,
elevation: 0,
height: (Platform.OS == 'ios') ? 80 : 54
}}
>
<Tab.Screen
name="TabMovie"
component={TabMovie}
options={{
tabBarLabel: 'Cine',
tabBarColor: '#EC9B45',
tabBarIcon: (({ color }) => (
<Icon color={color} size={25} name="videocam-outline" />
))
}}
/>
<Tab.Screen
name="TabsTvShow"
component={TabsTvShow}
options={{
tabBarLabel: 'TV Shows',
tabBarColor: '#58149C',
tabBarIcon: (({ color }) => (
<Icon color={color} size={25} name="desktop-outline" />
))
}}
/>
<Tab.Screen
name="TabTopRated"
component={TabTopRated}
options={{
tabBarLabel: 'Top Rated',
tabBarColor: '#135990',
tabBarIcon: (({ color }) => (
<Icon color={color} size={25} name="star-half-outline" />
))
}}
/>
<Tab.Screen
name="TabSearch"
component={TabSearch}
options={{
tabBarLabel: 'Search',
tabBarColor: '#A62349',
tabBarIcon: (({ color }) => (
<Icon color={color} size={25} name="search-outline" />
))
}}
/>
</Tab.Navigator>
One of stack navigators
<Stack.Navigator
initialRouteName='HomeScreen'
screenOptions={{
headerShown: false,
cardStyle: {
backgroundColor: 'white'
}
}}
>
<Stack.Screen name="HomeScreen" component={HomeScreen} />
<Stack.Screen name="MovieDetailScreen" component={MovieDetailScreen} />
</Stack.Navigator>
Another stack navigator
<Stack.Navigator
initialRouteName="TvShowsScreen"
screenOptions={{
headerShown: false,
cardStyle: {
backgroundColor: 'white'
}
}}
>
<Stack.Screen name="TvShowsScreen" component={TvShowsScreen} />
<Stack.Screen name="TvShowDetailScreen" component={TvShowDetailScreen} />
</Stack.Navigator>
I use the navigation hook to navigate between views, and i do not have any button to return. I hope to use the button return that each mobile has, and the nativation tab (material tab button) to return to the previous view
This is a shared component when I use the navigation
<TouchableOpacity
onPress={() => navigation.navigate('MovieDetailScreen', movie)}
activeOpacity={0.95}
style={{ width, height, ...moviePosterStyles.card }}>
<View style={moviePosterStyles.imageContainer}>
<Image
source={
(poster_path)
? { uri }
: require('../assets/images/no-movie.jpg')
}
style={moviePosterStyles.image}
/>
</View>
</TouchableOpacity>
Screen where I press return
<ScrollView>
<View style={detailStyles.imageContainer}>
<View style={detailStyles.imageBorder}>
<Image
source={{ uri }}
style={detailStyles.posterImage}
/>
</View>
</View>
<View style={detailStyles.titlesContainer}>
<Text style={detailStyles.subTitle}>{original_title}</Text>
<Text style={detailStyles.title}>{title}</Text>
</View>
<MovieDetails movieFull={movieFullDetails!} cast={cast} similarMovies={similarMovies!} />
</ScrollView>
Package.json
"dependencies": {
"#react-native-masked-view/masked-view": "^0.2.7",
"#react-navigation/material-bottom-tabs": "^6.2.3",
"#react-navigation/native": "^6.0.11",
"#react-navigation/stack": "^6.2.2",
"axios": "^0.27.2",
"intl": "^1.2.5",
"react": "18.0.0",
"react-native": "0.69.3",
"react-native-gesture-handler": "^2.5.0",
"react-native-image-colors": "^1.3.1",
"react-native-linear-gradient": "^2.6.2",
"react-native-paper": "^4.12.4",
"react-native-reanimated": "^2.9.1",
"react-native-reanimated-carousel": "^3.0.3",
"react-native-safe-area-context": "^4.3.1",
"react-native-screens": "^3.15.0",
"react-native-snap-carousel": "^1.3.1",
"react-native-splash-screen": "^3.3.0",
"react-native-vector-icons": "^9.2.0",
"react-native-webview": "^11.23.0",
"react-native-youtube-iframe": "^2.2.2"
},
There is no have a problem with the navigation.
I use a package: react-native-youtube-ifram to show YouTube videos, and the component was needs an additional attr
<YoutubePlayer
videoId={trailerYoutubeKey}
playList={trailersYoutubeList}
height={screenDimensions * 0.30}
webViewStyle={{ opacity: 0.99 }} // This attr
/>
Now, the navigation works correctly
When I try to swipe it open, it swings right back.
I'm using stack with drawer together maybe this might be a problem, but so far
I've tried everything, reviewed all the similar questions to this but nothing worked
my code:
const Drawer = createDrawerNavigator();
function DrawerNav({ navigation }) {
// toggleDrawer = () => {
// this.props.navigation.dispatch(DrawerActions.toggleDrawer())
// }
return (
<Drawer.Navigator initialRouteName="Home"
screenOptions={{
headerShown: true,
headerStyle: {
backgroundColor: brand,
},
headerTintColor: primary,
headerTransparent: false,
headerTitle: '',
headerLeftContainerStyle: {
paddingLeft: 20,
},
}}>
<Drawer.Screen name="Home" component={HomeScreen} options={horizontalAnimation}/>
</Drawer.Navigator>
);
}
const Stack = createStackNavigator();
const RootStack = () => {
return (
<CredentialsContext.Consumer>
{({ storedCredentials }) => (
<NavigationContainer>
<Stack.Navigator
screenOptions={{
headerStyle: {
backgroundColor: brand,
},
headerTintColor: primary,
headerTransparent: true,
headerTitle: '',
headerLeftContainerStyle: {
paddingLeft: 20,
},
}}
>
{storedCredentials ? (
<Stack.Screen name="Home" component={DrawerNav} options={horizontalAnimation}/>
) : (
<>
<Stack.Screen name="Login" component={Login} options={horizontalAnimation}/>
<Stack.Screen name="Signup" component={Signup} options={horizontalAnimation}/>
</>
)}
</Stack.Navigator>
</NavigationContainer>
)}
</CredentialsContext.Consumer>
);
};
Any help will be greatly appreciated, thanks in advance.
I had the same issue. I found out that some of my react-navigation libs where not on the same major release (in the package.json). So I changed them all to be on the same major version number, 6.X in my case, re-installed the packages and my code started working.
- "#react-navigation/bottom-tabs": "^6.0.1",
- "#react-navigation/native": "^5.9.4",
- "#react-navigation/stack": "^5.14.5",
+ "#react-navigation/drawer": "^6.1.4",
+ "#react-navigation/native": "^6.0.4",
+ "#react-navigation/stack": "^6.0.9",
Just change version of react-navigation/drawer if you have version 5
I want to add the line at the top of the bottom tabs, how to add this?
like this issue https://github.com/react-navigation/react-navigation/issues/8957
React navigation versions:
"#react-navigation/bottom-tabs": "^5.9.2",
"#react-navigation/native": "^5.7.6",
"#react-navigation/stack": "^5.9.3",
"react": "16.13.1",
"react-native": "0.63.3",
You can use a custom button like below
const CustomTabButton = (props) => (
<TouchableOpacity
{...props}
style={
props.accessibilityState.selected
? [props.style, { borderTopColor: 'red', borderTopWidth: 2 }]
: props.style
}
/>
);
And provide it as the tabBarButton when initializing the navigation.
<Tab.Navigator>
<Tab.Screen
name="Home"
component={HomeScreen}
options={{
tabBarButton: CustomTabButton,
}}
/>
<Tab.Screen
name="Settings"
component={SettingsScreen}
options={{
tabBarButton: CustomTabButton,
}}
/>
</Tab.Navigator>
You can try the below snack
https://snack.expo.io/6lMAe57lM
I have:
<PaperProvider theme={theme}>
<NavigationContainer>
<Tab.Navigator initialRouteName="Feed">
<Tab.Screen
name="Home"
component={Conversations}
options={{
tabBarLabel: "Home",
tabBarIcon: ({ color, size }) => (
<AntDesign name="home" size={size} color={color} />
),
}}
/>
<Tab.Screen
name="Explore"
component={Conversations}
options={{
tabBarLabel: "Explore",
tabBarIcon: ({ color, size }) => (
<AntDesign name="find" size={size} color={color} />
),
}}
/>
<Tab.Screen
name="Profile"
component={Conversations}
options={{
tabBarLabel: "Profile",
tabBarIcon: ({ color, size }) => (
<AntDesign name="setting" size={size} color={color} />
),
}}
/>
</Tab.Navigator>
</NavigationContainer>
</PaperProvider>;
And it loads fine, but I can't scroll. I'm also using react-native-web to attempt to make it web compatible.
It seems this is actually a problem with Expo, which I supose you are using to test your app. The problem is described in this Issue in the React Navigation repo:
https://github.com/react-navigation/react-navigation/issues/1797
Updating/Reinstalling Expo seems to fix your problem, if this is the case!
There is also an old fix for Expo's web integration that had this problem too, as described in this issue:
https://github.com/react-navigation/react-navigation/issues/6165
Theorically it is fixed, but if you are using an old version of React Navigation... Well, it seems you can fix this by setting the cardStyle property to {flex: 1}