React-navigation: how to style a big middle button in tab navigation? - react-native

So I have this requirement. To make tab navigation with this exact appearance:
I had no problem styling the tab bar with the gradient and the buttons. I created my own custom one with this code:
export default createBottomTabNavigator({
(... routes here)
}, {
initialRouteName: "Inspiration",
tabBarComponent: props => <BottomTabBar {...props} />
})
But now I'm having trouble with the middle button. My bar looks like this:
If I remove the custom tab bar removing this line:
tabBarComponent: props => <BottomTabBar {...props} />
Then now my middle button looks how it should, but of course, all of the other styles are missing:
This is how my BottomTabBar component looks right now:
import React from "react";
import { Image, StyleSheet, Text, TouchableOpacity } from "react-native";
import { TabBarBottomProps, NavigationRoute } from "react-navigation";
import LinearGradient from "react-native-linear-gradient";
const iconBag = require("./images/bag.png");
export default function BottomTabBar(props: TabBarBottomProps) {
const {
renderIcon,
getLabelText,
activeTintColor,
inactiveTintColor,
onTabPress,
onTabLongPress,
getAccessibilityLabel,
navigation
} = props;
const { routes, index: activeRouteIndex } = navigation.state;
function renderTabBarButton(routeIndex, route) {
const isRouteActive = routeIndex === activeRouteIndex;
const tintColor = isRouteActive ? activeTintColor : inactiveTintColor;
if (route.key == "Bag")
return <Image style={{ width: 100, height: 100 }} source={iconBag} />;
return (
<TouchableOpacity
key={routeIndex}
style={styles.tabButton}
onPress={() => onTabPress({ route })}
onLongPress={() => onTabLongPress({ route })}
accessibilityLabel={getAccessibilityLabel({ route })}
>
{renderIcon({ route, focused: isRouteActive, tintColor })}
<Text style={styles.tabText}>{getLabelText({ route })}</Text>
</TouchableOpacity>
);
}
return (
<LinearGradient colors={["#FFFFFF", "#DEDEDE"]} style={styles.container}>
{routes.map((route, routeIndex) => renderTabBarButton(routeIndex, route))}
</LinearGradient>
);
}
const styles = StyleSheet.create({
container: {
height: 60,
flexDirection: "row",
alignItems: "center",
borderWidth: 1,
borderColor: "#C4C4C4"
},
tabButton: {
flex: 1,
justifyContent: "center",
alignItems: "center"
},
tabText: {
fontFamily: "Source Sans Pro",
fontSize: 11,
color: "#454545",
marginTop: 1
}
});
What can I do? Any help will be really much appreciated!

You can try my solution
const TabNavigator = createBottomTabNavigator(
{
Top: {
screen: HomeScreen,
navigationOptions: {
tabBarIcon: ({tintColor}) => (
<Image
source={require('./src/assets/ic_list.png')}
style={{width: 24, height: 24, tintColor: tintColor}}
/>
),
},
},
New: {
screen: HomeScreen,
navigationOptions: {
tabBarIcon: ({tintColor}) => (
<Image
source={require('./src/assets/ic_clock.png')}
style={{width: 24, height: 24, tintColor: tintColor}}
/>
),
},
},
Ask: { // big plus icon in the middle
screen: HomeScreen,
navigationOptions: {
tabBarIcon: ({tintColor}) => (
<View
style={{
position: 'absolute',
bottom: 20, // space from bottombar
height: 58,
width: 58,
borderRadius: 58,
backgroundColor: '#5a95ff',
justifyContent: 'center',
alignItems: 'center',
}}>
<Image
source={require('./src/assets/ic_add_24.png')}
style={{
width: 40,
height: 40,
tintColor: '#f1f6f9',
alignContent: 'center',
}}
/>
</View>
),
},
},
Show: {
screen: HomeScreen,
navigationOptions: {
tabBarIcon: ({tintColor}) => (
<Image
source={require('./src/assets/ic_notification.png')}
style={{width: 24, height: 24, tintColor: tintColor}}
/>
),
},
},
Jobs: {
screen: HomeScreen,
navigationOptions: {
tabBarIcon: ({tintColor}) => (
<Image
source={require('./src/assets/ic_person.png')}
style={{width: 24, height: 24, tintColor: tintColor}}
/>
),
},
},
},
{
tabBarOptions: {
activeTintColor: '#FF6F00',
inactiveTintColor: '#8997B0',
showIcon: true,
showLabel: false,
style: {
backgroundColor: '#f1f6f9',
},
},
},
);

I made this bottom tab with react native. I think your design is very simple. My code sample will help you I think.
import React from 'react';
import { createBottomTabNavigator, createStackNavigator } from 'react-navigation';
import { View, Image } from 'react-native'
import { Text } from 'native-base';
import Featured from './featured';
import AboutUs from './about_us';
import Shop from './shop';
import Booking from './booking';
import Settings from './settings';
import styles from './styles';
import star from './../../assets/images/icons/star.png';
import star_check from './../../assets/images/icons/star_check.png';
import about from './../../assets/images/icons/about.png';
import about_check from './../../assets/images/icons/about_check.png';
import book from './../../assets/images/icons/book.png';
import check from './../../assets/images/icons/check.png';
import shop from './../../assets/images/icons/shop.png';
import shop_check from './../../assets/images/icons/shop_check.png';
import more from './../../assets/images/icons/more.png';
import more_check from './../../assets/images/icons/more_check.png';
const Tabs = createBottomTabNavigator(
{
Featured: {
screen: Featured,
navigationOptions: {
title: 'Featured',
tabBarIcon: ({ tintColor, focused }) => (
<View style={styles.tab}>
<Image source={focused? star_check : star} style={styles.icon} />
<Text style={[styles.name, {color: tintColor}]}>Kampanjer</Text>
</View>
)
}
},
AboutUs: {
screen: AboutUs,
navigationOptions: {
title: 'About Us',
tabBarIcon: ({ tintColor, focused }) => (
<View style={styles.tab}>
<Image source={focused? about_check : about} style={styles.icon} />
<Text style={[styles.name, {color: tintColor}]}>Om oss</Text>
</View>
)
}
},
Booking: {
screen: Booking,
navigationOptions: {
title: 'MIN SALONG',
tabBarIcon: ({ tintColor, focused }) => (
<View style={styles.book}>
<Image source={focused? check : book} style={styles.book_icon} />
</View>
)
}
},
Shop: {
screen: Shop,
navigationOptions: {
title: 'Shop',
tabBarIcon: ({ tintColor, focused }) => (
<View style={styles.tab}>
<Image source={focused? shop_check : shop} style={styles.icon} />
<Text style={[styles.name, {color: tintColor}]}>Shop</Text>
</View>
)
}
},
Settings: {
screen: Settings,
navigationOptions: {
title: 'More',
tabBarIcon: ({ tintColor, focused }) => (
<View style={styles.tab}>
<Image source={focused? more_check : more} style={styles.icon} />
<Text style={[styles.name, {color: tintColor}]}>Inställningar</Text>
</View>
)
}
},
},
{
initialRouteName: 'Featured',
tabBarOptions: {
activeTintColor: '#80A0AB',
inactiveTintColor: '#fff',
showLabel: false,
style: {
height: 60,
backgroundColor: '#485155'
},
labelStyle: {
fontSize: 12,
fontFamily: 'Abel-Regular'
}
}
}
);
export default createStackNavigator({Tabs}, {headerMode: "none"});

Try this
<Tab.Navigator
tabBarOptions={{
activeTintColor: 'red',
// activeBackgroundColor:'#000',
//inactiveBackgroundColor:'red',
labelStyle: {
position: 'absolute',
top: constants.vh(35),
fontSize:constants.vh(18),
}
}}
>
<Tab.Screen name='Home' //bottom tab for Home
options={{
tabBarIcon: ({ focused }) => {
let iconName;
iconName = focused ? constants.images.bottomHome : constants.images.bottomHome //for icon or image
return (
<View>
<Image source={iconName} style={{ width: constants.vw(40), height: constants.vh(25) ,position:'absolute',right:constants.vw(-20),bottom:constants.vh(-5)}} resizeMode="contain" />
</View>
)
}
}}
component={HomeScreen} />
</Tab.Navigator>

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]

Pass Props from the react-redux to React Native Bottom Tab Navigation

I am struggling with the
import { createBottomTabNavigator } from 'react-navigation-tabs';
I want to pass the value of my cartItems from react redux to Bottom Navigation Icon but from no where I am able to pass the props.
Here is my code,
import React from 'react';
import { View, Text } from 'react-native';
import { createBottomTabNavigator } from 'react-navigation-tabs';
import Icon from 'src/containers/IconTabbar';
import Home from 'src/screens/home/home';
import Cart from 'src/screens/cart/cart';
import { connect } from 'react-redux';
const Tabs = createBottomTabNavigator(
{
home: {
screen: Home,
navigationOptions: () => ({
title: 'Home',
tabBarIcon: ({ tintColor }) => <Icon name="home" color={tintColor} />,
}),
},
cart: {
screen: Cart,
navigationOptions: () => ({
title: 'Cart',
tabBarIcon: ({ tintColor }) => <View>
<View style={{ position: 'absolute', height: 20, width: 20, borderRadius: 15, backgroundColor: 'rgba(95,197,123,0.8)', right: 10, bottom: 15, alignItems: 'center', justifyContent: 'center', zIndex: 2000, }}>
//Here I want add props instead of 4 like this.props.cartItems
<Text style={{ color: 'white', fontWeight: 'bold' }}>4</Text>
</View>
<Icon name="shopping-cart" color={tintColor} />
</View>,
}),
},
},
{
defaultNavigationOptions: props => {
return {
tabBarOptions: {
style: {
height: 60,
elevation: 0,
borderTopWidth: 1,
},
activeTintColor: 'green',
inactiveTintColor: 'grey',
},
};
},
}
);
const mapStateToProps = (state) => {
return {
cartItems: state.carts.carts
}
}
export default connect(mapStateToProps)(Tabs);
Image of Static 4 Value displaying in BottomTabNavigation
You can create a separate component for the tab icon and connect it to redux.
Here is an untested example.
const TabIcon = (props) => {
return (
<View>
<View style={{
position: 'absolute', height: 20, width: 20, borderRadius: 15,
backgroundColor: 'rgba(95,197,123,0.8)', right: 10, bottom: 15, alignItems: 'center', justifyContent: 'center', zIndex: 2000,
}}>
<Text style={{ color: 'white', fontWeight: 'bold' }}>{props.cartItems}</Text>
</View>
<Icon name="shopping-cart" color={props.tintColor} />
</View >
)
}
const mapStateToProps = state => {
return {
cartItems: state.carts.carts
}
}
export default connect(mapStateToProps, null)(TabIcon)
You can then try something like:
tabBarIcon: ({ tintColor }) => (
<TabIcon tintColor={tintColor}/>
)

Passing this.state into static function

I am trying to set the headerTitle in the header bar to be the username of the logged in user: this.state.username. However, when I try to set navigationOptions to a function, I am unable to pass in the current state.
What would be the best way to set the headerTitle inside the static navigationOptions? I believe that navigationOptions must remain static, otherwise nothing will be displayed.
class profile extends React.Component {
static navigationOptions =
{
headerTitle: this.state.username
};
const TabStack = createBottomTabNavigator(
{
Home: {
screen: home,
navigationOptions: {
tabBarIcon: ({ tintColor }) => (
<Icon name="home" size={25} style={{ color: tintColor }} />
),
},
},
Explore: {
screen: explore,
navigationOptions: {
tabBarIcon: ({ tintColor }) => (
<Icon name="search" size={25} style={{ color: tintColor }} />
),
}
},
Profile: {
screen: profile,
navigationOptions: {
tabBarIcon: ({ tintColor }) => (
<Icon name="person" size={25} style={{ color: tintColor }} />
),
}
},
Create: {
screen: createCompetition,
navigationOptions: {
tabBarIcon: ({ tintColor }) => (
<Icon name="add" size={25} style={{ color: tintColor }} />
),
}
},
Payment: {
screen: payment,
navigationOptions: {
tabBarIcon: ({ tintColor }) => (
<Icon name="attach-money" size={25} style={{ color: tintColor }} />
),
title: 'Payment',
}
}
},
{
tabBarOptions: {
showIcon: true,
showLabel: false,
activeTintColor: 'black',
style: { backgroundColor: 'white', }
},
},
)
TabStack.navigationOptions = ({ navigation, screenProps }) => {
const childOptions = getActiveChildNavigationOptions(navigation, screenProps)
return {
title: childOptions.title,
headerLeft: childOptions.headerLeft,
headerRight: childOptions.headerRight,
}
}
So instead of using react navigation Header ive disabled it and used my own cutsom,
This is my Header.js :
import React, {Fragment, Component} from 'react';
import {View, Text, TouchableOpacity, Image, SafeAreaView} from 'react-native';
import {
widthPercentageToDP as wp,
heightPercentageToDP as hp,
} from 'react-native-responsive-screen';
import {headerStyles} from '../style/headerStyles';
export default class Header extends Component {
constructor(props) {
super(props);
this.state = {};
}
render() {
return (
<View
style={{
flexDirection: 'row',
paddingBottom: hp('3.125%'),
justifyContent: 'space-between',
alignItems: 'center',
}}>
<View style={{opacity: 0}}>
<Image source={require('../assets/images/crossIcon.png')} />
</View>
<View style={{flexShrink: 1}}>
<Text style={headerStyles.headerText}>{this.props.title}</Text>
</View>
<View style={{left: -20, paddingLeft: 10, marginLeft: 10}}>
<TouchableOpacity
style={headerStyles.imageView}
onPress={() => this.props.navigation.goBack()}>
<Image
style={{height: 15, width: 15}}
source={require('../assets/images/crossIcon.png')}
/>
</TouchableOpacity>
</View>
</View>
);
}
}
and you can import in any component like :
import Header from '../components/Header';
return(
<Header title={this.state.userName} navigation={this.props.navigation} />
)
With this you have enough power to do anything you want with header.
Hope it helps. feel free for doubts.
I assume you are using react-navigation, I suggest you set a navigation param in your component and then get the param in the navigationOptions.
after login do this:
navigation.setParams({ headerTitle: this.state.userName})
and then inside your navigationOptions where you already have navigation:
return { title: navigation.getParam('headerTitle') }

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"}
/>

the images are displayed in the emulator IOS but not in the real devices

in the emulator the images are shown perfectly but when compiling and sending to the store the images of the navigation bar are not displayed correctly
emulator:
the emulator the images are shown perfectly
device:
on devices the imeges are shown as shown below
code:
import React from "react";
import {createStackNavigator,DrawerActions} from 'react-navigation';
import {
TouchableOpacity,
View,
Image,
Dimensions,
Platform,
} from "react-native";
import DrawerScreen from './menu/DrawerScreen';
import Load from './screens/Load';
import CacheStore from 'react-native-cache-store';
import ListProduct from './screens/ListProduct';
import Points from './screens/Points';
import OffConnection from './screens/OffConnection';
import CategorieList from './screens/CategorieList';
const {width} = Dimensions.get('window');
let img = null;
setInterval(()=>{
CacheStore.get('image').then((value) => {
if(value === 1 ){
img = require('../public/images/carShopRed.png');
}else{
img = require('../public/images/carShop.png');
}
});
},100);
export const HomeStack = createStackNavigator({
screen_load:{
screen:Load,
navigationOptions:{
header:null,
drawerLockMode:'unlocked',
}
},
screen_Off:{
screen:OffConnection,
navigationOptions:{
header:null,
drawerLockMode:'unlocked',
}
},
screen_List: {
screen: ListProduct,
navigationOptions: ({navigation}) => ({
headerLeft:
<TouchableOpacity
onPress={() => {
navigation.navigate('Points');
}}
>
<Image source={require('../public/images/back3.png')}
style={{
width: 40,
height: 35,
resizeMode: 'contain',
marginBottom:3,
marginLeft:4
}}
/>
</TouchableOpacity>,
headerRight: "",
}),
},
screen_Category: {
screen: CategorieList,
navigationOptions: ({navigation}) => ({
headerLeft:
<TouchableOpacity
onPress={() => {
navigation.navigate('Products');
}}
>
<Image source={require('../public/images/back3.png')}
style={{
width: 40,
height: 35,
resizeMode: 'contain',
marginBottom:3,
marginLeft:4
}}
/>
</TouchableOpacity>,
headerRight: "",
}),
},
DrawerStack:{screen:DrawerScreen}
}, {
headerMode: 'float',
navigationOptions: ({navigation}) => (
{
headerStyle: {
backgroundColor:'rgb(70,70,70)',
},
headerTitleStyle: {
...Platform.select({
ios:{
width: width,
}
})
},
...Platform.select({
ios:{
title:
<Image source={require('../public/images/banner.png')}
style={{
width:width,
}}
/>,
}
}),
...Platform.select({
android:{
headerBackground: <Image source={require('../public/images/banner.png')}
style={{
width:width,
height:56,
}}
/>,
}
}),
headerTintColor: 'black',
headerLeftStyle:{
backgroundColor:'rgb(70,70,70)',
},
headerLeft: <View>
<TouchableOpacity
onPress={() => {
navigation.dispatch(DrawerActions.toggleDrawer());
}}
>
<Image source={require('../public/images/menu.png')}
style={{
width: 40,
height: 40,
resizeMode: 'center',
position:'relative',
marginLeft:10,
}}
/>
</TouchableOpacity>
</View>,
headerRight:<View>
<TouchableOpacity
onPress={()=>navigation.navigate('MyShopping')}
>
<Image source={img}
style={{
width: 30,
height: 30,
resizeMode: 'center',
position:'relative',
marginLeft:5,
}}
/>
</TouchableOpacity>
</View>
})
});
This is the code I use to create and put the navigation images