react native unable to hide my drawer menu behind my screens - react-native

I tried to use transition for opening and closing my drawer but there is a problem which is my drawer is over my screen which is not satisfying. I want my screens become over my drawer.
you can clearly see below (right one is desired and left is what I achieved so far):
I tried to use zIndex on my styles but no luck. here is my navigation code:
const IntroStack = createStackNavigator();
const IntroNavigation = () => {
return (
<NavigationContainer>
<IntroStack.Navigator>
<IntroStack.Screen name='intro' component={Intro} options={{ headerShown: false }} />
<IntroStack.Screen name='login' component={Login} options={{ headerShown: false }} />
<IntroStack.Screen name='createAccount' component={CreateAccount} options={{ headerShown: false }} />
<IntroStack.Screen name='forgotPassword' component={ForgotPassword} options={{ headerShown: false }} />
<IntroStack.Screen name='enterCode' component={EnterCode} options={{ headerShown: false }} />
<IntroStack.Screen name='changePassword' component={ChangePassword} options={{ headerShown: false }} />
<IntroStack.Screen name='home' component={DrawerNavigation} options={{ headerShown: false }} />
<IntroStack.Screen name='notfications' component={Notifications} options={{ headerShown: true }} />
</IntroStack.Navigator>
</NavigationContainer>
)
}
const Drawer = createDrawerNavigator();
const DrawerNavigation = () => {
const [progress, setProgress] = useState(new Animated.Value(0));
const rotate = Animated.interpolate(progress, {
inputRange: [0, 1],
outputRange: [0, -0.28],
});
const scale = Animated.interpolate(progress, {
inputRange: [0, 1],
outputRange: [1, 0.8],
});
const screenStyles = { transform: [{ rotate, scale }] }
return (
<Drawer.Navigator drawerType='slide' drawerStyle={{width: 300}} overlayColor='transparent' sceneContainerStyle={{backgroundColor: '#3170FF'}} drawerContent={
(props) => {
setProgress(props.progress);
return <DrawerContent {...props} />
}}>
<Drawer.Screen name="Home">
{(props) => <TabNavigation style={screenStyles} />}
</Drawer.Screen>
</Drawer.Navigator>
);
}
const Tab = createBottomTabNavigator();
const TabNavigation = (props) => {
return (
<Animated.View style={[{ flex: 1 }, props.style]}>
<Tab.Navigator tabBarOptions={{
style: {
borderTopLeftRadius: 23,
borderTopRightRadius: 23,
height: 70,
alignItems: 'center',
}
}} >
<Tab.Screen name="Home" component={Home} options={{
tabBarButton: (props) => <TabComponent label='home' {...props} />,
}} />
<Tab.Screen name="WorldTour" component={WorldTour} options={{
tabBarButton: (props) => <TabComponent label='earth' {...props} />,
}} />
<Tab.Screen name="Outlet" component={Outlet} options={{
tabBarButton: (props) => <TabComponent label='compass' {...props} />,
}} />
<Tab.Screen name="ChrisLeong" component={ChrisLeong} options={{
tabBarButton: (props) => <TabComponent label='crown' {...props} />,
}} />
<Tab.Screen name="OurTherapists" component={OurTherapists} options={{
tabBarButton: (props) => <TabComponent label='joint' {...props} />,
}} />
</Tab.Navigator>
</Animated.View>
);
}
export default IntroNavigation;
how can I fix this issue? thanks in advance!

import React from 'react';
import {View} from 'react-native';
import {useDrawerProgress} from '#react-navigation/drawer';
import Animated, {interpolate, useAnimatedStyle} from 'react-native-reanimated';
import {AppStyle} from '../../theme';
export default function DrawerScreen({children, style}) {
const drawerProgress = useDrawerProgress();
const viewStyles = useAnimatedStyle(() => {
const scale = interpolate(drawerProgress.value, [0, 1], [1, 0.75]);
const translateX = interpolate(drawerProgress.value, [0, 1], [0, 60]);
const borderRadius = interpolate(drawerProgress.value, [0, 1], [1, 10]);
const rotate = interpolate(drawerProgress.value, [0, 1], [0, -12]);
return {
transform: [
{scale},
{translateX},
{translateY: translateX - 100},
{rotate: `${rotate}deg`},
],
borderRadius,
};
});
const cardStyles = useAnimatedStyle(() => {
const translateTransparentCard = interpolate(
drawerProgress.value,
[0, 0.4, 1],
[0, 0, 0],
);
const scale = interpolate(drawerProgress.value, [0, 1], [1, 0.6]);
const rotate = interpolate(drawerProgress.value, [0, 1], [0, -18]);
return {
transform: [
{translateX: -translateTransparentCard},
{translateY: translateTransparentCard + 20},
{scale},
{rotate: `${rotate}deg`},
],
};
});
return (
<View style={AppStyle.fill}>
<Animated.View
style={[
{
opacity: 0.8,
borderRadius: 10,
overflow: 'hidden',
position: 'absolute',
},
AppStyle.fullSize,
cardStyles,
style,
]}>
{children}
</Animated.View>
<Animated.View style={[style, viewStyles]}>
<View style={[AppStyle.hideOverFlow, AppStyle.fill]}>{children}</View>
</Animated.View>
</View>
);
}

If you're using react navigation, you can use drawerType: "slide" in your drawer configuration
That is available on react-navigation above v3.x and should achieve what you're expecting.
https://reactnavigation.org/docs/drawer-navigator/#drawertype

Related

How to replace tab navigation screen to stack navigation screen in react native

I am using stack navigation for the login module, When login is successful after that I navigate to the tab navigation (Home screen). When the user goes to log out from the profile screen after that I am not able to navigate on stack navigation (login screen).
I am searching on google but still have not found any related answer
this is the navigation screen code:-
const Stack = createNativeStackNavigator();
const Tab = createBottomTabNavigator();
function Navigation() {
const [token, setToken] = useState('');
const [sessionHandle, setSessionHandle] = useState(false);
AsyncStorage.getItem('token', (err, result) => {
setToken(result);
if (!token) {
setSessionHandle(false);
} else {
setSessionHandle(true);
}
});
const {width, height} = Dimensions.get('window');
function MyTabs() {
return (
<Tab.Navigator
initialRouteName="HomeTab"
screenOptions={{
headerShown: false,
tabBarActiveTintColor: Colors.black,
tabBarInactiveTintColor: Colors.gray,
tabBarStyle: {height: width * 0.18, borderRadius: 40},
}}>
<Tab.Screen
name="HomeTab"
component={ProductFlowNavigation}
options={{
tabBarLabel: 'Home',
tabBarLabelStyle: {
fontSize: 12,
fontFamily: 'Poppins-Regular',
marginBottom: 10,
},
tabBarIcon: ({focused}) => {
const set_color = focused ? Colors.bright_sky_blue : Colors.gray;
return <Ionicons name="ios-home" color={set_color} size={25} />;
},
}}
/>
<Tab.Screen
name="OrderHistory"
component={OrderHistory}
options={{
tabBarLabel: 'History',
tabBarLabelStyle: {
fontSize: 12,
fontFamily: 'Poppins-Regular',
marginBottom: 10,
},
tabBarIcon: ({focused}) => {
const set_color = focused ? Colors.bright_sky_blue : Colors.gray;
return <Ionicons name="timer" color={set_color} size={25} />;
},
}}
/>
<Tab.Screen
name="Profile"
component={Profile}
options={{
tabBarLabel: 'Profile',
tabBarLabelStyle: {
fontSize: 12,
fontFamily: 'Poppins-Regular',
marginBottom: 10,
},
tabBarIcon: ({focused}) => {
const set_color = focused ? Colors.bright_sky_blue : Colors.gray;
return <Ionicons name="person" color={set_color} size={25} />;
},
}}
/>
</Tab.Navigator>
);
}
function MyLoginSignupNavigation() {
return (
<Stack.Navigator initialRouteName="Login">
<Stack.Screen
name="Signup"
component={SignUp}
options={{headerShown: false}}
/>
<Stack.Screen
name="Login"
component={Login}
options={{headerShown: false}}
/>
<Stack.Screen
name="Home"
component={MyTabs}
options={{headerShown: false}}
/>
</Stack.Navigator>
);
}
return (
<NavigationContainer>
{sessionHandle ? <MyTabs /> : <MyLoginSignupNavigation />}
</NavigationContainer>
);
}
export default Navigation;
#mahesh you are switching between tab and stack navigation based on "sessionHandle", so i suggest you if you want to logout just set the value of "sessionHandle" to false, it will direct you to stack navigation first screen
{sessionHandle ? <MyTabs /> : <MyLoginSignupNavigation />}
you navigation depends on sessionHandle
Hopefully it will help you

React Native Navigation Animation slide implementation

Is it possible to make a Navigation animation between screen like in the video ?
Closest behaviour can be achieved with.
import { TransitionPresets } from '#react-navigation/stack';
<Stack.Screen
key={screen.key}
name={screen.key}
component={screen.component}
options={{
headerShown: false,
...TransitionPresets.SlideFromRightIOS,
}}
/>
You can try that:
const SlideTransition = {
cardStyleInterpolator: ({ current, next, layouts }) => {
return {
cardStyle: {
transform: [
{
translateX: current.progress.interpolate({
inputRange: [0, 1],
outputRange: [layouts.screen.width, 0],
}),
},
{
translateX: next
? next.progress.interpolate({
inputRange: [0, 1],
outputRange: [0, -layouts.screen.width],
})
: 1,
},
],
},
};
},
};
and then
<NavigationContainer>
<Stack.Navigator
initialRouteName={"Page1"}
screenOptions={{ headerShown: false }}
>
<Stack.Screen
name={"Page1"}
component={Page1}
options={{ ...SlideTransition }}
/>
<Stack.Screen
name={"Page2"}
component={Page2}
options={{ ...SlideTransition }}
/>
</Stack.Navigator>
</NavigationContainer>

Navigation in react-native error with stackNavigation

in the application I am creating I have set up bottom-tabs. They are functioning properly.
const Tab = createBottomTabNavigator();
export default function App() {
return (
<NavigationContainer>
<Tab.Navigator initialRouteName="Feed"
tabBarOptions={{activeTintColor: '#F78400'}}>
<Tab.Screen
name="Authentication" component={Authentication}
options={{
tabBarIcon: ({ focused, horizontal, tintColor }) => {
return (
<Image
source={require("./assets/images/authentication.jpg")}
style={{ width: 20, height: 20 }}
/>
);
}
}}
/>
<Tab.Screen
name="Dashboard"
component={Dashboard}
options={{
tabBarIcon: ({ focused, horizontal, tintColor }) => {
return (
<Image
source={require("./assets/images/dashboard.png")}
style={{ width: 20, height: 20 }}
/>
);
}
}}
/>
<Tab.Screen
name="Tools"
component={Tools}
options={{
tabBarIcon: ({ focused, horizontal, tintColor }) => {
return (
<Image
source={require("./assets/images/tools.png")}
style={{ width: 20, height: 20 }}
/>
);
}
}}
/>
<Tab.Screen
name="Settings"
component={Settings}
options={{
tabBarIcon: ({ focused, horizontal, tintColor }) => {
return (
<Image
source={require("./assets/images/settings.png")}
style={{ width: 20, height: 20 }}
/>
);
}
}}
/>
</Tab.Navigator>
</NavigationContainer>
);
}
So now, I want to set up navigation to be able to go from one screen to another. I added the code of the stacks to the code of my tabs and when I want to go on antorher screen, I click a button to go on another screen, the name of the screen appear at the top of the page but it looks like it still the first screen. I don't get what's wrong
view config getter callback for component,
could you please explain to me how to do? 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 Login from '../../Screens/Authentication'
import Signup from '../../Screens/Authentication'
import Tools from '../../Screens/Tools'
import Dashboard from '../../Screens/Dashboard'
import Settings from '../../Screens/Settings'
import Scan from '../../Screens/Tools'
import i18n from '../../src/i18n'
const Tab = createBottomTabNavigator();
const Stack = createStackNavigator();
function ScreenNavigator() {
return(
<Stack.Navigator>
<Stack.Screen name = 'Authentication' component = {Authentication}/>
<Stack.Screen name = 'Login' component = {Login}/>
<Stack.Screen name = 'Signup' component = {Signup}/>
<Stack.Screen name = 'Tools' component = {Tools}/>
<Stack.Screen name = 'Scan' component = {Scan}/>
<Stack.Screen name = 'Dashboard' component = {Dashboard}/>
<Stack.Screen name = 'Settings' component = {Settings}/>
</Stack.Navigator>
)
}
export default function AppNavigation() {
return (
<NavigationContainer>
<Tab.Navigator initialRouteName="Feed"
tabBarOptions={{activeTintColor: '#F78400'}}>
<Tab.Screen
name={i18n.t("app.auth")}
component={ScreenNavigator}
options={{
tabBarIcon: ({ focused, horizontal, tintColor }) => {
return (
<Image
source={require("../../assets/images/authentication.jpg")}
style={{ width: 20, height: 20 }}
/>
);
}
}}
/>
<Tab.Screen
name={i18n.t("app.dash")}
component={Dashboard}
options={{
tabBarIcon: ({ focused, horizontal, tintColor }) => {
return (
<Image
source={require("../../assets/images/dashboard.png")}
style={{ width: 20, height: 20 }}
/>
);
}
}}
/>
<Tab.Screen
name={i18n.t("app.tools")}
component={Tools}
options={{
tabBarIcon: ({ focused, horizontal, tintColor }) => {
return (
<Image
source={require("../../assets/images/tools.png")}
style={{ width: 20, height: 20 }}
/>
);
}
}}
/>
<Tab.Screen
name={i18n.t("app.settings")}
component={Settings}
options={{
tabBarIcon: ({ focused, horizontal, tintColor }) => {
return (
<Image
source={require("../../assets/images/settings.png")}
style={{ width: 20, height: 20 }}
/>
);
}
}}
/>
</Tab.Navigator>
</NavigationContainer>
)
}
You are not passing components when initializing the navigation
The below code
<Stack.Screen name = 'Authentication' component = 'Authentication'/>
You have passed a string for component which is causing the error, this should change to
<Stack.Screen name = 'Authentication' component = {Authentication}/>
You will have to change other screens in the stack as well

How to set always first screen of Stack Navigator inside Tab Navigator React Navigation 5

React Navigation 5
I've build a StackNavigator inside of a TabNavigator, and the navigation between home screen and other screens is working. But the problem is,When I move from Tab2 to Tab1 I expect Tab1 always show me first screen of StackNavigator.
tab1
-> Stack
-screen1
-screen2
tab2
I am on screen2 and then move to tab2
after that then I move back to Tab1 I want to always display screen1.
I am try to use
OnTabPress({navigation})=>{
navigation.navigate("stackName",{
screen: "screen1"
}).
}
Its work but its show me screen2 first then navigate to screen1. Is there any other Solution.
https://snack.expo.io/#usamasomy/groaning-donut
Use unmountOnBlur: true in options.
Eg.
<Tab.Screen
name="Stack1"
component={Stack1}
options={{
tabBarLabel: "Stack1",
unmountOnBlur: true,
}}
/>
So when you are navigating away from this tab and you're on screen2 of Stack1, you will always come on the first screen of this stackNavigator when coming back to this tab.
initialRouteName= "NAME" is the keyword to make sure you have a default
and make sure you use navigate() push() pop() accordingly.
Firstly, create a custom TabBar so we can write our own functions executed by onPress
function MyTabBar({ state, descriptors, navigation }) {
return (
<View style={{ flexDirection: 'row' }}>
{state.routes.map((route, index) => {
const { options } = descriptors[route.key];
const label =
options.tabBarLabel !== undefined
? options.tabBarLabel
: options.title !== undefined
? options.title
: route.name;
const isFocused = state.index === index;
const onPress = () => {
navigation.reset({
index: 0,
routes: [{ name: 'Screen1' }],
})
if (!isFocused && !event.defaultPrevented) {
navigation.navigate(route.name);
}
}}
const onLongPress = () => {
navigation.emit({
type: 'tabLongPress',
target: route.key,
});
};
Then in the TabScreens override the original TabBar in Tab.Navigator by using tabBar=... then call navigation.reset() with index:0 and routes:{{name: 'Screen1'}} every time MyTabBar is pressed.
const TabScreens = ()=>{
return(
<Tab.Navigator tabBar={props => <MyTabBar {...props} />} initialRouteName="Tab1Screens" >
<Tab.Screen
name = "Tab1Screens"
component = {Tab1Screens}
/>
<Tab.Screen
name = "Tab2Screens"
component = {Tab2Screens}
/>
</Tab.Navigator>
)
}
return (
<TouchableOpacity
accessibilityRole="button"
accessibilityStates={isFocused ? ['selected'] : []}
accessibilityLabel={options.tabBarAccessibilityLabel}
testID={options.tabBarTestID}
onPress={onPress}
onLongPress={onLongPress}
style={{ flex: 1 }}
>
<Text style={{ color: isFocused ? '#673ab7' : '#222' }}>
{label}
</Text>
</TouchableOpacity>
);
})}
</View>
);
}
This can be greatly improved eg:
-some logic before `navigation.reset()`
-Accessing onPress without creating a new component
-etc..
finally snack available here :https://snack.expo.io/#karammarrie/customtabbar
i have a simple solution is to set initialRouteName= "screen1" in
<Stack.Navigator
screenOptions={{
headerShown: false,
}}
initialRouteName="screen1"
>
<Stack.Screen name="screen1" component={Screen1} />
<Stack.Screen name="screen2" component={Screen2} />
</Stack.Navigator>
{/** **/}
if the screen still shows the first screen 2, you just need to comment the line <Stack.Screen name="screen2" component={Screen2} /> and reload the screen, then remove the comment line.
There is no documentation about it, but the following code worked for me:
const navigationComp = useNavigation<StackNavigationProp<Screen1Stack>();
<Tab.Screen
name="Screen1 Tab"
component={Screen1StackScreen}
listeners={{
tabPress: () => {
navigationComp.replace('Screen 1 Child 1');
},
}}
/>
The code above always navigates to the 'Screen 1 Child 1' when the "Screen1 Tab" is pressed.
like this
e
xport default function BottonTab() {
const tabOffsetValue = useRef(new Animated.Value(0)).current;
return (
<View style={{flex: 1, backgroundColor: colors.primaryColor}}>
<Tab.Navigator
initialRouteName="Home"
screenOptions={{
showLabel: false,
tabBarShowLabel: false,
headerShown: false,
tabBarStyle: {
backgroundColor: colors.white,
position: 'absolute',
bottom: hp(0.51),
marginHorizontal: wp(2),
height: hp(8),
borderRadius: wp(2),
shadowColor: '#000',
shadowOpacity: 0.06,
shadowOffset: {
width: 10,
height: 10,
},
paddingHorizontal: 20,
},
}}>
<Tab.Screen
name={'Home'}
component={HomeScreen}
options={{
title: 'Home',
showLabel: false,
tabBarIcon: ({focused}) => (
<View>
<FontAwesome5
name="home"
size={wp(6)}
color={
focused ? colors.primaryColor : colors.secondaryTextColor
}
/>
</View>
),
}}
listeners={({navigation, route}) => ({
tabPress: e => {
Animated.spring(tabOffsetValue, {
toValue: getWidth() * 0,
useNativeDriver: true,
}).start();
},
})}
/>
<Tab.Screen
name={'HelpDiskScreen'}
component={HelpDiskScreen}
options={{
title: 'HelpDisk',
tabBarIcon: ({focused}) => (
<View>
<FontAwesome5
name="search"
size={wp(6)}
color={
focused ? colors.primaryColor : colors.secondaryTextColor
}
/>
</View>
),
}}
listeners={({navigation, route}) => ({
tabPress: e => {
Animated.spring(tabOffsetValue, {
toValue: getWidth() * 1.22,
useNativeDriver: true,
}).start();
},
})}
/>
<Tab.Screen
name={'ManageBookingScreen'}
component={ManageBookingScreen}
options={{
title: 'Manage',
tabBarIcon: ({focused}) => (
<View>
<Feather
name="settings"
size={wp(6)}
color={
focused ? colors.primaryColor : colors.secondaryTextColor
}
/>
</View>
),
}}
listeners={({navigation, route}) => ({
tabPress: e => {
Animated.spring(tabOffsetValue, {
toValue: getWidth() * 2.52,
useNativeDriver: true,
}).start();
},
})}
/>
<Tab.Screen
name={'ParkyingTypesScreen'}
component={ParkyingTypesScreen}
options={{
title: 'Parking',
tabBarIcon: ({focused}) => (
<View>
<FontAwesome5
name="bell"
size={wp(6)}
color={
focused ? colors.primaryColor : colors.secondaryTextColor
}
/>
</View>
),
}}
listeners={({navigation, route}) => ({
tabPress: e => {
Animated.spring(tabOffsetValue, {
toValue: getWidth() * 3.82,
useNativeDriver: true,
}).start();
},
})}
/>
</Tab.Navigator>
<Animated.View
style={{
width: getWidth(),
marginLeft: getWidth() * 0.58,
height: 2,
backgroundColor: colors.primaryColor,
bottom: hp(7),
borderRadius: 20,
transform: [{translateX: tabOffsetValue}],
}}></Animated.View>
</View>
);
}
Another option is to clear the stack of the navigation before navigating, so when you return to that screen, the navigation starts from the top
navigation.dispatch(StackActions.popToTop());
navigation.navigate("NextScreen");

Unable to navigate betwen stacks even with navigation.navigate('name")

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.