Header icon navigation not working on react navigation (React Native) - react-native

My React Native application consists of a TabNavigator that is nested inside of a StackNavigator, which is the entry point of the app's routing.
In the StackNavigator I have also a screen for About, which I want to be shown when an Icon in the header is clicked. The TabNavigator works as expected, however clicking the icon does nothing and does not produce any error. Does anyone have an idea what I am missing?
This is the code:
import { Icon } from 'native-base';
import React, { Component } from 'react';
import { createTabNavigator, createStackNavigator } from 'react-navigation';
import { View } from 'react-native';
import HomeTab from './tabs/HomeTab';
import HistoryTab from './tabs/HistoryTab';
import AboutScreen from './AboutScreen';
export default class Main extends Component {
static navigationOptions = ({ navigation }) => {
return {
headerTitle: 'Find Phone Country',
headerStyle: {
backgroundColor: '#C62828'
},
headerMode: 'screen',
headerTintColor: '#FFFFFF',
headerTitleStyle: {
fontWeight: 'bold',
justifyContent: 'space-between',
alignSelf: 'center',
textAlign: 'center',
flex: 1,
flexGrow: 1
},
headerRight: (
<Icon
name="ios-help-circle-outline"
style={{ paddingRight: 16, color: 'white' }}
onPress={() => navigation.navigate('About')}
/>
),
headerLeft: <View />
};
};
render() {
return <RootStack />;
}
}
const MainTabNavigator = createTabNavigator(
{
Home: {
screen: HomeTab
},
History: {
screen: HistoryTab
}
},
{
animationEnabled: true,
swipeEnabled: true,
tabBarPosition: 'bottom',
tabBarOptions: {
showIcon: true,
showLabel: true,
upperCaseLabel: false,
allowFontScaling: true,
indicatorStyle: {
opacity: 0
},
style: {
backgroundColor: '#C62828'
},
activeTintColor: '#ffffff',
inactiveTintColor: '#e0e0e0'
}
}
);
const RootStack = createStackNavigator({
Main: {
screen: MainTabNavigator,
navigationOptions: () => ({
title: 'Main',
headerBackTitle: null,
header: null
})
},
About: {
screen: AboutScreen,
navigationOptions: () => ({
title: 'About',
headerBackTitle: 'Back'
})
}
});
Thank you

Icon from native-base doesn't have a prop named onPress. Try encapsulating your icon inside a proper component for capturing the touch, like:
headerRight: (
<TouchableWithoutFeedback onPress={() => navigation.navigate('About')}>
<Icon
name="ios-help-circle-outline"
style={{ paddingRight: 16, color: 'white' }}
/>
</TouchableWithoutFeedback>
),
and don't forget, on your imports:
import { View, TouchableWithoutFeedback } from 'react-native';

Related

React Native - How to set the drawer navigation content on the particular tab based on drawer item selection?

What i want to achieve is there are 2 tabs in my app
1) Home => On press it shows a simple screen
2) Menu => On press it opens and close drawer based on whether drawer is opened or not.
Drawer has custom content.
It has 4 buttons
1) Accounts
2) Reports
3) Graph
4) List
Selecting on any of the drawer item it should open a respective page in the "Menu" tab navigator space.
So how to manage this kind of navigation?
import React from 'react';
import { View, Text } from 'react-native'
import { createAppContainer, createSwitchNavigator } from 'react-navigation'
import { createStackNavigator } from 'react-navigation-stack'
import ShipmentScreen from '../containers/Shipment/ShipmentScreen';
import LoginScreen from '../containers/Login/LoginScreen';
import ShipmentDetailScreen from '../containers/Shipment/ShipmentDetailScreen';
import AuthLoadingScreen from '../containers/AuthLoadingScreen';
import BarcodeScreen from '../containers/Barcode/BarcodeScreen';
import { createBottomTabNavigator } from 'react-navigation-tabs'
import { createDrawerNavigator } from 'react-navigation-drawer';
import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons';
import Colors from "../utils/Colors";
import Sidebar from '../components/Sidebar';
class HomeScreen extends React.Component {
render() {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>Home Screen</Text>
</View>
);
}
}
class Data extends React.Component {
render() {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>Menu Screen</Text>
</View>
);
}
}
const defaultStackNavOptions = {
headerStyle: {
backgroundColor: Platform.OS === 'android' ? Colors.primaryColor : ''
},
headerTitleStyle: {
fontWeight: 'bold',
},
headerBackTitleStyle: {
fontWeight: 'bold',
},
headerTintColor: Platform.OS === 'android' ? Colors.lightColor : Colors.primaryColor,
headerTitle: 'SFL'
};
const TabNavigator = createBottomTabNavigator({
Home: {
screen: HomeScreen,
navigationOptions: {
tabBarLabel: 'Home',
tabBarIcon: ({ tintColor }) => (
<View>
<MaterialCommunityIcons style={{ color: tintColor }} size={25} name={'home'} />
</View>),
},
},
Menu: {
screen: sideDrawer,
navigationOptions: {
tabBarLabel: 'Menu',
tabBarIcon: ({ tintColor }) => (
<View>
<MaterialCommunityIcons style={{ color: tintColor, }} size={25} name={'menu'} />
</View>),
},
},
},
{
initialRouteName: "Home",
activeColor: Colors.activeTabColor,
inactiveColor: Colors.inactiveTabColor,
barStyle: {
backgroundColor: Colors.grayColor
},
tabBarOptions: {
style: {
borderTopColor: 'transparent',
shadowColor: Colors.darkColor,
shadowOpacity: 1,
shadowRadius: 30,
shadowOffset: {
height: 10,
width: 10
},
elevation: 5
},
labelStyle: {
fontSize: 12,
fontWeight: 'bold'
},
tabStyle: {
paddingVertical: 5
}
}
},
);
const sideDrawer = createDrawerNavigator(
{
ScreenA: { screen: Data },
ScreenB: { screen: Data },
ScreenC: { screen: Data }
},
{
drawerPosition: 'right',
contentComponent: Sidebar,
}
)
export default AppContainer = createAppContainer(TabNavigator)
How can i will be able to achieve this?
can anyone suggest a workaround solution?
Thanks.

How do I solve this: 'TypeError: undefined is not an object (evaluating '_this.props.navigationProps.toggleDrawer')'

A few days into React-Native, I am trying to implement a navigation drawer in my app.
However, I am not able to solve the error TypeError: undefined is not an object (evaluating '_this.props.navigationProps.toggleDrawer') when I tap the TouchableOpacity component that should trigger the drawer.
Following is the code I have used:
Header.js
import React, { Component } from 'react';
import { View, StyleSheet, Image, TouchableOpacity, Platform } from 'react-native';
import { createAppContainer } from 'react-navigation';
import { createDrawerNavigator } from 'react-navigation-drawer';
import { createStackNavigator } from 'react-navigation-stack';
import Screen1 from '../pages/screen1';
import Screen2 from '../pages/screen2';
import Screen3 from '../pages/screen3';
import logo from '../assets/logo.png';
import profileView from '../assets/profileIcon.png';
import menuDots from '../assets/3DotsMenu.png';
import { StatusBarHeight } from '../components/StatusBarHeight';
const statusBarHeight = StatusBarHeight
class Header extends Component {
toggleDrawer = () => {
this.props.navigationProps.toggleDrawer();
};
render() {
return (
<View>
<CreateDrawer />
<View style={styles.header} />
<View style={styles.headerContainer}>
<View style={styles.imageHolder}>
<TouchableOpacity
activeOpacity={0.6}
onPress={this.toggleDrawer.bind(this)}
>
<View>
<Image style={styles.menu} source={menuDots} />
</View>
</TouchableOpacity>
<TouchableOpacity activeOpacity={0.6}>
<View>
<Image style={styles.logo} source={logo} />
</View>
</TouchableOpacity>
<TouchableOpacity activeOpacity={0.6}>
<View>
<Image style={styles.profile} source={profileView} />
</View>
</TouchableOpacity>
</View>
</View>
</View>
);
};
}
const FirstActivity_StackNavigator = createStackNavigator({
First: {
screen: Screen1,
navigationOptions: ({ navigation }) => ({
title: 'Demo Screen 1',
headerLeft: () => <Header navigationProps={navigation} />,
headerStyle: {
backgroundColor: '#FF9800',
},
headerTintColor: '#fff',
}),
},
}
,
{
headerMode: "none"
}
);
const Screen2_StackNavigator = createStackNavigator({
Second: {
screen: Screen2,
navigationOptions: ({ navigation }) => ({
title: 'Demo Screen 2',
headerLeft: () => <Header navigationProps={navigation} />,
headerStyle: {
backgroundColor: '#FF9800',
},
headerTintColor: '#fff',
}),
},
},
{
headerMode: "none"
}
);
const Screen3_StackNavigator = createStackNavigator({
Third: {
screen: Screen3,
navigationOptions: ({ navigation }) => ({
title: 'Demo Screen 3',
headerLeft: () => <Header navigationProps={navigation} />,
headerStyle: {
backgroundColor: '#FF9800',
},
headerTintColor: '#fff',
}),
},
});
const DrawerNavigator = createDrawerNavigator({
Screen1: {
screen: FirstActivity_StackNavigator,
navigationOptions: {
drawerLabel: 'Demo Screen 1',
},
},
Screen2: {
screen: Screen2_StackNavigator,
navigationOptions: {
drawerLabel: 'Demo Screen 2',
},
},
Screen3: {
screen: Screen3_StackNavigator,
navigationOptions: {
drawerLabel: 'Demo Screen 3',
},
},
});
const styles = StyleSheet.create({
header: {
width: '100%',
height: statusBarHeight,
backgroundColor: '#E6E3E2',
flexDirection: 'row',
},
headerContainer: {
height: 60,
backgroundColor: '#E6E3E2',
justifyContent: 'center',
alignItems: 'center'
},
imageHolder: {
flexDirection: "row",
justifyContent: 'space-between',
width: '95%'
},
menu: {
marginTop: 15,
width: 27,
height: 19,
resizeMode: "stretch"
},
logo: {
width: 140,
height: Platform.OS === 'ios' ? 50 : 50,
},
profile: {
marginTop: 3,
height: 38,
width: 35
}
});
const CreateDrawer = createAppContainer(DrawerNavigator);
export default Header;
App.js
import React, { Component } from "react";
import { StyleSheet, Text, View } from "react-native";
import Header from './components/Header';
export default class App extends Component {
render() {
return (
<View style={{flex:1}} >
<View style={{backgroundColor: 'blue'}}>
<Header />
</View>
</View>
);
}
}
Use export default withNavigation(Header); while exporting for a stack of navigations.

React native BottomTabNavigator with DrawerNavigator, how to keep bottom navigator visible all the time

I have gone through various posts on SO and github about react navigation, but most of them are a combination of react native stack navigator with drawer navigator. I couldn't find anything that could help fix my problem.
What i am trying to do is i have a bottom tab bar with five screens which load nicely with correct data, i want to add a drawer navigator to provide more screens and have different data. I have managed to build the drawer navigator on top of the tab navigator but when the drawer is opened, it overlaps the bottom tab bar and hence bottom tab navigation is useless as long as the drawer is open. Also adding the tabs under the drawer navigator shows Tabs as one of the options in the drawer menu.
What i want to achieve is,
1. Have a bottom tab navigation visible all the time.
2. When the drawer is open the drawer menu opens and does not over lap the bottom tab bar.
3. And the drawer menu should have only those screens which can be navigated from the drawer menu.
Below is my navigation code,
import React from 'react'
// Navigators
import { DrawerNavigator, StackNavigator, createBottomTabNavigator } from 'react-navigation'
// TabNavigator screens
import ProfileConnector from '../connectors/ProfileConnector'
import InboxConnector from '../connectors/InboxConnector'
import AttendanceConnector from '../connectors/AttendanceConnector'
import Results from '../layouts/results/Results'
import TimetableConnector from '../connectors/TimetableConnector'
import Icon from 'react-native-vector-icons/Entypo'
import {Dimensions} from 'react-native'
const deviceW = Dimensions.get('window').width
const basePx = 375
function px2dp(px) {
return px * deviceW / basePx
}
import Gallery from '../layouts/gallery/Gallery'
export const Tabs = createBottomTabNavigator({
Profile: {
screen: ProfileConnector,
navigationOptions: {
tabBarLabel: 'Profile',
tabBarIcon: ({tintColor}) => <Icon name="user" size={px2dp(22)} color={tintColor}/>,
},
},
Inbox: {
screen: InboxConnector,
navigationOptions: {
tabBarLabel: 'Inbox',
tabBarIcon: ({tintColor}) => <Icon name="inbox" size={px2dp(22)} color={tintColor}/>,
},
},
Attendance: {
screen: AttendanceConnector,
navigationOptions: {
tabBarLabel: 'Attendance',
tabBarIcon: ({tintColor}) => <Icon name="hand" size={px2dp(22)} color={tintColor}/>,
},
},
Timetable: {
screen: TimetableConnector,
navigationOptions: {
tabBarLabel: 'Timetable',
tabBarIcon: ({tintColor}) => <Icon name="calendar" size={px2dp(22)} color={tintColor}/>,
},
},
Results: {
screen: Results,
navigationOptions: {
tabBarLabel: 'Results',
tabBarIcon: ({tintColor}) => <Icon name="bar-graph" size={px2dp(22)} color={tintColor}/>,
},
},
}, {
initialRouteName: 'Inbox',
tabBarPosition: 'bottom',
swipeEnabled: true,
tabBarOptions: {
activeTintColor: 'teal',
inactiveTintColor: '#424949',
activeBackgroundColor: "white",
inactiveTintColor: '#424949',
labelStyle: { fontSize: 14 },
style : { height : 50}
}
});
export const Drawer = DrawerNavigator({
Tabs: {screen: Tabs},
Gallery: { screen: Gallery },
},{
drawerWidth: 250,
drawerPosition: 'left',
drawerOpenRoute: 'DrawerOpen',
drawerCloseRoute: 'DrawerClose',
drawerToggleRoute: 'DrawerToggle',
})
Can anybody help me with this please?
Thanks,
Vikram
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* #format
* #flow`enter code here`
*/
import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View,Button} from 'react-native';
import Icon from 'react-native-vector-icons/Ionicons';
import {
createBottomTabNavigator,
createStackNavigator,
createAppContainer,
createDrawerNavigator,
createSwitchNavigator,
} from 'react-navigation';
import Icons from 'react-native-ionicons';
const instructions = Platform.select({
ios: 'Press Cmd+R to reload,\n' + 'Cmd+D or shake for dev menu',
android:
'Double tap R on your keyboard to reload,\n' +
'Shake or press menu button for dev menu',
});
class DetailsScreen extends React.Component {
render() {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>Details!</Text>
</View>
);
}
}
class HomeScreen extends React.Component {
render() {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
{/* other code from before here */}
<Button
title="Go to Details"
onPress={() => this.props.navigation.navigate('Details')}
/>
</View>
);
}
}
class SettingsScreen extends React.Component {
render() {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
{/* other code from before here */}
<Button
title="Go to Details"
onPress={() => this.props.navigation.navigate('Details')}
/>
</View>
);
}
}
class LoginScreen extends React.Component {
render() {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
{/* other code from before here */}
<Button
title="Login"
onPress={() => this.props.navigation.navigate('Home')}
/>
</View>
);
}
}
const HomeStack = createStackNavigator({
Home: {screen:HomeScreen,
navigationOptions: ({ navigation }) => ({
title: `Home`,
headerLeft: <Icon name='md-menu' size={30} onPress={()=>{navigation.openDrawer()}}/>,
headerStyle:{
textAlign:'center',
alignContent: 'center',
}
}),
},
Details:{screen: DetailsScreen,
navigationOptions: ({ navigation }) => ({
title: `Details`,
//headerLeft: <Icon name='md-menu' size={30}/>,
headerStyle:{
alignContent: 'center',
}
}),
},
},{
initialRouteName: 'Home',
}
);
const SettingsStack = createStackNavigator({
Settings:{screen: SettingsScreen,
navigationOptions: ({ navigation }) => ({
title: `Privacy`,
headerLeft: <Icon name='md-menu' size={30}/>,
headerStyle:{
alignContent: 'center',
}
}),
},
Details: {screen:DetailsScreen,
navigationOptions: ({ navigation }) => ({
title: `Privacy Details`,
//headerLeft: <Icon name='md-menu' size={30}/>,
headerStyle:{
alignContent: 'center',
}
}),
},
});
const bottomTabNavigator = createBottomTabNavigator(
{
Home: HomeStack,
Settings: SettingsStack,
}
)
// const bottomStack = createStackNavigator({
// bottomTabNavigator
// },{
// defaultNavigationOptions:({navigation})=>{
// return {
// headerLeft: <Icon name='md-menu' size={30} onPress={()=>{navigation.openDrawer()}}/>,
// title:navigation.state.routeName[navigation.state.index]
// }
// }
// })
const dashboardStack = createDrawerNavigator({
Dashboard: bottomTabNavigator,
},)
const authStack = createSwitchNavigator({
Login:LoginScreen,
Dashboard:dashboardStack
})
export default createAppContainer(authStack);
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
Well, i tried and it's close to what you want. Background of DrawerNavigator is transparent and in CustomDrawerContentComponent, height is assigned to a view to make bottom tab bar visible. Hope that works for you.
const CustomDrawerContentComponent = (props) => (
<View style={{height:500}} >
<ScrollView
horizontal
style={{ backgroundColor: 'blue'}}
><DrawerItems {...props} />
</ScrollView>
</View>
);
const Drawer = createDrawerNavigator({
Tabs: {screen: Tabs},
Gallery: { screen: Home },
},{
drawerBackgroundColor : 'transparent',
contentComponent: props => <CustomDrawerContentComponent {...props} />
}
)

showing navigation bottom bar in screens which are not part of bottom tabs in react native

I have three tabs and 8 screens in react native app. I have created bottom tab navigator as follows and I have 5 more screens which i dont want in tabs but on those screens the normal three tabs bottom bar navigator is required. Exact help is appreciated.
const TabNavigation = createBottomTabNavigator(
{
Scan: {
screen: ScanScreen,
navigationOptions: {
tabBarLabel: 'Scan',
tabBarIcon: () => <Ionicons name="ios-qr-scanner-outline" size={32} color="blue" />
,
},
},
Patient: {
screen: PatientStack,
navigationOptions: {
tabBarLabel: 'Patients',
tabBarIcon: () => <Ionicons name="ios-people" size={32} color="blue" />
,
},
},
Setting: {
screen: SettingScreen,
navigationOptions: {
tabBarLabel: 'Setting',
tabBarIcon: () => <Ionicons name="ios-settings" size={32} color="blue" />
,
},
},
},
{
lazyLoad: true,
animationEnabled: false,
tabBarPosition: 'bottom',
tabBarOptions: {
showIcon: true,
showLabel: true,
activeTintColor: '#7117ea',
inactiveTintColor: '#7117ea',
style: {
backgroundColor: '#eff0f1'
},
iconStyle: {
width: 40
},
tabStyle: {
height: 60
}
},
},
);
This is an Example code which will solve your problem (Hope so)
In this there are three scenes and in bottom bar two screens are rendered and the third scenes is rendered after clicking a link but the bottom bar will be there.
import React from 'react';
import { Button, Text, View } from 'react-native';
import { Ionicons } from '#expo/vector-icons';
import { createStackNavigator, createBottomTabNavigator } from 'react-navigation';
class HomeScreen extends React.Component {
render() {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>Home!</Text>
<Button
title="Go to Settings"
onPress={() => this.props.navigation.navigate('Settings')}
/>
<Button
title="Go to Details"
onPress={() => this.props.navigation.navigate('Details')}
/>
</View>
);
}
}
class SettingsScreen extends React.Component {
render() {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>Settings!</Text>
<Button
title="Go to Home"
onPress={() => this.props.navigation.navigate('Home')}
/>
<Button
title="Go to Details"
onPress={() => this.props.navigation.navigate('Details')}
/>
</View>
);
}
}
class DetailsScreen extends React.Component {
render() {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>Details!</Text>
</View>
);
}
}
const HomeStack = createStackNavigator({
Home: { screen: HomeScreen },
Details: { screen: DetailsScreen },
});
const SettingsStack = createStackNavigator({
Settings: { screen: SettingsScreen },
Details: { screen: DetailsScreen },
});
export default createBottomTabNavigator(
{
Home: { screen: HomeStack },
Settings: { screen: SettingsStack },
},
{
navigationOptions: ({ navigation }) => ({
tabBarIcon: ({ focused, tintColor }) => {
const { routeName } = navigation.state;
let iconName;
if (routeName === 'Home') {
iconName = `ios-information-circle${focused ? '' : '-outline'}`;
} else if (routeName === 'Settings') {
iconName = `ios-options${focused ? '' : '-outline'}`;
}
// You can return any component that you like here! We usually use an
// icon component from react-native-vector-icons
return <Ionicons name={iconName} size={25} color={tintColor} />;
},
}),
tabBarOptions: {
activeTintColor: 'red',
inactiveTintColor: 'gray',
},
}
);

React navigation How can I change the header navigation title dynamically for each tab?

I have created 3 screens which display as tabs on the createMaterialTopTabNavigator which is inside a stack navigator my issue is i dont know how to dynamically set Header title for each tab. currently setting the title to "welcome" applies to all the tabs. Any help please?
xxxxxx
xxxxxx
xxxxxx
xxxxxx
xxxxxx
import { LinearGradient } from 'expo';
import { Icon } from "native-base";
import React from 'react';
import { StyleSheet, View } from 'react-native';
import { createMaterialTopTabNavigator, DrawerActions } from 'react-navigation';
import Home from '../TabNavigator/Home';
import MyProfile from '../TabNavigator/MyProfile';
import SelectAirtime from '../TabNavigator/SelectAirtime';
export default class TabNavigator extends React.Component {
static navigationOptions = ({ navigation, }) => {
return {
title: "Welcome",
headerLeft: (
<View style={{ padding: 10, }}>
<Icon style={{ color: '#fff', fontSize: 24 }} name='menu' type="MaterialCommunityIcons"
onPress={() => navigation.dispatch(DrawerActions.openDrawer())} />
</View>
),
headerBackground: (
<LinearGradient
colors={['#2acc55', '#10356c']}
style={{ flex: 1 }}
start={[0, 0]}
end={[1, 0]}
/>
),
headerTitleStyle: { color: '#fff' },
}
}
render() {
return (
<HomeScreenTabNavigator></HomeScreenTabNavigator>
);
}
}
const HomeScreenTabNavigator = createMaterialTopTabNavigator({
Home: {
screen: Home, navigationOptions: {
tabBarIcon: ({ tintColor }) => (<Icon style={{ color: 'white', fontSize: 24 }} name='home' type="MaterialCommunityIcons" />),
}
},
"Buy AirTime": {
screen: SelectAirtime, navigationOptions: {
tabBarIcon: ({ tintColor }) => (<Icon style={{ color: 'white', fontSize: 24 }} name='cards-outline' type="MaterialCommunityIcons" />),
}
},
"Account": {
screen: MyProfile, navigationOptions: {
tabBarIcon: ({ tintColor }) => (<Icon style={{ color: 'white', fontSize: 24 }} name='user' type="EvilIcons" />),
}
},
},
{
initialRouteName: 'Home',
tabBarPosition: 'bottom',
tabBarOptions: {
activeTintColor: 'white',
inactiveTintColor: '#f2f2f2',
labelStyle: {
fontSize: 9,
},
tabStyle: {
height: 60,
},
style: {
backgroundColor: '#1e3c72',
borderBottomColor: '#1e3c72',
},
indicatorStyle: {
height: 0,
},
showIcon: true,
}
}
)
Define TabNavigator:
import { LinearGradient } from 'expo';
import { Icon } from "native-base";
import React from 'react';
import { StyleSheet, View } from 'react-native';
import { createMaterialTopTabNavigator, DrawerActions } from 'react-navigation';
import Home from '../TabNavigator/Home';
import MyProfile from '../TabNavigator/MyProfile';
import SelectAirtime from '../TabNavigator/SelectAirtime';
const HomeScreenTabNavigator = createMaterialTopTabNavigator({
Home: {
screen: Home,
navigationOptions: {
tabBarIcon: ({ tintColor, homeTitle }) => ( < Icon style = { { color: 'white', fontSize: 24 } } name = 'home'
type = "MaterialCommunityIcons" / > ),
tabBarLabel: homeTitle,
}
},
"Buy AirTime": {
screen: SelectAirtime,
navigationOptions: {
tabBarIcon: ({ tintColor, selectAirtimeTitle }) => ( < Icon style = { { color: 'white', fontSize: 24 } } name = 'cards-outline'
type = "MaterialCommunityIcons" / > ),
tabBarLabel: selectAirtimeTitle,
}
},
"Account": {
screen: MyProfile,
navigationOptions: {
tabBarIcon: ({ tintColor, myProfileTitle }) => ( < Icon style = { { color: 'white', fontSize: 24 } } name = 'user'
type = "EvilIcons" / > ),
tabBarLabel: myProfileTitle,
}
},
}, {
initialRouteName: 'Home',
tabBarPosition: 'bottom',
tabBarOptions: {
activeTintColor: 'white',
inactiveTintColor: '#f2f2f2',
labelStyle: {
fontSize: 9,
},
tabStyle: {
height: 60,
},
style: {
backgroundColor: '#1e3c72',
borderBottomColor: '#1e3c72',
},
indicatorStyle: {
height: 0,
},
showIcon: true,
}
})
export default HomeScreenTabNavigator;
use it:
<HomeScreenTabNavigator
screenProps={{
homeTitle: 'This home title',
selectAirtimeTitle: 'This airtime title',
myProfileTitle: 'This profile title',
}}
/>
I hope useful to you!