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'
}
},
});
Related
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!
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);
I'm currently new developing a project using React Native, and I have problem regarding creating a navigation which, I won't allow the navigation will insert on the BottomTabNavigator. I have module where when i press the Setting my screen will go to the ProfileScreen.
Question: How can I navigate screen that not include in the BottomTabNavigator?
Import File:
import React, {Component} from 'react';
import {Platform, StyleSheet, View, YellowBox, Dimensions, AppRegistry, Image, TouchableOpacity, AsyncStorage,} from 'react-native';
import axios from 'axios';
import {Container, Header, Title, Content, Footer, FooterTab, Button, Left, Right, Body, Icon, Text, Item, Input,Toast} from 'native-base';
import {
createSwitchNavigator,
createAppContainer,
createStackNavigator,
createDrawerNavigator,
createBottomTabNavigator
}
from 'react-navigation';
import Fa5Icons from 'react-native-vector-icons/FontAwesome5';
import Mat5Icons from 'react-native-vector-icons/MaterialCommunityIcons';
import MaterialIcons from 'react-native-vector-icons/MaterialIcons';
import AuthLoadingScreen from './Screens/AuthLoadingScreen';
import SignInScreen from './Screens/SignInScreen';
import DriverSettingScreen from './Screens/DriverSettingScreen';
import DriverHistoryScreen from './Screens/DriverHistoryScreen';
import DriverDashScreen from './Screens/DriverDashScreen';
import DriverNotificationScreen from './Screens/DriverNotificationScreen';
import DriverAssignOrderScreen from './Screens/DriverAssignOrderScreen';
import DriverProfileScreen from './Screens/DriverProfileScreen';
Navigation:
const AuthStackNavigator = createStackNavigator({
SignIn: SignInScreen,
});
let that = this;
const AppTabNavigator = createBottomTabNavigator({
DriverDashScreen: {
screen:DriverDashScreen,
navigationOptions: ({ navigation }) => ({
tabBarLabel:"Home",
tabBarIcon: ({ focused, tintColor }) => {
const { routeName } = navigation.state;
if (routeName === 'DriverDashScreen') {
return <Fa5Icons name='compass' size={22} color={tintColor} />
}
else
{
return <Fa5Icons name='compass' size={22} style={{color:'black'}}/>
}
},
tabBarOptions: {
activeTintColor: '#008E9B',
inactiveTintColor: 'grey',
showIcon: true,
labelStyle: {
fontWeight: 'bold',
},
},
})
},
DriverAssignOrderScreen: {
screen:DriverAssignOrderScreen,
navigationOptions: ({ navigation }) => ({
tabBarLabel:"Orders",
tabBarIcon: ({ focused, tintColor }) => {
const { routeName } = navigation.state;
if (routeName === 'DriverAssignOrderScreen') {
return <Mat5Icons name='food' size={27} color={tintColor} />
}
else
{
return <Mat5Icons name='food' size={27} style={{color:'black'}} />
}
},
tabStyle: { justifyContent: 'center', alignItems: 'center', paddingVertical: 5 },
tabBarOptions: {
activeTintColor: '#008E9B',
inactiveTintColor: 'grey',
showIcon: true,
labelStyle: {
fontWeight: 'bold',
},
},
})
},
DriverHistoryScreen: {
screen:DriverHistoryScreen,
navigationOptions: ({ navigation }) => ({
tabBarLabel:"History",
tabBarIcon: ({ focused, tintColor }) => {
const { routeName } = navigation.state;
if (routeName === 'DriverHistoryScreen') {
return <Fa5Icons name='history' size={19} color={tintColor} />
}
},
tabBarOptions: {
activeTintColor: '#008E9B',
inactiveTintColor: 'grey',
showIcon: true,
labelStyle: {
fontWeight: 'bold',
},
},
})
},
DriverNotificationScreen: {
screen:DriverNotificationScreen,
navigationOptions: ({ navigation }) => ({
tabBarLabel:"Notification",
tabBarIcon: ({ focused, tintColor }) => {
const { routeName } = navigation.state;
if (routeName === 'DriverNotificationScreen') {
return <MaterialIcons name='notifications-active' size={22} color={tintColor} />
}
},
tabBarOptions: {
activeTintColor: '#008E9B',
inactiveTintColor: 'grey',
showIcon: true,
labelStyle: {
fontWeight: 'bold',
},
},
})
},
DriverSettingScreen: {
screen:DriverSettingScreen,
navigationOptions: ({ navigation }) => ({
tabBarLabel:"Account",
tabBarIcon: ({ focused, tintColor }) => {
const { routeName } = navigation.state;
if (routeName === 'DriverSettingScreen') {
return <MaterialIcons name='account-circle' size={22} color={tintColor} />
}
else
{
return <MaterialIcons name='account-circle' size={22} style={{color:'black'}} />
}
},
tabBarOptions: {
activeTintColor: '#008E9B',
inactiveTintColor: 'grey',
showIcon: true,
labelStyle: {
fontWeight: 'bold',
},
},
})
},
})
const AppStackNavigator = createStackNavigator({
AppTabNavigator: {
screen:AppTabNavigator
}
},{
header: null,
headerMode: 'none'
});
const AppDrawerNavigator = createDrawerNavigator({
Home:AppStackNavigator,
})
export default createAppContainer(createSwitchNavigator({
AuthLoading: AuthLoadingScreen,
Auth:AuthStackNavigator,
App: AppDrawerNavigator,
},
{
initialRouteName: 'AuthLoading',
}
))
My Action Button:
<ListItem icon onPress={() => navigate('DriverProfileScreen')}>
<Left>
<Button style={{ backgroundColor: "#FF9501", width:25, height:25}}>
<Icon type="MaterialIcons" name="settings" style={{fontSize:16}}/>
</Button>
</Left>
<Body>
<Text style={{fontSize:14}}>Settings</Text>
</Body>
<Right>
<Icon name="arrow-forward" />
</Right>
</ListItem>
Import File:
import React, {Component} from 'react';
import {Platform, StyleSheet, View, YellowBox, Dimensions, AppRegistry,
Image, TouchableOpacity, AsyncStorage,} from 'react-native';
import axios from 'axios';
import {Container, Header, Title, Content, Footer, FooterTab, Button, Left, Right, Body, Icon, Text, Item, Input,Toast} from 'native-base';
import {
createSwitchNavigator,
createAppContainer,
createStackNavigator,
createDrawerNavigator,
}
from 'react-navigation';
import Fa5Icons from 'react-native-vector-icons/FontAwesome5';
import Mat5Icons from 'react-native-vector-icons/MaterialCommunityIcons';
import MaterialIcons from 'react-native-vector-icons/MaterialIcons';
import AuthLoadingScreen from './Screens/AuthLoadingScreen';
import SignInScreen from './Screens/SignInScreen';
import DriverSettingScreen from './Screens/DriverSettingScreen';
import DriverHistoryScreen from './Screens/DriverHistoryScreen';
import DriverDashScreen from './Screens/DriverDashScreen';
import DriverNotificationScreen from './Screens/DriverNotificationScreen';
import DriverAssignOrderScreen from './Screens/DriverAssignOrderScreen';
import DriverProfileScreen from './Screens/DriverProfileScreen';
Navigation:
const AuthStackNavigator = createStackNavigator({
SignIn: SignInScreen,
});
let that = this;
const stackNav = createStackNavigator({
DriverDashScreen: {
screen: DriverDashScreen,
navigationOptions: ({ navigation }) => ({
})
},
DriverAssignOrderScreen: {
screen: DriverAssignOrderScreen,
navigationOptions: ({ navigation }) => ({
})
},
DriverHistoryScreen: {
screen: DriverHistoryScreen,
navigationOptions: ({ navigation }) => ({
})
},
DriverNotificationScreen: {
screen: DriverNotificationScreen,
navigationOptions: ({ navigation }) => ({
})
},
DriverSettingScreen: {
screen: DriverSettingScreen,
navigationOptions: ({ navigation }) => ({
})
},
})
const AppDrawerNavigator = createDrawerNavigator({
Home:stackNav,
})
export default createAppContainer(createSwitchNavigator({
AuthLoading: AuthLoadingScreen,
Auth:AuthStackNavigator,
App: AppDrawerNavigator,
},
{
initialRouteName: 'AuthLoading',
}
))
My Action Button:
<ListItem icon onPress={() =>
this.props.navigation.navigate('DriverSettingScreen')}>
<Left>
<Button style={{ backgroundColor: "#FF9501", width:25, height:25}}>
<Icon type="MaterialIcons" name="settings" style={{fontSize:16}}/>
</Button>
</Left>
<Body>
<Text style={{fontSize:14}}>Settings</Text>
</Body>
<Right>
<Icon name="arrow-forward" />
</Right>
</ListItem>
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'}
});
I'm trying to navigate from tab page to other page. I'm following tabnavigator and stacknavigator.
myTabsHost(RegisterHostPage) Here I'm hosting two tabs
import React, { Component } from "react";
import {
AppRegistry,
Text,
View,
Image,
StyleSheet,
TouchableOpacity
} from "react-native";
import { TabNavigator } from "react-navigation";
import { Tab } from "../../config/router.js";
import {Tab2} from "../../config/router.js";
import { NavigationActions } from "react-navigation";
class RegisterHost extends Component {
render() {
return (
<View style={Styles.container}>
<Text style={Styles.boldLabel}> User Register</Text>
<Text style={Styles.normalLabel}>Wallet account registration</Text>
<TouchableOpacity
onPress={() => {
const navigateAction = NavigationActions.navigate({
key: null,
routeName: "preactivate",
params: {}
});
this.props.navigation.dispatch(navigateAction);
}}
>
<Text>topreactivate</Text>
</TouchableOpacity>
<Tab2 />
</View>
);
}
}
const Styles = StyleSheet.create({
container: {
flex: 1,
padding: 2,
justifyContent: "center",
backgroundColor: "#FFFFFF"
},
boldLabel: {
fontWeight: "bold",
fontSize: 24,
alignSelf: "center",
color: "#08AE9E",
marginBottom: 20,
marginTop: 10
},
normalLabel: {
fontWeight: "normal",
fontSize: 18,
alignSelf: "center",
color: "black",
marginBottom: 20,
marginTop: 10
}
});
export default RegisterHost;
myTabPage (BankCustomerRegister)
import React, { Component } from "react";
import {
Text,
View,
Image,
StyleSheet,
TextInput,
TouchableOpacity
} from "react-native";
import { TabNavigator } from "react-navigation";
import{StackNavigator} from 'react-navigation';
import FetchData from "../../utils/fetch.js";
class BankCustomerRegister extends Component {
constructor(props) {
super(props);
this.state = {
stCustId: "",
stIdcard: "",
stPhoneNum: "",
isMounted: false
};
}
}
};
render() {
const { navigate } = this.props.navigation;
return (
<View style={styles.container}>
<Image source={require("../../resources/icons/bank.png")} />
<TextInput
style={styles.textInput}
onChangeText={this._handleCustId}
placeholderTextColor="black"
placeholder="Customer ID"
/>
<TextInput
style={styles.textInput}
placeholderTextColor="black"
onChangeText={this._handleIdCard}
placeholder="ID card"
/>
<TextInput
style={styles.textInput}
placeholderTextColor="black"
onChangeText={this._handlePhoneNum}
placeholder="Phone No"
/>
<TouchableOpacity
onPress={() => {
// NOTICE HERE
const navigateAction = NavigationActions.navigate({
routeName: "preactivate",
params: {},
});
this.props.navigation.dispatch(navigateAction);
}}
style={styles.touchable}
>
<Text style={styles.btnlabel}>Register</Text>
</TouchableOpacity>
</View>
);
}
}
export default BankCustomerRegister;
when i click touchable.its supposed to navigate to otherPage, i'ts not navigating anywhere , even no errors.
myOtherPage(preactivate)
import React, { Component } from "react";
import {
View,
Text,
StyleSheet
} from "react-native";
class PreUserActivation extends Component {
// Render callBack
render() {
return (
<View style={styles.container}>
<Text>Screen</Text>
</View>
);
}
}
export default PreUserActivation;
My router config in router.js
//tab Router
export const Tab = TabNavigator(
{
BankCustomerRegister: {
screen: BankCustomerRegister,
navigationOptions: {
tabBarLabel: "Bank Customer"
}
},
nonbankcustomer: {
screen: NonCustomerRegister,
navigationOptions: {
tabBarLabel: "New Customer"
}
}
},
{
tabBarPosition: "top",
animationEnabled: true,
tabBarOptions: {
// activeTintColor: "#e91e63",
labelStyle: {
fontSize: 16
},
style: {
backgroundColor: "#08AE9E"
},
tabStyle: { width: 200 } //Set width to make INLINE TABS
}
}
);
export const Root = StackNavigator({
board: {
screen: OnBoardScreen,
navigationOptions: {
header: null
}
},
preactivate: {
screen: PreUserActivation,
navigationOptions: {
header: null
}
},
Tabs: {
screen: Tab
}
});
Is there something i'm missing.
You need a reset. Use navigate() when navigating from one tab to another in the same TabNavigator for example. In your case, you are navigating to a screen in the parent navigator. Try this instead:
onPress={() => {
const navigateAction = NavigationActions.reset({
index: 0,
actions: [
NavigationActions.navigate({ routeName: 'preactivate'})
]
});
this.props.navigation.dispatch(navigateAction);
}}