MaterialBottomTabNavigator / React-Native / React Navigation - reactjs

im using the Material-Bottom-Tab-Navigatior and would like to get a transparent bar background however my result atm looks like this
This is the code
import React from 'react';
import { createMaterialBottomTabNavigator } from 'react-navigation-material-bottom-tabs';
import Icon from 'react-native-vector-icons/Feather';
import HomePage from '../components/whatsOn/HomePage';
import ComingSoon from '../components/comingSoon/ComingSoon';
import Favourites from '../components/favourites/Favourites';
import config from '../static/config.json';
import texts from '../static/texts.json';
const { gradient } = config.colors;
const { ComingSoonTitle, HomeTitle, FavouritesTitle } = texts.Tabs;
const lang = config.language;
export const TabStack = createMaterialBottomTabNavigator({
comingSoon: {
screen: ComingSoon,
activeTintColor: gradient.primary,
navigationOptions: {
tabBarColor: 'transparent',
tabBarLabel: ComingSoonTitle[lang],
tabBarIcon: ({ tintColor }) => (<Icon name="calendar" color={tintColor} size={24} />),
},
},
whatsOn: {
screen: HomePage,
activeTintColor: gradient.primary,
navigationOptions: {
tabBarColor: 'transparent',
tabBarLabel: HomeTitle[lang],
tabBarIcon: ({ tintColor }) => (<Icon name="film" color={tintColor} size={24} />),
},
},
favourites: {
screen: Favourites,
activeTintColor: gradient.primary,
navigationOptions: {
tabBarColor: 'transparent',
tabBarLabel: FavouritesTitle[lang],
tabBarIcon: ({ tintColor }) => (<Icon name="star" color={tintColor} size={24} />),
},
},
}, {
shifting: true,
initialRouteName: 'whatsOn',
order: ['comingSoon', 'whatsOn', 'favourites'],
tabBarPosition: 'bottom',
});
this TabStack is nested inside this stack:
export const HomeStack = createStackNavigator({
Tabs: {
screen: TabStack,
navigationOptions: {
title: 'Compeso',
header: props => <CustomHeader {...props} />,
headerStyle: {
backgroundColor: 'transparent',
},
headerTitleStyle: {
fontSize: 24,
fontWeight: '500',
color: colors.typography,
},
headerRight: MenuIcon,
headerLeft: SearchIcon,
animationEnabled: true,
},
},
Drawer: {
screen: MoreInfromation,
},
}, {
initialRouteName: 'Tabs',
cardStyle: { backgroundColor: 'transparent' },
});
the HomeStack is nested in a switchNavigator
export default class Router extends Component {
render() {
return (
<MainStack />
);
}
}
const MainStack = createSwitchNavigator({
Auth: LoginStack,
Home: HomeStack,
},
{
initialRouteName: 'Home',
});
This MainStack is getting rendered in my App.js
I put this tab navigator into a stack navigator and each component that gets displayed shows a scroll view with a height of 815 pixels to make sure the background is behind the bar.
Can someone advice ?
Thanks in advance

You need to include barStyle.
So, for transparent the style will be something like this:
barStyle: {backgroundColor:'transparent'}
In your code it will look something like this(included at bottom).
export const TabStack = createMaterialBottomTabNavigator({
comingSoon: {
...
},
...
}, {
shifting: true,
initialRouteName: 'whatsOn',
order: ['comingSoon', 'whatsOn', 'favourites'],
tabBarPosition: 'bottom',
barStyle: {backgroundColor:'transparent'}
});

Related

Error: Element type is invalid React Native

When I launch my app on android I get that error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
Here is my Navigation.js
import React from 'react'
import { createStackNavigator } from 'react-navigation-stack'
import { Dimensions } from 'react-native'
import {createAppContainer, } from 'react-navigation';
import { createBottomTabNavigator } from 'react-navigation-tabs'
import Home from '../screens/Home'
import AddCollege from '../screens/AddCollege'
import ViewCollege from '../screens/ViewCollege'
import ViewSchool from '../screens/ViewSchool'
import AddSchool from '../screens/AddSchool'
import Profile from '../screens/Profile'
import Dashboard from '../screens/Dashboard'
import Settings from '../screens/Settings'
import ManageProfile from '../screens/ManageProfile'
import { Ionicons } from "react-native-vector-icons";
const HEIGHT = Dimensions.get('window').height
const WIDTH = Dimensions.get('window').width
const HomeStack = createStackNavigator(
{
Home: Home,
AddCollege: AddCollege,
ViewCollege: ViewCollege,
ViewSchool: ViewSchool,
AddSchool: AddSchool,
ManageProfile: ManageProfile
},
{
defaultNavigationOptions: {
headerStyle: {
backgroundColor: 'black',
height: HEIGHT / 9
},
headerTintColor: '#fff',
},
}
);
const ProfileStack = createStackNavigator(
{
Profile: Profile,
},
{
defaultNavigationOptions: {
headerTitleStyle: {
textAlign: 'center',
},
headerStyle: {
backgroundColor: 'black',
height: HEIGHT / 9
//marginTop: 24 ,
},
headerTintColor: '#fff',
title: 'Profile',
},
}
);
const DashboardStack = createStackNavigator(
{
Dashboard: Dashboard,
},
{
defaultNavigationOptions: {
title: 'Dashboard',
headerStyle: {
backgroundColor: 'black',
height: HEIGHT / 9
},
headerTintColor: '#fff',
},
}
);
const SettingsStack = createStackNavigator(
{
Settings: Settings,
},
{
defaultNavigationOptions: {
title: 'Settings ',
headerStyle: {
backgroundColor: 'black',
height:HEIGHT / 9
},
headerTitleStyle: {
color: '#fff',
},
},
},
);
const MainApp = createBottomTabNavigator({
Home: {
screen: HomeStack ,
navigationOptions: {
tabBarLabel: 'Home',
tabBarIcon: ({ tintColor }) => (
<Ionicons name="md-home" color={tintColor} size={30} />
)
}
},
Profile: {
screen: ProfileStack,
navigationOptions: {
tabBarLabel: 'Profile',
tabBarIcon: ({ tintColor }) => (
<Ionicons name="md-user" color={tintColor} size={30} />
)
}
},
Dashboard: {
screen: DashboardStack,
navigationOptions: {
tabBarLabel: 'Dashboard',
tabBarIcon: ({ tintColor }) => (
<Ionicons name="md-clipboard" color={tintColor} size={30} />
)
}
} ,
Settings: {
screen : SettingsStack ,
navigationOptions: {
tabBarLabel: 'Settings',
tabBarIcon: ({ tintColor }) => (
<Ionicons name="md-settings" color={tintColor} size={30} />
)
}
}
},
{
tabBarOptions: {
labelStyle: {
fontSize: 12,
padding: 0,
margin: 0
},
activeTintColor: 'red',
inactiveTintColor: 'white',
style:{height: HEIGHT / 10, backgroundColor: 'black' },
showIcon: true,
padding: 0,
margin: 0
}
});
export default createAppContainer(MainApp);
It's because of the wrong import from react-native-vector-icons
You should do it in this way
import Ionicons from "react-native-vector-icons/Ionicons";
or for other fonts
import FontAwesome from 'react-native-vector-icons/FontAwesome';
import FontAwesome5 from 'react-native-vector-icons/FontAwesome5';
Also check your other components (like your screens) that are exported as default!

how to add another screen on navigator

I'm using a tab bottom navigator in my project. I want to show a new page in a tab of the tab bottom navigator but I want the tab navigator to appear again at the bottom. I don't want to add the button of the new page I want to show below. How do I manage this situation.I created the new scene as another js file and added it to the app js. I mean. I have a button to redirect to a new page in the Home tab, but how do I navigate
my navigator codes in app.js:
import LoadingScreen from './screens/LoadingScreen'
import HomeScreen from './screens/HomeScreen'
import LoginScreen from './screens/LoginScreen'
import RegisterScreen from './screens/RegisterScreen'
import ProfileScreen from './screens/profileScreen'
import NotificationScreen from './screens/notificationScreen'
import PostScreen from './screens/postScreen'
import soruOnaylaScreen from './screens/soruOnaylaScreen'
const AppContainer = createStackNavigator(
{
default: createBottomTabNavigator(
{
soruOnayla: {
screen: soruOnaylaScreen,
navigationOptions: {
tabBarIcon: ({ tintColor }) =>
<Ionicons name="ios-chatboxes" size={24} color={tintColor} />
}
},
Home: {
screen: HomeScreen,
navigationOptions: {
tabBarIcon: ({ tintColor }) =>
<Ionicons name="ios-home" size={24} color={tintColor} />
}
},
Post: {
screen: PostScreen,
navigationOptions: {
tabBarIcon: ({ tintColor }) =>
<Ionicons
name="ios-add-circle"
size={36}
color='#E9446A'
style={{
shadowColor: "#E9446A",
shadowOffset: { width: 0, height: 0 },
shadowRadius: 10,
shadowOpacity: 0.3
}}
/>
}
}
, Notification: {
screen: NotificationScreen,
navigationOptions: {
tabBarIcon: ({ tintColor }) =>
<Ionicons name="ios-notifications" size={24} color={tintColor} />
}
},
Profile: {
screen: ProfileScreen,
navigationOptions: {
tabBarIcon: ({ tintColor }) =>
<Ionicons name="ios-person" size={24} color={tintColor} />
}
}
},
{
tabBarOptions: {
activeTintColor: "#161f3d",
inactiveTintColor: "#b8bbc4",
}
}
),
postModal: {
screen: PostScreen
}
},
{
mode: "modal",
headerMode: "none"
}
)
const AuthStack = createStackNavigator({
Login: LoginScreen,
Register: RegisterScreen
})
export default createAppContainer(
createSwitchNavigator(
{
Loading: LoadingScreen,
App: AppContainer,
Auth: AuthStack
},
{
initialRouteName: "Loading"
}
)
)

React Native Navigation GoBack isn't working

im using react navigation 3 and also using
this.props.navigation.navigate(item.navigationPath)
to navigate through pages
the problem is when i click the button in navbar to go back it doesn't go back
i want it to go back 1 step but it do nothing
here is the back component
class NavigationBack extends Component {
toggleDrawer = () => {
this.props.navigation.goBack()
};
render() {
return (
<View style={{ flexDirection: 'row' }}>
<TouchableOpacity onPress={this.toggleDrawer.bind(this)}>
<Image
source={require('./image/drawer.png')}
style={{ width: 25, height: 25, marginLeft: 5 }}
/>
</TouchableOpacity>
</View>
);
}
}
Also when im in the Home->Category->Single-Category
and i press the hardware back button it take me to Home instead of Category
here is a link to snack
https://snack.expo.io/#ov3rcontrol/navi
I tried your code and made some modification. can you check this code ? is this what you need ?
/*Example of Navigation Drawer with Sectioned Menu*/
import React, { Component } from 'react';
import {
StyleSheet,
Platform,
View,
Text,
Image,
TouchableOpacity,
YellowBox,
Dimensions,
Button,
} from 'react-native';
//Import required react-navigation component
import {
createDrawerNavigator,
createStackNavigator,
createAppContainer,
} from 'react-navigation';
//Import all the screens
import Screen1 from './pages/Screen1';
import Screen2 from './pages/Screen2';
import Screen3 from './pages/Screen3';
import category from './pages/category';
import singleCategory from './pages/singleCategory';
//Import custom Drawer / sidebar
import SideMenu from './sidemenu';
//Navigation Drawer Structure for all screen
class NavigationDrawerStructure extends Component {
toggleDrawer = () => {
this.props.navigationProps.toggleDrawer();
};
render() {
return (
<View style={{ flexDirection: 'row' }}>
<TouchableOpacity onPress={this.toggleDrawer.bind(this)}>
{/*Donute Button Image */}
<Image
source={require('./image/drawer.png')}
style={{ width: 25, height: 25, marginLeft: 5 }}
/>
</TouchableOpacity>
</View>
);
}
}
class NavigationBack extends Component {
toggleDrawer = () => {
this.props.navigation.goBack()
};
render() {
return (
<View style={{ flexDirection: 'row' }}>
<TouchableOpacity onPress={this.toggleDrawer.bind(this)}>
<Image
source={require('./image/drawer.png')}
style={{ width: 25, height: 25, marginLeft: 5 }}
/>
</TouchableOpacity>
</View>
);
}
}
//Stack Navigator for the First Option of Navigation Drawer
const FirstActivity_StackNavigator = createStackNavigator({
//All the screen from the First Option will be indexed here
First: {
screen: Screen1,
navigationOptions: ({ navigation }) => ({
title: 'Demo Screen 1',
headerLeft: <NavigationDrawerStructure navigationProps={navigation} />,
headerStyle: {
backgroundColor: '#FF9800',
},
headerTintColor: '#fff',
}),
},
});
//Stack Navigator for the Second Option of Navigation Drawer
const Screen2_StackNavigator = createStackNavigator({
//All the screen from the Second Option will be indexed here
Second: {
screen: Screen2,
navigationOptions: ({ navigation }) => ({
title: 'Demo Screen 2',
headerLeft: <NavigationDrawerStructure navigationProps={navigation} />,
headerStyle: {
backgroundColor: '#FF9800',
},
headerTintColor: '#fff',
}),
},
});
//Stack Navigator for the Third Option of Navigation Drawer
const Screen3_StackNavigator = createStackNavigator({
//All the screen from the Third Option will be indexed here
Third: {
screen: Screen3,
navigationOptions: ({ navigation }) => ({
title: 'Demo Screen 3',
headerLeft: <NavigationDrawerStructure navigationProps={navigation} />,
headerStyle: {
backgroundColor: '#FF9800',
},
headerTintColor: '#fff',
}),
},
});
const category_nav = createStackNavigator({
//All the screen from the Third Option will be indexed here
cat: {
screen: category,
navigationOptions: ({ navigation }) => ({
title: 'Makeup Artist',
headerLeft: <NavigationBack navigationProps={navigation} />,
headerStyle: {
backgroundColor: 'grey',
},
headerTintColor: '#fff',
}),
},
});
const single_category_nav = createStackNavigator({
//All the screen from the Third Option will be indexed here
single_cat: {
screen: singleCategory,
navigationOptions: ({ navigation }) => ({
title: 'Mahmoud Makup',
headerLeft: <NavigationBack navigationProps={navigation} />,
headerStyle: {
backgroundColor: 'grey',
},
headerTintColor: '#fff',
}),
},
});
//Drawer Navigator for the Navigation Drawer / Sidebar
const Drawers = createStackNavigator({
NavScreen1: { screen: FirstActivity_StackNavigator },
NavScreen2: { screen: Screen2_StackNavigator },
NavScreen3: { screen: Screen3_StackNavigator },
category: {screen: category_nav},
single_category: {screen: single_category_nav}
},{
headerMode: 'none'
})
const DrawerStack = createDrawerNavigator(
{
drawerScreens: Drawers
},
{
contentComponent: (props) => (
<SideMenu {...props}/>
),
drawerWidth: Dimensions.get('window').width - 120,
}
);
const RootStack = createStackNavigator({
root: DrawerStack
},{
headerMode: "none"
});
export default createAppContainer(RootStack);

Custom tabs Styling on React Navigation

I'm developing an app using React-Native (Expo) with React-Navigation module. I'm struggling to get what I want for "createBottomTabBar" styling and working on a custom tab bar component.
Where can I learn/find examples similar to this? Is my code correct?
I am using this: Border bottom on Bottom Navigation in React Native and this video: https://www.youtube.com/watch?v=w24FE9PZpzk
But I don't know how to get any further.
Router/index.js
import { createSwitchNavigator,createStackNavigator, createBottomTabNavigator, createDrawerNavigator, createAppContainer } from 'react-navigation';
import { Home, SignUpScreen, LoginScreen, ForgotPasswordScreen, Setting, AboutScreen, ScanFlight, FlightDetails, ChatList, ChatMessages, FriendList, exploreProfile, myProfile, FlightAdd, Notifications,Achievements } from '../Screens';
// Tab bar Custom Component
import appBottomTabs from '../NavigationLayout/bottomTabBar'
// Bottom Tab navigation
const MainTabNavigator = createBottomTabNavigator({
Home,
ChatList,
ScanFlight
}, {
tabBarOptions: {
activeTintColor: "#6200EE",
inactiveTintColor: "#858585",
style: {
paddingVertical: 10,
backgroundColor: "#fff",
border: '#ffffff'
},
labelStyle: {
fontSize: 14,
lineHeight: 16,
fontFamily: "Rubik_Regular"
},
tabBarPosition: "bottom",
tabBarComponent: appBottomTabs,
animationEnabled: true,
swipeEnabled: true,
unmountInactiveRoutes: true
}
});
// Drawer Navigation
const appDrawerNavigator = createDrawerNavigator({
Home: {screen: MainTabNavigator},
Login: LoginScreen,
SignUp: SignUpScreen,
ForgotPassword: ForgotPasswordScreen,
Settings: Setting,
About: AboutScreen,
FlightDetails: FlightDetails,
FlightAdd: FlightAdd,
}, {
unmountInactiveRoutes: true
});
const AppLoginNavigator = createSwitchNavigator({
LoginScreen,
ForgotPasswordScreen,
appDrawerNavigator: {
screen: appDrawerNavigator
},
appStackNavigator: {
screen: appStackNavigator
}
});
const AppContainer = createAppContainer(AppLoginNavigator);
class App extends Component {
render() {
return (
<AppContainer />
);
}
}
export default App;
NavigationLayout/bottomTabBar.js
import React, {Component} from 'react'
import {View, TouchableWithoutFeedback, Text, StyleSheet} from 'react-native'
class appBottomTabs extends Component {
constructor(){
super()
this.state = {
routeNameSelected:'Home'
}
}
onPressTab(routeName){
this.props.jumpTo(routeName)
this.setState({
routeNameSelected:routeName
})
}
render() {
const {navigation} = this.props;
const {routes} = navigation.state;
return (
<View style={styles.tabbar}>
{routes && routes.map((route, index) => {
return (
<TouchableWithoutFeedback
key={route.key}
style={styles.tab}
onPress={() => this.onPressTab(route.routeName)}
>
</TouchableWithoutFeedback>
);
})}
</View>
)
}
}
export default appBottomTabs;
This is the layout I'm aiming to achieve: https://postimg.cc/Mfc5HxPs
with the active link having bigger font size and a border bottom.
So you need to use defaultNavigationOptions in createBottomTabNavigator.
defaultNavigationOptions takes in a function/react component where you can return you component.
For example
const renderNav = (routeName, name, tintColor, focused) => (
<View style={{flex: 1, alignItems: 'center', borderBottomColor: focused ? tintColor: '', borderBottomWidth: focused ? 4 : 0}}>
<Icon name={name} color={tintColor} size={12} style={{paddingBottom: 4, paddingTop: 10}} />
<Text style={{paddingBottom: 8}}>{routeName}</Text>
</View>
)
const customTabs = ({ navigation }) => ({
tabBarIcon: ({ focused, horizontal, tintColor }) => {
const { routeName } = navigation.state;
if (routeName === 'Profile') {
return renderNav(routeName, 'user', tintColor, focused);
} else if (routeName === 'Home') {
return renderNav(routeName, 'home', tintColor, focused);
} else if (routeName === 'History') {
return renderNav(routeName, 'history', tintColor, focused);
} else if (routeName === 'Cart') {
return renderNav(routeName, 'shopping-cart', tintColor, focused);
}
}
});
const DashboardTabNav = createBottomTabNavigator({
Profile: {
screen: ProfileScreen
},
Home: Dashboard,
History: SettingsScreen,
Cart: CartScreen
},
{
defaultNavigationOptions: customTabs,
animationEnabled: true,
swipeEnabled: true,
tabBarPosition: 'bottom',
initialRouteName: 'Cart',
tabBarOptions: {
activeTintColor: '#6C1D7C',
inactiveTintColor: 'rgba(0,0,0,0.6)',
showLabel: false,
style:{
shadowColor: 'rgba(58,55,55,0.1)',
shadowOffset: { width: 0, height: 0 },
shadowOpacity: 1,
shadowRadius: 15,
elevation: 3,
borderTopColor: 'transparent',
backgroundColor:'#fff',
borderTopLeftRadius: 20,
borderTopRightRadius: 20,
height: 50
},
activeTabStyle: {
backgroundColor: 'white',
borderBottomWidth: 4,
borderColor: '#6C1D7C'
}
},
});

Create header for DrawerNavigator

I want to create a drawer. For each screen accessed through the drawer I want to show the same header I am actually customizing on WelcomeContainer AppNavigator. The drawer should overlap the header. The problem is that the header appear only on the home screen: If I click on the the category menu, the drawer disappear. I even tried to copy the header code and past it in the category screen and nothing appeared. This is my code
const AppNavigator = StackNavigator({
Home: {
screen: WelcomeContainer,
navigationOptions: ({navigation}) => ({
headerLeft:
<Icon name="menu" color='#5c72b0' size={35} style={{ flexDirection: 'row', justifyContent: 'space-between', alignItems:'center',
paddingLeft:10 }} onPress={ () => navigation.navigate('DrawerOpen') } />,
headerRight:
<Icon name="settings" color='#5c72b0' size={25} style={{ alignItems:'center', paddingRight:10 }}
onPress={ () => navigation.navigate('Settings', {title: I18n.t('settings.title') }) } /> })
},
Settings: {
screen: SettingsContainer,
navigationOptions: ({navigation}) => ({
title: navigation.state.params.title
})
},
About: {
screen: About,
navigationOptions: ({navigation}) => ({
title: navigation.state.params.title
})
}
})
const AppDrawer = DrawerNavigator(
{
Home: {
path: '/',
screen: AppNavigator,
},
Category: {
path: '/sent',
screen: CategoryContainer,
},
},
{
initialRouteName: 'Home',
contentOptions: {
activeTintColor: '#e91e63',
},
}
);
Could you please help me solve the problem?

Resources