React Drawer Navigation menu icon is not showing - react-native

Please note that this is my route configuration with the "Stack, Drawer and Tab Navigation"
Stack and the tab navigation is working fine. But the drawer icon is not showing at all and the drawer is working only If I slide the window manually. How to show the drawer icon and use it to open the drawer window? Please help me to sort this out.
import React from "react"
import { createAppContainer } from 'react-navigation'
import { createStackNavigator } from 'react-navigation-stack'
import { createBottomTabNavigator } from 'react-navigation-tabs'
import { createDrawerNavigator } from 'react-navigation-drawer'
import Icon from 'react-native-vector-icons/Feather'
import HomeScreen from './screens/home/HomeScreen'
import ControlScreen from './screens/controls/ControlScreen'
import MoreScreen from './screens/more/MoreScreen'
import SignUpScreen from './screens/signup/SignUpScreen'
import AboutScreen from './screens/about/AboutScreen'
const TabContainer = createBottomTabNavigator({
Home: {
screen: HomeScreen,
navigationOptions: {
tabBarIcon: ({ tintColor, focused }) => <Icon name="home" size={20} color={`${focused ? tintColor : '#404040'}`} />,
}
},
Controls: {
screen: ControlScreen,
navigationOptions: {
tabBarIcon: ({ tintColor, focused }) => <Icon name="sliders" size={20} color={`${focused ? tintColor : '#404040'}`} />
}
},
More: {
screen: MoreScreen,
navigationOptions: {
tabBarIcon: ({ tintColor, focused }) => <Icon name="more-horizontal" size={20} color={`${focused ? tintColor : '#404040'}`} />
}
},
},{
tabBarposition: 'bottom',
swipeEnabled: false,
tabBarOptions: {
activeTintColor: '#069',
inactiveTintColor: '#404040',
labelStyle: {
fontSize: 14,
paddingTop: 0,
paddingBottom: 0
},
style:{
borderTopWidth: 1,
borderTopColor:'#333333',
position: 'absolute',
bottom: 0,
left: 0
},
animationEnabled: false,
tabStyle: {
paddingBottom: 15,
paddingTop: 0,
height: 75,
marginBottom: 0,
},
}
}
)
const StackContainer = createStackNavigator({
TabContainer,
},{
defaultNavigationOptions: {
headerShown: false
}
})
const MainDrawerNavigator = createDrawerNavigator({
Home: {
screen: StackContainer,
headerStyle: {
backgroundColor: '#f4511e',
},
headerTintColor: '#fff',
headerTitleStyle: {
fontWeight: 'bold',
},
title: 'Home',
navigationOptions: {
drawerIcon: ({ tintColor }) => (
<Icon name="home" size={20} color={'#404040'} />
),
}
},
SignUp: {
screen: SignUpScreen,
navigationOptions: {
drawerIcon: ({ tintColor }) => (
<Icon name="user" size={20} color={'#404040'} />
),
}
},
About: {
screen: AboutScreen,
navigationOptions: {
drawerIcon: ({ tintColor }) => (
<Icon name="alert-circle" size={20} color={'#404040'} />
),
}
},
},
{
drawerOpenRoute: 'DrawerOpen',
drawerCloseRoute: 'DrawerClose',
drawerToggleRoute: 'DrawerToggle',
navigationOptions: {
drawerLockMode: 'locked-closed',
},
drawerPosition: 'left',
headerStyle: { backgroundColor: '#E73536' },
headerTintColor: 'white',
drawerOpenRoute: 'DrawerOpen',
drawerCloseRoute: 'DrawerClose',
drawerToggleRoute: 'DrawerToggle',
},
)
export default createAppContainer(MainDrawerNavigator)

You need to include your drawerNavigator inside stackNavigator and you can provide the default navigation options there.
I had edited your code check this:
import React from "react"
import { createAppContainer } from 'react-navigation'
import { createStackNavigator } from 'react-navigation-stack'
import { createBottomTabNavigator } from 'react-navigation-tabs'
import { createDrawerNavigator } from 'react-navigation-drawer';
import Icon from 'react-native-vector-icons/Feather'
import HomeScreen from './screens/Example'
import ControlScreen from './screens/Main'
import MoreScreen from './screens/Sample'
import SignUpScreen from './screens/login'
import AboutScreen from './screens/login'
const TabContainer = createBottomTabNavigator({
Home: {
screen: HomeScreen,
navigationOptions: {
tabBarIcon: ({ tintColor, focused }) => <Icon name="home" size={20} color={`${focused ? tintColor : '#404040'}`} />,
}
},
Controls: {
screen: ControlScreen,
navigationOptions: {
tabBarIcon: ({ tintColor, focused }) => <Icon name="sliders" size={20} color={`${focused ? tintColor : '#404040'}`} />
}
},
More: {
screen: MoreScreen,
navigationOptions: {
tabBarIcon: ({ tintColor, focused }) => <Icon name="more-horizontal" size={20} color={`${focused ? tintColor : '#404040'}`} />
}
},
},{
tabBarposition: 'bottom',
swipeEnabled: false,
tabBarOptions: {
activeTintColor: '#069',
inactiveTintColor: '#404040',
labelStyle: {
fontSize: 14,
paddingTop: 0,
paddingBottom: 0
},
style:{
borderTopWidth: 1,
borderTopColor:'#333333',
position: 'absolute',
bottom: 0,
left: 0
},
animationEnabled: false,
tabStyle: {
paddingBottom: 15,
paddingTop: 0,
height: 75,
marginBottom: 0,
},
}
}
)
const MainDrawerNavigator = createDrawerNavigator({
Home: {
screen: TabContainer,
headerStyle: {
backgroundColor: '#f4511e',
},
headerTintColor: '#fff',
headerTitleStyle: {
fontWeight: 'bold',
},
title: 'Home',
navigationOptions: {
drawerIcon: ({ tintColor }) => (
<Icon name="home" size={20} color={'#404040'} />
),
}
},
SignUp: {
screen: SignUpScreen,
navigationOptions: {
drawerIcon: ({ tintColor }) => (
<Icon name="user" size={20} color={'#404040'} />
),
}
},
About: {
screen: AboutScreen,
navigationOptions: {
drawerIcon: ({ tintColor }) => (
<Icon name="alert-circle" size={20} color={'#404040'} />
),
}
},
},{
initialRouteName:"Home"
}
)
const StackContainer = createStackNavigator({
MainDrawerNavigator,
}, {
defaultNavigationOptions: ({ navigation }) => {
return {
headerTitle:"Welcome!",
headerLeft: (
<Icon
style={{ paddingLeft: 10 }}
onPress={() => navigation.openDrawer()}
name="menu"
size={30}
/>
)
};
}
})
export default createAppContainer(StackContainer)
Hope this helps!

Related

React Native -- Even after imports and exports are correct getting error "The component for route 'Menu' must be a react component"

I have encountered the mentioned error. I searched for this through different links as. I changed import and export according to the answer to this question but the same error is still there. I have done imports and exports correctly.*
This is
MainComponent.js file where the Menu component is imported.
import React, { Component } from 'react';
import Menu from './MenuComponent';
import Dishdetail from './DishDetailComponent';
import Contact from './ContactComponent';
import About from './AboutComponent';
import Home from './HomeComponent';
import { View, Platform, Image, StyleSheet, ScrollView, Text } from 'react-native';
import { createStackNavigator, createDrawerNavigator, DrawerItems, SafeAreaView, SrollView } from 'react-navigation';
import { Icon } from 'react-native-elements';
import { connect } from 'react-redux';
import { fetchDishes, fetchComments, fetchPromos, fetchLeaders } from '../redux/ActionCreators';
const mapStateToProps = (state) => {
return {
dishes: state.dishes,
promotions: state.promotions,
leaders: state.leaders,
};
};
const mapDispatchToProps = (dispatch) => ({
fetchDishes: () => dispatch(fetchDishes()),
fetchComments: () => dispatch(fetchComments()),
fetchPromos: () => dispatch(fetchPromos()),
fetchLeaders: () => dispatch(fetchLeaders()),
});
const MenuNavigator = createStackNavigator(
{
Menu: {
screen: Menu,
navigationOptions: ({ navigation }) => ({
headerLeft: <Icon name="menu" size={24} color="#fff" onPress={() => navigation.toggleDrawer()} />,
}),
},
Dishdetail: { screen: Dishdetail },
},
{
initialRouteName: 'Menu',
navigationOptions: {
headerStyle: {
backgroundColor: '#512DA8',
},
headerTintColor: '#fff',
headerTitleStyle: {
color: '#fff',
},
},
}
);
const HomeNavigator = createStackNavigator(
{
Home: { screen: Home },
},
{
navigationOptions: ({ navigation }) => ({
headerStyle: {
backgroundColor: '#512DA8',
},
headerTintColor: '#fff',
headerTitleStyle: {
color: '#fff',
},
headerLeft: <Icon name="menu" size={24} color="#fff" onPress={() => navigation.toggleDrawer()} />,
}),
}
);
const ContactNavigator = createStackNavigator(
{
Contact: { screen: Contact },
},
{
navigationOptions: ({ navigation }) => ({
headerStyle: {
backgroundColor: '#512DA8',
},
headerTintColor: '#fff',
headerTitleStyle: {
color: '#fff',
},
headerLeft: <Icon name="menu" size={24} color="#fff" onPress={() => navigation.toggleDrawer()} />,
}),
}
);
const AboutNavigator = createStackNavigator(
{
About: { screen: About },
},
{
navigationOptions: ({ navigation }) => ({
headerStyle: {
backgroundColor: '#512DA8',
},
headerTintColor: '#fff',
headerTitleStyle: {
color: '#fff',
},
headerLeft: <Icon name="menu" size={24} color="#fff" onPress={() => navigation.toggleDrawer()} />,
}),
}
);
const CustomDrawerContentComponent = (props) => (
<ScrollView>
<SafeAreaView style={styles.container} forceInset={{ top: 'always', horizontal: 'never' }}>
<View style={styles.drawerHeader}>
<View style={{ flex: 1 }}>
<Image source={require('./images/logo.png')} style={styles.drawerImage} />
</View>
<View style={{ flex: 2 }}>
<Text style={styles.drawerHeaderText}>VangooApp</Text>
</View>
</View>
<DrawerItems {...props} />
</SafeAreaView>
</ScrollView>
);
const MainNavigator = createDrawerNavigator(
{
Home: {
screen: HomeNavigator,
navigationOptions: {
title: 'Home',
drawerLabel: 'Home',
drawerIcon: ({ tintColor }) => <Icon name="home" type="font-awesome" size={24} color={tintColor} />,
},
},
About: {
screen: AboutNavigator,
navigationOptions: {
title: 'About',
drawerLabel: 'About Us',
drawerIcon: ({ tintColor }) => (
<Icon name="info-circle" type="font-awesome" size={24} color={tintColor} />
),
},
},
Menu: {
screen: MenuNavigator,
navigationOptions: {
title: 'Menu',
drawerLabel: 'Menu',
drawerIcon: ({ tintColor }) => <Icon name="list" type="font-awesome" size={24} color={tintColor} />,
},
},
Contact: {
screen: ContactNavigator,
navigationOptions: {
title: 'Contact',
drawerLabel: 'Contact Us',
drawerIcon: ({ tintColor }) => (
<Icon name="address-card" type="font-awesome" size={22} color={tintColor} />
),
},
},
},
{
drawerBackgroundColor: '#D1C4E9',
contentComponent: CustomDrawerContentComponent,
}
);
class MainComponent extends Component {
componentDidMount() {
this.props.fetchDishes();
this.props.fetchComments();
this.props.fetchPromos();
this.props.fetchLeaders();
}
render() {
return (
<View style={{ flex: 1, paddingTop: Platform.OS === 'ios' ? 0 : Expo.Constants.statusBarHeight }}>
<MainNavigator />
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
drawerHeader: {
backgroundColor: '#512DA8',
height: 140,
alignItems: 'center',
justifyContent: 'center',
flex: 1,
flexDirection: 'row',
},
drawerHeaderText: {
color: '#fff',
fontSize: 24,
fontWeight: 'bold',
},
drawerImage: {
margin: 10,
width: 80,
height: 60,
},
});
export default connect(mapStateToProps, mapDispatchToProps)(MainComponent);
MenuComponent.js
import React, { Component } from 'react';
import { FlatList } from 'react-native';
import { Tile } from 'react-native-elements';
import { connect } from 'react-redux';
import { baseUrl } from '../shared/baseURL';
const mapStateToProps = (state) => {
return {
dishes: state.dishes,
};
};
class Menu extends Component {
static navigationOptions = {
title: 'Menu',
};
render() {
const renderMenuItem = ({ item, index }) => {
return (
<Tile
key={index}
title={item.name}
caption={item.description}
featured
onPress={() => navigate('Dishdetail', { dishId: item.id })}
imageSrc={{ uri: baseUrl + item.image }}
/>
);
};
const { navigate } = this.props.navigation;
return (
<FlatList
data={this.props.dishes.dishes}
renderItem={renderMenuItem}
keyExtractor={(item) => item.id.toString()}
/>
);
}
}
export default connect(mapStateToProps)(Menu);
[![Error][1]][1]

React Native - making a second tab bar navigator for a modal screen

Building out a relatively simple app on React Native, I currently have a tabBarNavigator where one of the icons on the tab bar opens a pop-up modal. I'm then trying to create another, separate, tab bar at the bottom of the modal.
However although I have created a tabBarNavigator and appContainer in my root App.js and have exported this container (passing it through my modal component), the modal then loads the base stack rather than the modal stack which I created - obviously not desired behavior!
The relevant portion of App.js:
const ModalNavigator = createBottomTabNavigator({
Photo: { screen: PrivacySettings,
navigationOptions: {
headerMode: false,
tabBarIcon: ({ tintColor }) => <Feather name="camera" size={24} color="black" />
}
},
Camera: { screen: HelpSettings,
navigationOptions: {
headerMode: false,
tabBarIcon: ({ tintColor }) => <Feather name="type" size={24} color="black" />
}
},
Text: { screen: ContactUs,
navigationOptions: {
headerMode: false,
tabBarIcon: ({ tintColor }) => <Feather name="type" size={24} color="black" />
}
}
});
export const ModalContainer = createAppContainer(ModalNavigator);
const AppContainer = createStackNavigator({
default: createBottomTabNavigator({
Home: { screen: Home,
navigationOptions: {
headerMode: false,
tabBarIcon: ({ tintColor }) => <FontAwesomeIcon size={30} icon={faHome} color={tintColor}/>
}
},
Search: { screen: Contacts,
navigationOptions: {
headerMode: false,
tabBarIcon: ({ tintColor }) => <FontAwesomeIcon size={30} icon={faSearch} color={tintColor}/>
}
},
AddPhoto: { screen: () => null,
navigationOptions: {
headerTitle: "Upload Photo",
tabBarIcon: <AddPhotoButton/>,
headerMode: 'none',
}
},
Likes: {screen: Vault,
navigationOptions: {
headerMode: false,
tabBarIcon: ({ tintColor }) => <FontAwesomeIcon size={30} icon={faHeart} color={tintColor}/>
}
},
Settings: {screen: Me,
navigationOptions: {
headerMode: false,
tabBarIcon: ({ tintColor }) => <FontAwesomeIcon size={30} icon={faUser} color={tintColor}/>
}
}
},
{
defaultNavigationOptions: {
tabBarOnPress: ({ navigation, defaultHandler }) => {
if (navigation.state.key === 'AddPhoto') {
navigation.navigate('addPhotoModal')
} else {
defaultHandler()
}
},
cardStyle: {
backgroundColor: "transparent",
opacity: 1
}
},
tabBarOptions: {
showLabel: false,
activeTintColor: '#1A86CB',
inactiveTintColor: 'black'
},
initialRouteName: "Home",
}),
addPhotoModal: {
screen: AddPhotoModal }
}, {
mode: 'modal',
headerMode: 'none',
transparentCard: true,
}
)
const Routes = createStackNavigator({
Home: { screen: AppContainer,
navigationOptions: {
headerShown: false }
},
SignIn: { screen: SignIn },
AddContact: { screen: AddContact,
navigationOptions: {
headerTitle: "Add Contact" }
},
ContactDetails: {screen: ContactDetails },
PrivacySettings: {screen: PrivacySettings,
navigationOptions: {
headerTitle: "Privacy",
headerStyle: {
backgroundColor: 'white',
shadowColor: 'transparent'
}}
},
NotificationSettings: {screen: NotificationSettings,
navigationOptions: {
headerTitle: "Notifications",
headerStyle: {
backgroundColor: 'white',
shadowColor: 'transparent'
}}
},
HelpSettings: {screen: HelpSettings,
navigationOptions: {
headerTitle: "Help",
headerStyle: {
backgroundColor: 'white',
shadowColor: 'transparent'
}}
},
InviteSettings: {screen: InviteSettings,
navigationOptions: {
headerTitle: "Invite Friends",
headerStyle: {
backgroundColor: 'white',
shadowColor: 'transparent'
}}
},
ContactUs: {screen: ContactUs,
navigationOptions: {
headerTitle: "Contact Us",
headerStyle: {
backgroundColor: 'white',
shadowColor: 'transparent'
}}
},
},
{ initialRouteName: "Home",
});
const AuthStack = createStackNavigator({
Login: SignIn,
})
export default createAppContainer(
createSwitchNavigator(
{
Loading: LoadingScreen,
App: Routes,
Auth: AuthStack
},
{
initalRouteName: LoadingScreen
}
)
)
The relevant portion of the Modal Component:
import ModalContainer from '../../App'
export default class AddPhotoModal extends React.Component {
render() {
return(
<View style={{backgroundColor:"#000000CC", flex:1}}>
<View style={{ backgroundColor:"#ffffff", marginLeft: 0, marginRight: 0, marginTop: 240, padding: 20, borderRadius: 20, flex: 1, }}>
<View style={styles.header}>
<TouchableOpacity style={{position: 'absolute'}} onPress={() => this.props.navigation.goBack()}>
<Text style={styles.buttonFont}>Back</Text>
</TouchableOpacity>
<TouchableOpacity style={{position: 'absolute', right: 0}} onPress={() => this.props.navigation.navigate('UploadScreen')}>
<Text style={styles.buttonFont}>Continue</Text>
</TouchableOpacity>
</View>
<ModalContainer/>
</View>
</View>
);
}
}
Edit:
With the below answer, I'm now getting this. Is there a way to place the tabbar as a child of the modal component?
https://ibb.co/kcTq0X3
'ModalContainer' is not a part of the 'Routes', So it is not known to the SwitchNavigator.
Add ModalContainer as a part of 'Routes' stack.
And to show the ModalContainer bottomTabs, navigate to ModalContainer on click of the tabIcon

react-navigation-tabs - icons not aligned and covering text

I cant seem to get the icons to align using the new react-navigation-tabs.....some icons are sitting higher than others.
Also the icons are covering the labels and Id like to have some margin between icon and label.
I tried the code style={{textAlignVertical: 'center'}} for the icons (from another question on SO) but that did not work either
Below is code
import {createMaterialTopTabNavigator} from 'react-navigation-tabs';
import IconFA from 'react-native-vector-icons/FontAwesome';
import IconMCI from 'react-native-vector-icons/MaterialCommunityIcons';
const ProfileTabBarIcon = ({tintColor}) => (
<IconFA
name="user-circle"
size={35}
color={tintColor}
/>
);
const SearchTabBarIcon = ({tintColor}) => (
<IconMCI
name="account-search"
size={45}
color={tintColor}
/*onPress={() => {
console.log('HELP!!');
this.props.navigation.navigate('Search');
}}*/
/>
);
const MessageTabBarIcon = ({tintColor}) => (
<IconFA
name="envelope"
size={35}
color={tintColor}
/>
);
const SignedInTabNav = createMaterialTopTabNavigator(
{
Profile: {
screen: Profile,
navigationOptions: {
tabBarLabel: 'Me',
tabBarIcon: ProfileTabBarIcon,
},
},
Search: {
screen: Search,
navigationOptions: {
tabBarLabel: 'Search',
tabBarIcon: SearchTabBarIcon,
},
},
Message: {
screen: Message,
navigationOptions: {
tabBarLabel: 'Message',
tabBarIcon: MessageTabBarIcon,
},
},
},
{
tabBarOptions: {
showIcon: true,
upperCaseLabel: false,
activeTintColor: '#42CBC8',
inactiveTintColor: '#9A9F99',
iconStyle: {
width: 'auto',
height: 20,
},
labelStyle: {
fontSize: 12,
},
style: {
backgroundColor: '#F8F8FF',
//borderBottomWidth: 2,
borderBottomColor: '#D3D3D3',
paddingVertical: 2,
height: 60,
},
},
animationEnabled: false,
},
);
....but this is what it looks like :(
Can anyone help?
I styled the first icon and you can change it as necessary to fit your needs and then apply those to the other two icons as well. If you need to understand what is going on better go ahead and apply backgroundColor attr to different elements. Simply, I wrapped the icon component in a View and then gave that view some styling to fit the icon appropriately.
import {createMaterialTopTabNavigator} from 'react-navigation-tabs';
import IconFA from 'react-native-vector-icons/FontAwesome';
import IconMCI from 'react-native-vector-icons/MaterialCommunityIcons';
import HomeScreen from '../screens/HomeScreen';
import LinksScreen from '../screens/LinksScreen';
import SettingsScreen from '../screens/SettingsScreen';
import React from 'react';
import { StyleSheet, View } from 'react-native';
const ProfileTabBarIcon = ({tintColor}) => (
<View style={styles.container}>
<IconFA
style={styles.iconStyle}
name="user-circle"
size={35}
color={tintColor}
/>
</View>
);
const SearchTabBarIcon = ({tintColor}) => (
<IconMCI
name="account-search"
size={45}
color={tintColor}
/*onPress={() => {
console.log('HELP!!');
this.props.navigation.navigate('Search');
}}*/
/>
);
const MessageTabBarIcon = ({tintColor}) => (
<IconFA
name="envelope"
size={35}
color={tintColor}
/>
);
export default SignedInTabNav = createMaterialTopTabNavigator(
{
Profile: {
screen: HomeScreen,
navigationOptions: {
tabBarLabel: 'Me',
tabBarIcon: ProfileTabBarIcon,
},
},
Search: {
screen: LinksScreen,
navigationOptions: {
tabBarLabel: 'Search',
tabBarIcon: SearchTabBarIcon,
},
},
Message: {
screen: SettingsScreen,
navigationOptions: {
tabBarLabel: 'Message',
tabBarIcon: MessageTabBarIcon,
},
},
},
{
tabBarOptions: {
showIcon: true,
upperCaseLabel: false,
activeTintColor: '#42CBC8',
inactiveTintColor: '#9A9F99',
labelStyle: {
fontSize: 12,
margin: 0
},
iconStyle: {
flex: 1
},
style: {
backgroundColor: '#F8F8FF',
height: 65,
borderBottomColor: '#D3D3D3',
},
},
animationEnabled: false,
},
);
const styles = StyleSheet.create({
container: {
flex: 1,
width: 50,
alignItems: 'center',
justifyContent: 'center',
alignSelf: 'center',
}
});
I added an empty tabBarLabel in the tab screen, and included the text inside the tabBarIcon.
<Tab.Screen
name="Home"
component={MainStackNavigator}
options=
{{
tabBarLabel:"",
tabBarIcon:() =>
{
return(
<View>
<Text>Home</Text>
<Image
style={{ width:20,height:20 }}
source{require('./assets/home_white.png')}>
</Image>
</View>
)
}
}}
/>
set resizeMode in your style section
such as :
<Image
source={iconName}
style={{ width: 25, height: 25, tintColor }}
resizeMode={"contain"}
/>

I couldn't use react-navigation tab bar. How to use this?

Now I am trying to create React Native app on Expo and use React-Navigation Tab Bar but I could't.
Actually I don't get any error but this code below doesn't work.
No warning as well.
import { createBottomTabNavigator, createAppContainer } from 'react-
navigation';
import Icon from 'react-native-vector-icons/FontAwesome';
import Home from './src/Screens/Home';
import Help from './src/Screens/Help';
const App = createBottomTabNavigator(
{
Home: {
screen: Home,
defaultNavigationOptions: {
tabBarIcon: ({ tintColor }) => {
<Icon name="home" style={{ width: 25, height: 25, tintColor:
tintColor}}/>
},
title: 'Home',
},
},
Help: { screen: Help },
},
{
swipeEnabled: false, //Android用
tabBarOptions: {
activeTintColor: '#DE628D',
inactiveTintColor: '#707070',
},
},
);
export default createAppContainer(App);
the tab works fine, but if you meant, there's no icon, try this instead
navigationOptions: {
tabBarIcon: ({ tintColor, activeTintColor }) => (
<Icon name="home" size={24} color={tintColor} />)
},
Please try to implement this way. This is copy of my tabNavigator. Hope this will be helpful for you.
const TabRouter = createBottomTabNavigator(
{
HomeAfterLoginScreen: { screen: A },
ShowListAlertScreen: { screen: B },
ShowListProfessionScreen: { screen: C },
MyAccountScreen: { screen: F }
},
{
tabBarPosition: "bottom",
tabBarOptions: {
style: { backgroundColor: "#50bcb8" },
showIcon: true,
showLabel: true,
gesturesEnabled: true,
indicatorStyle: { borderBottomWidth: 3, borderBottomColor: Style.color },
inactiveTintColor: "#fff",
activeTintColor: "#fff",
tabStyle: { justifyContent: "center", alignItems: "center" }
}
});
I got it. I have solved this issue.
const App = createBottomTabNavigator(
{
Favorite: {
screen: FavoriteShops,
navigationOptions: {
tabBarLabel: 'お気に入り',
tabBarIcon: ({ tintColor }) => (
<Icon name="heart" size={25} color={tintColor} />
),
},
},
Home: {
screen: Home,
navigationOptions: {
tabBarLabel: 'ホーム',
tabBarIcon: ({ tintColor }) => (
<Icon name="home" size={30} color={tintColor} />
),
},
},
Help: {
screen: Help,
navigationOptions: {
tabBarLabel: 'その他',
tabBarIcon: ({ tintColor }) => (
<Icon name="bars" size={25} color={tintColor} />
),
},
},
},
{
swipeEnabled: false, //Android用
tabBarOptions: {
showIcon: true,
showLabel: true,
activeTintColor: '#DE628D',
inactiveTintColor: '#707070',
style: {
width: '100%',
height: 70,
},
tabStyle: {
paddingTop: 20,
},
},
},
);

How to get a background image in createBottomTabNavigator?

I have been trying to get a background image for the tabbar. I tried using tabBarComponent but it hides the tabs under it.
The code that I am using is
export default MainNavigation = createBottomTabNavigator(
{
Profile:{
screen: Profile,
navigationOptions: ({ navigation }) => ({
tabBarIcon: ({ focused, tintColor }) => {
return <Image source={require('./images/tab_explore.png')} />
}
}),
}
},
{
tabBarComponent: props =>{
return(
<View style={{backgroundColor:"black"}}>
<Image
style={{ width:'100%', height: 80 }}
source={ require('./images/bottom_btn.png')} />
</View>
);
}
})
Does anyone know how to solve the problem? Thanks in advance!
Current Output:
It should show the tabs on top of orange color.
Maybe it is too late, but I wish this answer will help many people. In React Navigation version 2 you can do it like this:
import { createBottomTabNavigator, BottomTabBar } from 'react-navigation-tabs';
You don't need to install react-navigation-tabs if you have installed 'react-navigation'.
Then create TabBarComponent by const TabBarComponent = (props) => (<BottomTabBar {...props} />);. You will use tabBarComponent key in createBottomTabNavigator. BackgroundColor: 'transparent' for default tabs and VOILA!
The following code will give you the main idea
export const Tabs = createBottomTabNavigator({
Posters: {
screen: Posters,
navigationOptions: {
tabBarLabel: 'AFİŞA',
tabBarIcon: ({tintColor}) => (
<MaterialIcons name="local-movies" size={24} color={tintColor} />
)
}
},
ComingSoon: {
screen: ComingSoon,
navigationOptions: {
tabBarLabel: 'TEZLİKLƏ',
tabBarIcon: ({tintColor}) => (
<MaterialIcons name="movie" size={24} color={tintColor} />
)
}
},
Tickets: {
screen: Tickets,
navigationOptions: {
tabBarLabel: 'BİLETLƏR',
tabBarIcon: ({tintColor}) => (
<MaterialIcons name="confirmation-number" size={24} color={tintColor} />
),
}
},
More: {
screen: More,
navigationOptions: {
tabBarLabel: 'MENU',
tabBarIcon: ({tintColor}) => (
<MaterialIcons name="more-horiz" size={24} color={tintColor} />
),
tabBarOnPress: ({ navigation }) => {
return <Text>sd</Text>
}
}
},
},
{
order: ['Posters', 'ComingSoon', 'Tickets', 'More' ],
tabBarOptions: {
activeTintColor: colors.darkYellow(),
inactiveTintColor: 'white',
labelStyle: {
fontSize: 12,
fontWeight: 'bold',
fontFamily: defaults.fontFamily
},
style: styles.tabBar,
},
tabBarComponent: props =>{
return(
<React.Fragment>
<TabBarComponent {...props} />
<Image style={styles.fakeTabBackground}/>
</React.Fragment>
)
}
})
I wish I could comment but I don't have enough reputation to do that.
<React.Fragment>
<ImageBackground
source={require('./images/bottom_btn.png')}
style={{width: '100%', height: 80}}
>
<TabBarComponent {...props} />
</ImageBackground>
</React.Fragment>
This worked for me. Spent almost a day figuring out the <ImageBackground> thing.
With the latest version of the 'react-navigation-tabs' the above solutions don't work, what we need to do is, we should pass the following three properties to the BottomTabBar component explicitly:
<BottomTabBar
{...this.props}
getButtonComponent={this.getButtonComponent}
getAccessibilityRole={() => 'button'}
getAccessibilityStates={({focused}) => (focused ? ['selected'] : [])}
/>
So the full code for this example is as follows :
class TabBar extends React.Component {
render() {
return (
<BottomTabBar
{...this.props}
getButtonComponent={this.getButtonComponent}
getAccessibilityRole={() => 'button'}
getAccessibilityStates={({focused}) => (focused ? ['selected'] : [])}
/>
);
}
getButtonComponent({route}) {
if (route.key === 'Other') {
return () => <View />; // a view that doesn't render its children
} else {
return null; // use the default nav button component
}
}
}
const Tabs = createMaterialTopTabNavigator(
{
home: {
screen: Home_StackNavigator,
navigationOptions: ({navigation}) => ({
title: 'home',
tabBarIcon: ({tintColor}) => (
<FontAwesome name="home" size={23} color={tintColor} />
),
}),
},
favourites: {
screen: Favourites_StackNavigator,
navigationOptions: ({navigation}) => ({
title: 'favourites',
tabBarIcon: ({tintColor}) => (
<Ionicons name="md-star" size={25} color={tintColor} />
),
}),
},
calendar: {
screen: Calendar_StackNavigator,
navigationOptions: ({navigation}) => ({
title: 'calendar',
tabBarIcon: ({tintColor}) => (
<Feather name="calendar" size={23} color={tintColor} />
),
}),
},
shoppingList: {
screen: ShoppingList_StackNavigator,
navigationOptions: ({navigation}) => ({
title: 'shopping List',
tabBarIcon: ({tintColor}) => (
<Feather name="shopping-bag" size={23} color={tintColor} />
),
}),
},
profile: {
screen: Profile_StackNavigator,
navigationOptions: ({navigation}) => ({
title: 'profile',
tabBarIcon: ({tintColor}) => (
<Feather name="user" size={23} color={tintColor} />
),
}),
},
},
{
tabBarPosition: 'bottom',
swipeEnabled: false,
animationEnabled: true,
tabBarOptions: {
showIcon: true,
activeTintColor: Colors.DARK.ICON_ACTIVE,
inactiveTintColor: Colors.DARK.ICON_INACTIVE,
style: {
backgroundColor: 'transparent',
},
labelStyle: {
textAlign: 'center',
fontSize: 10,
textTransform: 'capitalize',
color: Colors.DARK.ICON_INACTIVE,
marginBottom: 1,
width: 70,
},
indicatorStyle: {
borderBottomColor: Colors.DARK.ICON_INACTIVE,
borderBottomWidth: 2,
},
},
tabBarComponent: (props) => {
return (
<React.Fragment>
<ImageBackground
source={require('../../assets/images/image_bottom.jpg')}
style={{width: '100%', height: 60}}>
<TabBar {...props} />
</ImageBackground>
</React.Fragment>
);
},
},
);