I'm unable to move between the nested stacks.
I've traced a route from the RootStackScreen back to all the different screens I want to display.
No issues at all with push, pop or back around screens in the same stack but I'm unable to move between them when one is initially displayed.
Does useStates block me from navigation between stacks or is there something else which I'm missing?!
Thanks in advance.
import React, {useState, useEffect} from 'react';
import { NavigationContainer } from '#react-navigation/native'
import { createStackNavigator } from '#react-navigation/stack'
import { createBottomTabNavigator } from '#react-navigation/bottom-tabs'
import Icon from 'react-native-vector-icons/Feather'
import firebase from 'firebase'
// Screens
// Modal
import Modal from '../screens/modal';
// Onboarding
import OnboardingOne from '../screens/onboardingOne'
import OnboardingTwo from '../screens/onboardingTwo'
import OnboardingThree from '../screens/onboardingThree'
import OnboardingFour from '../screens/onboardingFour'
import SignIn from '../screens/signIn'
import CreateUser from '../screens/createUser'
import OnboardingUser from '../screens/onboardingUser'
// Loading
import Loading from '../screens/loading'
// Tabs
import HomeScreen from '../screens/home'
import AboutScreen from '../screens/about'
import OrganisationScreen from '../screens/organisation'
// Profile
import ProfileScreen from '../screens/profile'
import SignOutScreen from '../screens/signOut'
const OnboardingStack = createStackNavigator();
const OnboardingStackScreen = () => (
<OnboardingStack.Navigator
headerMode='screen'
screenOptions={{animationEnabled: true}}
initialRouteName="OnboardingUser" >
<OnboardingStack.Screen
name="OnboardingOne"
component={OnboardingOne}
options={{
headerTitle: 'Onboarding One',
}}
/>
<OnboardingStack.Screen
name="OnboardingTwo"
component={OnboardingTwo}
options={{
headerTitle: 'OnboardingTwo'
}}
/>
<OnboardingStack.Screen
name="OnboardingThree"
component={OnboardingThree}
options={{
headerTitle: 'OnboardingThree'
}}
/>
<OnboardingStack.Screen
name="OnboardingFour"
component={OnboardingFour}
options={{
headerTitle: 'Onboarding Four'
}}
/>
<OnboardingStack.Screen
name="SignIn"
component={SignIn}
options={{
headerTitle: 'Sign in'
}}
/>
<OnboardingStack.Screen
name="CreateUser"
component={CreateUser}
options={{
headerTitle: 'Create User'
}}
/>
<OnboardingStack.Screen
name="OnboardingUser"
component={OnboardingUser}
options={{
headerTitle: 'Onboarding User',
}}
/>
</OnboardingStack.Navigator>
);
const ProfileStack = createStackNavigator();
const ProfileStackStackScreen = () => (
<ProfileStack.Navigator headerMode='screen' screenOptions={{animationEnabled: true}} >
<ProfileStack.Screen
name="Profile"
component={ProfileScreen}
options={{
headerTitle: 'Profile Screen',
}}
/>
<ProfileStack.Screen
name="SignOut"
component={SignOutScreen}
options={{
headerTitle: 'Sign Out',
}}
/>
</ProfileStack.Navigator>
);
const AppTabs = createBottomTabNavigator()
const AppTabsScreen = () => (
<AppTabs.Navigator
initialRouteName="Home"
tabBarOptions={{
activeTintColor: 'orange',
inactiveTintColor: 'gray',
}}>
<AppTabs.Screen name="Home" component={HomeScreen} options={{
tabBarLabel: "Hem",
tabBarIcon: props => <Icon name="home"
size={props.size}
color={props.color}/>
}}/>
<AppTabs.Screen name="About" component={AboutScreen} options={{
tabBarLabel: "Om",
tabBarIcon: props => (
<Icon name="feather"
size={props.size}
color={props.color}/>)
}}/>
<AppTabs.Screen name="Organisation" component={OrganisationScreen} options={{
tabBarLabel: "Organisationer",
tabBarIcon: props => <Icon name="list"
size={props.size}
color={props.color}/>
}}/>
<AppTabs.Screen name="Profile" component={ProfileStackStackScreen} options={{
tabBarLabel: "Profile",
tabBarIcon: props => <Icon name="user"
size={props.size}
color={props.color}/>
}}/>
</AppTabs.Navigator >
);
const RootStack = createStackNavigator();
const RootStackScreen = () => {
const [isLoading, setIsLoading] = useState(true)
const [isLoggedIn, setLoggedIn] = useState(false)
// Do we have a user?
var user = firebase.auth().currentUser;
// Set wait time for loading screen
useEffect(() => {
setIsLoading(!isLoading)
}, [])
return (
<RootStack.Navigator
headerMode="none"
screenOptions={{ animationEnabled: false }}
mode="modal">
{isLoading ? (
<RootStack.Screen name="Loading" component={Loading} />
) : !isLoggedIn ? (
<RootStack.Screen name="AppDrawerScreen" component={OnboardingStackScreen} />
) : (
<RootStack.Screen name="TabHomeScreen" component={AppTabsScreen} />
)}
<RootStack.Screen
name="Modal"
component={ Modal }
options={{ animationEnabled: true }}
/>
<RootStack.Screen
name="Alert"
component={ Modal }
options={{
animationEnabled: true,
cardStyle: { backgroundColor: 'rgba(0,0,0,0.15)'},
cardOverlayEnabled: true,
cardStyleInterpolator: ({current: { progress }}) => {
return{
cardStyle: {
opacity: progress.interpolate({
inputRange: [0, 0.5, 0.9, 1],
outputRange: [0, 0.25, 0.7, 1],
})
},
overlayStyle: {
opacity: progress.interpolate({
inputRange: [0, 1],
outputRange: [0, 0.5],
extrapolate: 'clamp',
})
}
}
}
}}
/>
</RootStack.Navigator>
);
};
export default () => {
return (
<NavigationContainer>
<RootStackScreen/>
</NavigationContainer>
)
}
Apparently useState (isLoading & isLoggedIn) prevents me from navigating between these components. Simply fixed my problem by adding:
<RootStack.Screen name="BottomTabNavigation" component={AppTabsScreen}/>
Placed under the the hooks that determine the initial screen of the app and now everything works as intended and navigation.navigate("BottomTabNavigation") now displays the bottomTabNavigator.
Related
I don't seem to have any problems using setState in other pages of my project but in the app.js it just does not work? I am very new to react native.
I am calling the function 'handleacount' from another page and it gets the data and I just want to update the 'Acount'
The state is updating because it alerts but it does not update when it has already been rendered? Am I missing something?
The page App.js is :
import 'react-native-gesture-handler';
import React, { useState, Component } from "react";
import { MaterialCommunityIcons } from '#expo/vector-icons';
import { NavigationContainer } from '#react-navigation/native';
import { createStackNavigator } from '#react-navigation/stack';
import { createBottomTabNavigator } from '#react-navigation/bottom-tabs';
import Constants from 'expo-constants';
import IconBadge from 'react-native-icon-badge';
import { Text, View, StyleSheet } from 'react-native';
import HomeScreen from './pages/HomeScreen';
import SearchScreen from './pages/SearchScreen';
import SettingsScreen from './pages/SettingsScreen';
import MapScreen from './pages/MapScreen';
import NotificationsScreen from './pages/NotificationsScreen';
import { ListItem, Avatar, Badge, Icon, withBadge } from 'react-native-elements'
const Stack = createStackNavigator();
const Tab = createBottomTabNavigator();
const MessagesIcon = ({ tintColor }) => (
<Icon
type="MaterialCommunityIcons"
name="checkcircle"
size={24}
color={tintColor}
/>
);
function HomeStack() {
return (
<Stack.Navigator>
<Stack.Screen
name="Home"
component={HomeScreen}
options={{ title: 'Home Page', headerShown: false }}
/>
<Stack.Screen
name="Search"
component={SearchScreen}
options={{ headerShown: false }}
/>
<Stack.Screen
name="Notifications"
component={NotificationsScreen}
options={{ headerShown: false }}
/>
<Stack.Screen
name="Map"
component={MapScreen}
changeoptions={{ headerShown: false }}
/>
<Stack.Screen
name="Settings"
component={SettingsScreen}
changeoptions={{ headerShown: false }}
/>
</Stack.Navigator>
);
}
function SettingsStack() {
return (
<Stack.Navigator>
<Stack.Screen
name="Settings"
component={SettingsScreen}
options={{ headerShown: false }}
/>
</Stack.Navigator>
);
}
function App() {
function App() {
const [Acount, setAcount] = useState(0)
this.state = {
Acount: 2
};
handleacount = (data) => {
this.state = {
Acount: 9
};
alert(this.state.acount)
}
return (
<NavigationContainer>
<Tab.Navigator
tabBarOptions={{
activeTintColor: '#b08cf3',
inactiveTintColor: 'black',
}}>
<Tab.Screen
name="HomeStack"
component={HomeScreen}
options={{
tabBarLabel: 'Home',
tabBarIcon: ({ color, size }) => (
<MaterialCommunityIcons name="home" color={color} size={30} />
),
}}
/>
<Tab.Screen
name="SearchStack"
component={SearchScreen}
options={{
tabBarLabel: 'Search',
tabBarIcon: ({ color, size }) => (
<MaterialCommunityIcons
name="account-search"
color={color}
size={30}
/>
),
}}
/>
<Tab.Screen
name="NotificationsStack"
component={NotificationsScreen}
options={{
tabBarBadge: 5,
tabBarLabel: 'Notifications',
tabBarIcon: ({ color, size }) => (
<MaterialCommunityIcons name="bell" color={color} size={30} />
),
}}
/>
<Tab.Screen
name="MapStack"
component={MapScreen}
options={{
tabBarLabel: 'Map',
tabBarIcon: ({ focused, color, size }) => {
return (
<View>
<MaterialCommunityIcons name="map-marker" size={30} color='rgb(68,68,68)' style={{ marginTop:0 }}/>
<View style={{position:'absolute', bottom:32, left:-38 }}>
<IconBadge
MainElement={
<View>
</View>
}
BadgeElement={
// here your text in badge icon
<Text style={{fontWeight: 900,fontFamily: "sans-serif-medium",
fontSize: 14,color:'#FFFFFF', Top:10 }}>{ this.state.acount }</Text>
}
IconBadgeStyle={
{width:20,
height:20,
borderWidth: 2,
borderColor: "#b5b5b5",
backgroundColor: '#ff8a8a'}
}
/></View>
</View>
);
},
}}
/>
<Tab.Screen
name="SettingsStack"
component={SettingsScreen}
options={{
tabBarLabel: 'Account',
tabBarIcon: ({ color, size }) => (
<MaterialCommunityIcons
name="account"
color={color}
size={30}
/>
),
}}
/>
</Tab.Navigator>
</NavigationContainer>
);
}
const styles = StyleSheet.create({
container: {
flex: 1
}
});
export default App;
State belongs to the component so you should move it inside the App component like this
function App() {
const [account, setAccount] = useState(0)
...
}
But how do you call the setAccount from another page you wonder and there you need to have a look into React Context or Redux.
Context: https://reactjs.org/docs/context.html
Redux: https://redux.js.org/
I sorted it by place this in another page:
<Button
onPress={() => {increment(2)}} title="Click Me"
/>
Then in the function App I added
// State: a counter value
const [counter, setCounter] = useState(0)
increment = (data) => {
setCounter(data)
}
Not entirely sure how or why this works though?
I am having a Bottom Navigation with 2 Tabs so far (Home & Messages). When inside Messages I can press on a User to get navigated to the ChatScreen which is a Screen from the Stack Navigator. In that ChatScreen I want to hide the BottomTab. I know that it is possible to hide it by adding tabBarStyle: { display: "none" } to the <Tab.Screen /> but this doesn't work for the ChatScreen since it is not a Tab.Screen
import * as React from 'react';
import {View, Text} from 'react-native';
import {NavigationContainer, StackActions} from '#react-navigation/native';
import {createNativeStackNavigator} from '#react-navigation/native-stack';
import Home from './app/Screens/Home';
import CommentSection from './app/Screens/CommentSection';
import MessageScreen from './app/Screens/MessageScreen';
import ChatScreen from './app/Screens/ChatScreen';
import NavigationHeader from './app/global/headers/NavigationHeader';
import SendOffer from './app/Screens/SendOffer';
import {createBottomTabNavigator} from '#react-navigation/bottom-tabs';
import Icon from 'react-native-vector-icons/MaterialIcons';
import ChatScreenHeader from './app/Screens/ChatScreen/ChatScreenHeader';
const HomeStack = createNativeStackNavigator();
const HomeStackScreen = () => {
return (
<HomeStack.Navigator initialRouteName="Home">
<HomeStack.Screen
name="HomeScreen"
component={Home}
options={{
// header: AppBar,
headerShown: false,
}}
/>
<HomeStack.Screen
name="CommentSection"
component={CommentSection}
options={{
headerTitle: 'Home',
// animationTypeForReplace: 'push',
animation: 'slide_from_bottom',
}}
/>
<HomeStack.Screen
name="SendOffer"
component={SendOffer}
options={{
headerTitle: 'Home',
animation: 'slide_from_right',
}}
/>
<HomeStack.Screen
name="ChatScreen"
component={ChatScreen} //HIDE BottomTab INSIDE THIS COMPONENT
options={{
headerTitle: 'Messages',
animation: 'slide_from_right',
}}
/>
</HomeStack.Navigator>
);
};
const MessageStack = createNativeStackNavigator();
const MessageStackScreen = () => {
return (
<MessageStack.Navigator>
<MessageStack.Screen
name="MessageScreen"
component={MessageScreen}
options={{
headerTitle: 'Messages',
animation: 'slide_from_right',
}}
/>
<MessageStack.Screen
name="ChatScreen"
component={ChatScreen} //HIDE BottomTab INSIDE THIS COMPONENT
options={{
headerTitle: 'Messages',
headerShown: false,
animation: 'slide_from_right',
}}
/>
</MessageStack.Navigator>
);
};
const Tab = createBottomTabNavigator();
export default function App() {
return (
<NavigationContainer>
<Tab.Navigator initialRouteName="Messages">
<Tab.Screen
name="Home"
component={HomeStackScreen}
options={{
headerShown: false,
tabBarLabel: 'Home',
tabBarIcon: ({ color }) => (
<Icon name="home" color={color} size={26} />
),
}}
/>
<Tab.Screen
name="Messages"
component={MessageStackScreen}
options={{
headerShown: false,
tabBarLabel: 'Messages',
tabBarIcon: ({ color }) => (
<Icon name="chat" color={color} size={26} />
),
// tabBarStyle: { display: "none" }
}}
/>
</Tab.Navigator>
</NavigationContainer>
);
}
Used solution by #Escaper from another question
useEffect(() => {
navigation.getParent()?.setOptions({ tabBarStyle: { display: "none" }});
return () => navigation.getParent()?.setOptions({ tabBarStyle: undefined });
}, [navigation]);
You could use createNavigationContainerRef to check the current route name via the getCurrentRoute() function inside the component that creates the BottomTabNavigator and then use tabBarStyle conditionally as you have suggested.
This could look as follows.
import { createNavigationContainerRef } from "#react-navigation/native"
const ref = createNavigationContainerRef();
const Tab = createBottomTabNavigator();
export default function App() {
const hide = "ChatScreen" === ref.current?.getCurrentRoute()?.name
return (
<NavigationContainer>
<Tab.Navigator initialRouteName="Messages">
<Tab.Screen
name="Home"
component={HomeStackScreen}
options={{
headerShown: false,
tabBarLabel: 'Home',
tabBarIcon: ({ color }) => (
<Icon name="home" color={color} size={26} />
),
}}
/>
<Tab.Screen
name="Messages"
component={MessageStackScreen}
options={{
headerShown: false,
tabBarLabel: 'Messages',
tabBarIcon: ({ color }) => (
<Icon name="chat" color={color} size={26} />
),
tabBarStyle: { display: hide ? "none" : "flex" }
}}
/>
</Tab.Navigator>
</NavigationContainer>
);
}
I am trying to test my application and I cannot get the navigation to work.
When I test my navigation to go to bottomtabnavigator I have the error:
Error: Element type is invalid: expected a string (for built-in
components) or a class/function (for composite components) but got:
object.
Is it just a syntax error?
Thank you for any help.
App.js
import React, { useState, useEffect } from 'react';
import AppContext from './AppContext';
import {NavigationContainer} from '#react-navigation/native';
import { createStackNavigator } from '#react-navigation/stack';
import Authentication from './Screens/Authentication';
import Login from './Screens/Login';
import Register from './Screens/Register';
const AuthenticationStack = createStackNavigator();
import Splash from './src/components/Splash';
import BottomTabNavigator from './Navigation/StackNavigator';
export default function App() {
const [user, setUser] = useState({ loggedIn: false });
const state = { user, setUser };
const [loading, setLoading] = useState(true);
useEffect(() => {
setTimeout(() => setLoading(false), 2000);
}, []);
if (loading) {
return <Splash />;
}
return (
<AppContext.Provider value={state}>
<NavigationContainer>
{user.loggedIn ? (
<AuthenticationStack.Navigator>
<AuthenticationStack.Screen name="Authentication" component={Authentication} />
<AuthenticationStack.Screen name="Login" component={Login} />
<AuthenticationStack.Screen name="Register" component={Register} />
</AuthenticationStack.Navigator>
) : (
<BottomTabNavigator />
)}
</NavigationContainer>
</AppContext.Provider>
);
}
StackNavigator:
import React from 'react';
import { createStackNavigator} from "#react-navigation/stack";
import { createBottomTabNavigator } from "#react-navigation/bottom-tabs";
import Authentication from '../Screens/Authentication';
import Activities from '../Screens/Activities';
import Login from '../Screens/Login';
import Register from '../Screens/Register';
import Tools from '../Screens/Tools';
import Dashboard from '../Screens/Dashboard';
import Orders from '../Screens/Orders';
import About from '../Screens/About';
import Terms from '../Screens/Terms';
import Completed from '../Screens/Orders/Completed';
import Current from '../Screens/Orders/Current';
import Settings from '../Screens/Settings';
import Contact from '../Screens/Contact';
import Scan from '../Screens/Tools/Scan';
import Products from '../Screens/Tools/Products';
import Tickets from '../Screens/Tools/Tickets';
import Welcome from '../Screens/Welcome';
import i18n from '../src/i18n';
const Stack = createStackNavigator();
const Tab = createBottomTabNavigator();
const screenOptionStyle = {
headerStyle: {
backgroundColor: "#F78400",
},
headerTintColor: "white",
headerBackTitle: "Back",
backgroundColor:'#f7f6f6'
};
const MainStackNavigator = () => {
return (
<Stack.Navigator screenOptions={screenOptionStyle}>
<Stack.Screen name = 'Orders' component = {Orders} options={{ title: i18n.t("orders.title") }}/>
<Stack.Screen name = 'Authentication' component = {Authentication} options={{ title: i18n.t("authentication.title") }}/>
<Stack.Screen name = 'Activities' component = {Activities} options={{ title: i18n.t("activities.title") }}/>
<Stack.Screen name = 'Contact' component = {Contact} options={{ title: i18n.t("contact.title") }}/>
<Stack.Screen name = 'Login' component = {Login} options={{ title: i18n.t("login.title") }}/>
<Stack.Screen name = 'Register' component = {Register} options={{ title: i18n.t("register.title") }}/>
<Stack.Screen name = 'Tools' component = {Tools} options={{ title: i18n.t("tools.title") }}/>
<Stack.Screen name = 'Scan' component = {Scan} options={{ title: i18n.t("scan.title") }}/>
<Stack.Screen name = 'Current' component = {Current} options={{ title: i18n.t("current.title") }}/>
<Stack.Screen name = 'Completed' component = {Completed} options={{ title: i18n.t("completed.title") }}/>
<Stack.Screen name = 'Products' component = {Products} options={{ title: i18n.t("products.title") }}/>
<Stack.Screen name = 'Terms' component = {Terms} options={{ title: i18n.t("terms.title") }}/>
<Stack.Screen name = 'About' component = {About} options={{ title: i18n.t("about.title") }}/>
<Stack.Screen name = 'Tickets' component = {Tickets} options={{ title: i18n.t("tickets.title") }}/>
<Stack.Screen name = 'Dashboard' component = {Dashboard} options={{ title: i18n.t("dashboard.title") }}/>
<Stack.Screen name = 'Settings' component = {Settings} options={{ title: i18n.t("settings.title") }}/>
<Stack.Screen name = 'Welcome' component = {Welcome} options={{ title: i18n.t("welcome.title") }}/>
</Stack.Navigator>
);
}
const BottomTabNavigator = () => {
return (
<Tab.Navigator tabBarOptions={{activeTintColor: 'black',
labelStyle: {fontSize: 12, color: 'white'},
style: {backgroundColor: '#F78400'},
}}>
<Tab.Screen
name={i18n.t("orders.title")}
component={MainStackNavigator}
options={{
tabBarIcon: ({ focused, horizontal, tintColor }) => {
return (
<Image
source={require("../assets/images/orders.png")}
style={styles.icon}
/>
);
}
}}
/>
<Tab.Screen
name={i18n.t("dashboard.title")}
component={Dashboard}
options={{
tabBarIcon: ({ focused, horizontal, tintColor }) => {
return (
<Image
source={require("../assets/images/dashboard.png")}
style={styles.icon}
/>
);
}
}}
/>
<Tab.Screen
name={i18n.t("tools.title")}
component={Tools}
options={{
tabBarIcon: ({ focused, horizontal, tintColor }) => {
return (
<Image
source={require("../assets/images/tools.png")}
style={styles.icon}
/>
);
}
}}
/>
<Tab.Screen
name={i18n.t("settings.title")}
component={SettingsStackNavigator}
options={{
tabBarIcon: ({ focused, horizontal, tintColor }) => {
return (
<Image
source={require("../assets/images/settings.png")}
style={styles.icon}
/>
);
}
}}
/>
</Tab.Navigator>
);
};
export default { MainStackNavigator, BottomTabNavigator };
this error comes because i was using #react-navigation/native and #react-navigation/bottom-tabs of different version
You are exporting a single object, you can do like beloe
export const BottomTabNavigator = () => {
to
import {BottomTabNavigator} from './Navigation/StackNavigator';
Use the same way to export the MainStackNavigator as well
To build off of Raghuvansh's answer, if you run
npm list
You should see all of your current npm packages for the local project.
In my case, my #react-navigation/native package was version 5.8.10, and my #react-navigation/bottom-tabs package was 6.0.5.
I was able to easily fix this by running npm update, which put them both onto the same package version.
I don't know how to get the navigation property to switch to child screens.
I thought my code was good but a priori it doesn't work ... When I put navigation container encompassing my tab.navigator, the tab navigator screens accepted navigation, but not the others, now I changed and I have included the screens of the stack.navigator in my NavigationContainer but it does not work either ... I have the error:
Couldn't register the navigator. Have you wrapped your app with
'NavigationContainer'?
I'm lost, Can somebody help me ?
Thanks a lot...
import React from 'react';
import { Image } from 'react-native';
import { createBottomTabNavigator } from '#react-navigation/bottom-tabs';
import { createStackNavigator} from "#react-navigation/stack";
import { NavigationContainer } from '#react-navigation/native';
import Authentication from '../../Screens/Authentication';
import Activities from '../../Screens/Activities';
import Login from '../../Screens/Authentication/Login';
import Register from '../../Screens/Authentication/Register';
import Tools from '../../Screens/Tools';
import Dashboard from '../../Screens/Dashboard';
import Orders from '../../Screens/Orders';
import Completed from '../../Screens/Orders/Completed';
import Current from '../../Screens/Orders/Current';
import Details from '../../Screens/Orders/Details';
import Settings from '../../Screens/Settings';
import Scan from '../../Screens/Tools/Scan';
import Products from '../../Screens/Tools/Products';
import Tickets from '../../Screens/Tools/Tickets';
import Welcome from '../../Screens/Welcome';
import i18n from '../../src/i18n';
import styles from '../../assets/styles';
const Tab = createBottomTabNavigator();
const Stack = createStackNavigator();
export default function ScreenNavigator() {
return(
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen name = 'Orders' component = {Orders} options={{ title: i18n.t("orders.title") }}/>
<Stack.Screen name = 'Authentication' component = {Authentication} options={{ title: i18n.t("authentication.title") }}/>
<Stack.Screen name = 'Activities' component = {Activities} options={{ title: i18n.t("activities.title") }}/>
<Stack.Screen name = 'Login' component = {Login} options={{ title: i18n.t("login.title") }}/>
<Stack.Screen name = 'Register' component = {Register} options={{ title: i18n.t("register.title") }}/>
<Stack.Screen name = 'Tools' component = {Tools} options={{ title: i18n.t("tools.title") }}/>
<Stack.Screen name = 'Scan' component = {Scan} options={{ title: i18n.t("scan.title") }}/>
<Stack.Screen name = 'Current' component = {Current} options={{ title: i18n.t("current.title") }}/>
<Stack.Screen name = 'Completed' component = {Completed} options={{ title: i18n.t("completed.title") }}/>
<Stack.Screen name = 'Details' component = {Details} options={{ title: i18n.t("details.title") }}/>
<Stack.Screen name = 'Products' component = {Products} options={{ title: i18n.t("products.title") }}/>
<Stack.Screen name = 'Tickets' component = {Tickets} options={{ title: i18n.t("tickets.title") }}/>
<Stack.Screen name = 'Dashboard' component = {Dashboard} options={{ title: i18n.t("dashboard.title") }}/>
<Stack.Screen name = 'Settings' component = {Settings} options={{ title: i18n.t("settings.title") }}/>
<Stack.Screen name = 'Welcome' component = {Welcome} options={{ title: i18n.t("welcome.title") }}/>
</Stack.Navigator>
</NavigationContainer>
)
}
export function AppNavigation() {
return (
<Tab.Navigator tabBarOptions={{activeTintColor: 'black',
labelStyle: {fontSize: 12, color: 'white'},
style: {backgroundColor: '#F78400'},
}}>
<Tab.Screen
name={i18n.t("orders.title")}
component={ScreenNavigator}
options={{
tabBarIcon: ({ focused, horizontal, tintColor }) => {
return (
<Image
source={require("../../assets/images/orders.png")}
style={styles.icon}
/>
);
}
}}
/>
<Tab.Screen
name={i18n.t("dashboard.title")}
component={Dashboard}
options={{
tabBarIcon: ({ focused, horizontal, tintColor }) => {
return (
<Image
source={require("../../assets/images/dashboard.png")}
style={styles.icon}
/>
);
}
}}
/>
<Tab.Screen
name={i18n.t("tools.title")}
component={Tools}
options={{
tabBarIcon: ({ focused, horizontal, tintColor }) => {
return (
<Image
source={require("../../assets/images/tools.png")}
style={styles.icon}
/>
);
}
}}
/>
<Tab.Screen
name={i18n.t("settings.title")}
component={Settings}
options={{
tabBarIcon: ({ focused, horizontal, tintColor }) => {
return (
<Image
source={require("../../assets/images/settings.png")}
style={styles.icon}
/>
);
}
}}
/>
</Tab.Navigator>
)
}
App.js:
import React from "react";
import {
View,
Text,
StatusBar,
Image,
ActivityIndicator,
} from "react-native";
import {
retrieveAppLang,
userSessionActive
} from "./src/common/Preferences";
import i18n from "./src/i18n";
import styles from './assets/styles';
import Authentication from './Screens/Authentication'
import { ScreenNavigator, AppNavigation } from './src/Navigation';
export default class App extends React.Component {
constructor(props) {
super(props);
this.state = {
isFirstConnection: true,
status: 0,
};
}
async UNSAFE_componentWillMount() {
let lang = await retrieveAppLang();
let isConnected = await userSessionActive();
if (lang.length == 2) {
i18n.changeLanguage(lang);
}
if (isConnected === true && this.props && this.props.navigation) {
this.props.navigation.navigate("ScreenNavigator");
}
}
async componentDidMount() {
const data = await this.performTimeConsumingTask();
if (data !== null) {
this.setState({
isFirstConnection: false,
status: 1,
});
}
}
async performTimeConsumingTask() {
return new Promise((resolve) =>
setTimeout(() => {
resolve("result");
}, 750)
);
};
render() {
if (this.state.status == 1) {
if (this.state.isFirstConnection ) {
return <Authentication />;
} else {
return <AppNavigation />
}
}
return (
<View style={styles.container}>
<StatusBar hidden={true} />
<View style={styles.subContainer}>
<Image
style={styles.logo}
source={require("./assets/images/logo.png")}
/>
<ActivityIndicator size="large" color="#F78400" />
<Text>{i18n.t("app.loading") + "..."}</Text>
</View>
</View>
);
}
}
I am facing some problems with FontAwesome icons. (I have tried with MaterialCommunityIcons and normal Icons, but the same result)
They don't appear in the bottom Tab navigation, as also under Social networks. (The other icons are from react-native-settings-page)
Here is a screenshot:
Here is the TabNavigation:
import React from 'react';
import { createBottomTabNavigator } from "#react-navigation/bottom-tabs";
import { MaterialCommunityIcons } from '#expo/vector-icons';
import HomeNavigator from '../navigation/HomeNavigator';
import NewsNavigator from '../navigation/NewsNavigator';
import settings from '../config/settings';
import i18n from "../locales/i18n";
const Tab = createBottomTabNavigator();
function TabNavigation(props) {
return (
<Tab.Navigator
screenOptions={({ route }) => ({
tabBarIcon: ({ color }) => {
let iconName;
if (route.name === 'Home') {
iconName = 'home';
}
else if (route.name === 'News') {
iconName = 'newspaper';
}
// You can return any component that you like here!
return <MaterialCommunityIcons color={color} icon={iconName} size={25} />;
},
})}
tabBarOptions={{
activeTintColor: settings.colors.activecolor,
inactiveTintColor: settings.colors.fontcolor,
activeBackgroundColor: settings.colors.navigation,
inactiveBackgroundColor:settings.colors.navigation,
}}
>
<Tab.Screen name="Home" options={{ tabBarLabel: i18n.t('navigation.home') }} component={HomeNavigator} />
<Tab.Screen name="News" options={{ tabBarLabel: i18n.t('navigation.news') }} component={NewsNavigator} />
</Tab.Navigator>
);
}
export default TabNavigation;
Here are my colors, but I think they are not making the problem:
export default {
colors: {
navigation: '#000',
bgcolor: "#000",
fontcolor: '#fff',
activecolor: '#dd163b',
settingsbackground: '#c3c3c3',
},
languages: {
}
}
You are using tabBarIcon as part of the navigator this should be passed to the screen level options like below
<Tab.Screen
name="Home"
options={{
tabBarLabel: i18n.t('navigation.home'),
tabBarIcon: ({ color }) => (
<MaterialCommunityIcons name="home" color={color} size={20} />
),
}}
component={HomeNavigator}
/>
<Tab.Screen
name="News"
options={{
tabBarLabel: i18n.t('navigation.news'),
tabBarIcon: ({ color }) => (
<MaterialCommunityIcons name="newspaper" color={color} size={20} />
),
}}
component={NewsNavigator}
/>