stacknavigator react native set title of top menu - react-native

i have a menu created like that :
import {createStackNavigator} from 'react-navigation';
const stackNav = createStackNavigator({
Main: {
screen: JourneeService,
navigationOptions: ({navigation}) => ({
headerTitle: <StackNavTitle title="Journée de Service " />,
headerStyle: {
backgroundColor: '#0088CE',
},
headerTintColor: '#fff',
headerTitleStyle: {
fontWeight: 'bold',
},
headerLeft: (
<TouchableOpacity
onPress={() => navigation.openDrawer()}
style={{width: '150%'}}>
<Icon name="ios-menu" size={35} color="#fff" style={{padding: 10}} />
</TouchableOpacity>
),
}),
}
with StackNavTitle :
class StackNavTitle extends Component {
constructor(props){
super(props);
}
render() {
return <Text style={{fontWeight: 'bold', color:'#fff', fontSize:20}}>
{this.props.title}.
</Text>;
}
}
on code i retrieve a title by callback i want to set title dynamically how can i do that ?
thanks in advance for your responses

You can provide a function to the header which accepts three parameters as per the docs and one of them contains the dynamic title. Here is an example I took from the docs and update with your header component
import {createStackNavigator} from 'react-navigation';
const stackNav = createStackNavigator({
Main: {
screen: JourneeService,
navigationOptions: ({navigation}) => ({
headerTitle: ({allowFontScaling, style, children})=> <StackNavTitle title={children.title} />,
headerStyle: {
backgroundColor: '#0088CE',
},
headerTintColor: '#fff',
headerTitleStyle: {
fontWeight: 'bold',
},
headerLeft: (
<TouchableOpacity
onPress={() => navigation.openDrawer()}
style={{width: '150%'}}>
<Icon name="ios-menu" size={35} color="#fff" style={{padding: 10}} />
</TouchableOpacity>
),
}),
}
You can find more info here https://reactnavigation.org/docs/4.x/stack-navigator#headertitle

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 drawer navigation screen header title and buttons

I am trying to add title and buttons to my home screen that is opened from drawer navigation. The following does not work(screen loads but no header) and i cant find documentation or sample on this that uses React Navigation v5. Did i miss something? This is the doc i am following.
<Drawer.Screen
name="Home"
component={HomeScreen}
title="Home Screen"
options={{
headerRight: () => (
<Button
onPress={() => alert("This is a button!")}
title="Info"
color="#fff"
/>
),
}}
/>
UPDATE: doing this on the screen didn't work as well.
const HomeScreen = (props) => {
return (
<Container>
<View style={{ flex: 1, alignItems: "center", justifyContent: "center" }}>
<Text>Home Screen2</Text>
</View>
</Container>
);
};
HomeScreen.navigationOptions = (props) => ({
title: "Home",
headerStyle: {
backgroundColor: "rgb(0, 145, 234)",
},
headerTintColor: "white",
headerTitleStyle: {
fontWeight: "bold",
color: "white",
},
});
export default HomeScreen;
From the option you put in, I guess you may want to add a Stack inside your Drawer navigation.
From the below example, when you go to the HomeStack, it will have a navigation bar and you can custom it using the option you put in.
(I also created a simple snack here: https://snack.expo.io/#gie3d/insane-ice-cream)
import React from 'react';
import { Text, View } from 'react-native';
import { NavigationContainer, DrawerActions } from '#react-navigation/native';
import { createStackNavigator } from '#react-navigation/stack';
import { createDrawerNavigator } from '#react-navigation/drawer';
import { Ionicons } from '#expo/vector-icons';
const Stack = createStackNavigator();
const Drawer = createDrawerNavigator();
const HomeStack = () => (
<Stack.Navigator>
<Stack.Screen name="Home" component={Home} options={({navigation}) => ({
title: "Home",
headerStyle: {
backgroundColor: "rgb(0, 145, 234)",
},
headerTintColor: "white",
headerTitleStyle: {
fontWeight: "bold",
color: "white",
},
headerLeft: () => (
<Ionicons
name={'md-menu'}
size={24}
style={{ marginLeft: 10 }}
onPress={() =>
navigation.dispatch(DrawerActions.toggleDrawer())
}
/>
),
})} />
</Stack.Navigator>
);
const Home = () => {
return (
<View>
<Text>This is Home</Text>
</View>
)}
export default () => {
return (
<NavigationContainer>
<Drawer.Navigator initialRouteName="HomeStack">
<Drawer.Screen name="HomeStack" component={HomeStack} />
<Drawer.Screen name="HomeNoStack" component={Home} />
</Drawer.Navigator>
</NavigationContainer>
);
}
You need to create the button on your screen too, like this.
import React from "react";
import {Text, View} from 'react-native';
export default class News extends React.Component {
static navigationOptions = ({navigation}) => {
return {
//headerLeft: --- PUT HERE YOU CUSTOM BUTTON (Use navigation.goBack() in onPress)
headerLeft:(<HeaderBackButton size={20} onPress={()=>{navigation.navigate('Home')}} color="#fff" tintColor="#fff"/>),
headerStyle: {
backgroundColor: 'rgb(0, 145, 234)',
},
headerTintColor: 'white',
headerTitleStyle:
{
fontWeight: 'bold',
color:'white' ,
//paddingTop:"2%",
},
}
}
render() {
return (
<View>
<Text> Here Leave the News!! </Text>
</View>
);
}
}

React Native navigation v5 navigate to another screen from header

I am currently following a tutorial that has an older version of navigator. I have update the code to use v5. When moving to a screen the navigation function is available as in
const CreateScreen = ({ navigation }) => {
I am then able to set the navigation with
onPress={() => navigation.navigate("home")
Please can someone show me how to expose the navigation function within the createStackNavigator function
import React from 'react';
import { Text, TouchableOpacity } from 'react-native';
import { NavigationContainer } from '#react-navigation/native';
import { createStackNavigator } from '#react-navigation/stack';
import IndexScreen from "./src/screens/IndexScreens"
import ShowScreen from "./src/screens/ShowScreen"
import CreateScreen from "./src/screens/CreateScreen"
import EditScreen from "./src/screens/EditScreen"
import { Provider} from "./src/context/BlogContext"
import { Feather } from '#expo/vector-icons';
import { EvilIcons } from '#expo/vector-icons';
const Stack = createStackNavigator();
const MyStack = () => (
<Stack.Navigator>
<Stack.Screen
name="Home"
component={IndexScreen}
options={{
title: 'Blog Posts',
headerTitleStyle: {
fontWeight: 'bold',
},
headerTitleAlign: "center",
headerRight: () => (
<TouchableOpacity style={{ marginRight: 15}} onPress={() => alert('Not working need to pass navigation function')}>
<Feather name="plus" size={30} />
</TouchableOpacity>
)
}}
/>
<Stack.Screen
name="Show"
component={ShowScreen}
options={{
title: 'Blog Post Detail',
headerTitleStyle: {
fontWeight: 'bold',
},
headerTitleAlign: "center",
headerRight: () => (
<TouchableOpacity style={{ marginRight: 15}} onPress={() => alert('Not working need to pass navigation function')}>
<EvilIcons name="pencil" size={35} />
</TouchableOpacity>
)
}}
/>
<Stack.Screen
name="Create"
component={CreateScreen}
options={{
title: 'Create A Blog Post',
headerTitleStyle: {
fontWeight: 'bold',
},
headerTitleAlign: "center"
}}
/>
<Stack.Screen
name="Edit"
component={EditScreen}
options={{
title: 'Edit Blog Post',
headerTitleStyle: {
fontWeight: 'bold',
},
headerTitleAlign: "center"
}}
/>
</Stack.Navigator>
);
const App = () => (
<NavigationContainer>
<MyStack />
</NavigationContainer>
);
export default () => {
return <Provider>
<App />
</Provider>
}
change your options
options={{
title: 'Blog Posts',
headerTitleStyle: {
fontWeight: 'bold',
},
headerTitleAlign: "center",
headerRight: () => (
<TouchableOpacity style={{ marginRight: 15}} onPress={() => alert('Not working need to pass navigation function')}>
<Feather name="plus" size={30} />
</TouchableOpacity>
)
}}
to
options={({ navigation }) => (
{
title: 'Blog Posts',
headerTitleStyle: {
fontWeight: 'bold',
},
headerTitleAlign: "center",
headerRight: () => (
<TouchableOpacity style={{ marginRight: 15}} onPress={() => navigation.navigate("Show")}>
<Feather name="plus" size={30} />
</TouchableOpacity>
)
})}
Do the same with the options in Show stack screen.
Hope this helps!
Replace navigation.navigate("Show") with navigation.navigate("Create")

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: how to style a big middle button in tab navigation?

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>