when added authentication state, the screen got stuck at splash screen - reactjs

I am trying to create my Authentication flow where I store my token in async storage, upon mounting my entry point checks the state of token if it is null then it goes to AuthNavigator or RootNavigator, however upon adding the code I have tried build many a times, each time it is being stuck at the splashscreen and not moving forward, my code is as follows:
App.js
import 'react-native-gesture-handler';
import React, {useEffect,useState} from 'react';
import SwitchRootNavigator from './src/navigationNative/AppNavigation';
import AsyncStorage from '#react-native-community/async-storage';
export default function App() {
const [userObject,setUserObject]=useState({});
const getData = async () => {
try {
const jsonValue = await AsyncStorage.getItem('user_object');
// return jsonValue != null ? JSON.parse(jsonValue) : null;
setUserObject(jsonValue);
} catch (e) {
console.log(e);
}
};
useEffect(() => {
getData();
});
return(
<>
{console.log('objjjj',userObject)}
<SwitchRootNavigator signedIn={userObject}/>
</>);
}
AppNavigation.js:
import * as React from 'react';
import {View, Image, Text, Platform} from 'react-native';
import {NavigationContainer} from '#react-navigation/native';
import {createStackNavigator} from '#react-navigation/stack';
import {createBottomTabNavigator} from '#react-navigation/bottom-tabs';
import MaterialIcon from 'react-native-vector-icons/MaterialIcons';
import FontAwesomeIcon from 'react-native-vector-icons/FontAwesome';
import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons';
import LoginScreen from '../screens/authentication/LoginScreen.native';
import OtpScreen from '../screens/authentication/OtpScreen.native';
import HomeScreen from '../screens/HomeScreen/HomeScreen.native';
import ConsultationHomeScreen from '../screens/Consult/ConsultationHomeScreen';
import PlansScreen from '../screens/PlansScreen';
import AcceptInviteScreen from '../screens/AcceptInviteScreen';
import OnlineConsultationWebviewScreen from '../screens/Consult/OnlineConsultationWebviewScreen';
import ActualConsultationWebviewScreen from '../screens/Consult/ActualConsultationWebviewScreen';
import VaccinationDetailreadMoreScreen from '../screens/HomeScreen/screens/Vaccination/VaccinationDetailreadMoreScreen';
import PLActivityPlanner from '../screens/activityplanner/PLActivityPlanner';
import PLActivityPlannerDetail from '../screens/activityplanner/PLActivityPlannerDetail';
import PLActivityPlannerReport from '../screens/activityplanner/PLActivityPlannerReport';
import SymptomChecker from '../screens/symptom-checker/symptom-checker';
import SymptomCheckerSearch from '../screens/symptom-checker/symptom-checker-search';
import symptomCheckerAssessmentReport from '../screens/symptom-checker/symptom-checker-assessment-report';
import SymptomCheckerQA from '../screens/symptom-checker/symptom-checker-question-answer';
import AddChild from '../screens/Child/AddChild';
import BabyAccuteIllnessScreen from '../screens/Consult/BabyAccuteIllnessScreen';
import VaccinationListScreen from '../screens/HomeScreen/screens/Vaccination/VaccinationListScreen';
import VaccinationDetailScreen from '../screens/HomeScreen/screens/Vaccination/VaccinationDetailScreen';
import SymptomCheckerDetailReport from '../screens/symptom-checker/symptom-checker-detail-report';
import TodaysGoalScreen from '../screens/diet/TodaysGoalScreen';
import MealDescriptionScreen from '../screens/diet/MealDescriptionScreen';
import {Images} from '../assets/index.js';
import HomeTabScreen from '../screens/HomeScreen/HomeTabScreen';
const RootStack = createStackNavigator();
const Tab = createBottomTabNavigator();
const AuthStack = createStackNavigator();
function AuthNavigator() {
return (
<AuthStack.Navigator>
<AuthStack.Screen
name="login"
component={LoginScreen}
options={{headerShown: false}}
/>
<AuthStack.Screen
name="otp"
component={OtpScreen}
options={{headerShown: false}}
/>
<AuthStack.Screen name="addchild" component={AddChild} />
<AuthStack.Screen
name="acceptinvitescreen"
component={AcceptInviteScreen}
/>
</AuthStack.Navigator>
);
}
function BottomTabBar() {
return (
<Tab.Navigator
lazy={false}
initialRouteName="Home"
tabBarOptions={{
labelStyle: {
color: '#FF1493',
fontSize: 12,
},
}}>
<Tab.Screen
name="Home"
// uncommnet below line to see new Home Tab
// component={HomeTabScreen}
// uncomment below see old Home Tab
component={HomeScreen}
options={{
tabBarLabel: 'Home',
tabBarIcon: ({color, size}) => (
<MaterialIcon name="home" color="#FF1493" size={30} />
),
}}
/>
<Tab.Screen
name="Consult"
component={ConsultationHomeScreen}
initialParams={{
uri: 'https://qa.parentlane.com/doctors/launch-home?app_type=0',
}}
options={{
tabBarLabel: 'Consult',
tabBarIcon: ({color, size}) => (
<FontAwesomeIcon name="stethoscope" color="#FF1493" size={30} />
),
}}
/>
<Tab.Screen
name="Plans"
component={PlansScreen}
options={{
tabBarLabel: 'Plans',
tabBarIcon: ({color, size}) => (
<MaterialCommunityIcons
name="crown-outline"
color="#FF1493"
size={30}
/>
),
}}
/>
</Tab.Navigator>
);
}
function RootNavigator() {
function LogoTitle(props) {
return (
<View
style={{
flexDirection: 'row',
alignItems: 'center',
marginVertical: 10,
}}>
<Image
style={{width: 31.44, height: 31.2}}
source={Images.symptomcheck_bot1}
/>
<Text
style={{
marginLeft: 10,
color: '#FFFFFF',
fontStyle: 'italic',
fontSize: 14,
}}>
{props.children}
</Text>
</View>
);
}
return (
<RootStack.Navigator>
<RootStack.Screen
name="Home"
component={BottomTabBar}
options={{headerShown: false}}
/>
<RootStack.Screen
name="online"
component={OnlineConsultationWebviewScreen}
/>
<RootStack.Screen
name="actual"
component={ActualConsultationWebviewScreen}
/>
<RootStack.Screen name="baby" component={BabyAccuteIllnessScreen} />
<RootStack.Screen name="vaccinelist" component={VaccinationListScreen} />
<RootStack.Screen
name="vaccinationdetail"
component={VaccinationDetailScreen}
/>
<RootStack.Screen
name="vaccinereadmore"
component={VaccinationDetailreadMoreScreen}
/>
<RootStack.Screen
name="symptomChecker"
component={SymptomChecker}
options={{
gesturesEnabled: false,
headerBackTitleVisible: false,
headerBackTitle: null,
title: 'Symptom Checker',
headerStyle: {
backgroundColor: '#FE017E',
},
headerTintColor: '#fff',
headerTitleStyle: {
fontWeight: '300',
fontSize: 14,
fontStyle: 'italic',
width: '100%',
},
headerTitleContainerStyle: {
left: Platform.OS === 'ios' ? -70 : 50,
},
headerTitle: (props) => <LogoTitle {...props} />,
}}
/>
<RootStack.Screen
name="symptomCheckerSearch"
component={SymptomCheckerSearch}
options={{
gesturesEnabled: false,
headerBackTitleVisible: false,
headerBackTitle: null,
title: 'Hi! I’m ISHA, your health care assistant',
headerStyle: {
backgroundColor: '#FE017E',
},
headerTintColor: '#fff',
headerTitleStyle: {
fontWeight: '300',
fontSize: 14,
fontStyle: 'italic',
},
headerTitleContainerStyle: {
left: Platform.OS === 'ios' ? 0 : 50,
},
headerTitle: (props) => <LogoTitle {...props} />,
}}
/>
<RootStack.Screen
name="symptomCheckerQA"
component={SymptomCheckerQA}
options={{
gesturesEnabled: false,
headerBackTitleVisible: false,
headerBackTitle: null,
title: 'Hi! I’m ISHA, your health care assistant',
headerStyle: {
backgroundColor: '#FE017E',
},
headerTintColor: '#fff',
headerTitleStyle: {
fontWeight: '300',
fontSize: 14,
fontStyle: 'italic',
},
headerTitleContainerStyle: {
left: Platform.OS === 'ios' ? 0 : 50,
},
headerTitle: (props) => <LogoTitle {...props} />,
}}
/>
<RootStack.Screen
name="symptomCheckerAssessmentReport"
component={symptomCheckerAssessmentReport}
options={{
gesturesEnabled: false,
headerBackTitleVisible: false,
headerBackTitle: null,
title: 'Assessment Report',
headerStyle: {
backgroundColor: '#FE017E',
},
headerTintColor: '#fff',
headerTitleStyle: {
fontWeight: '300',
fontSize: 14,
fontStyle: 'italic',
},
headerTitleContainerStyle: {
left: Platform.OS === 'ios' ? -70 : 50,
},
}}
/>
<RootStack.Screen
name="symptomCheckerDetailReport"
component={SymptomCheckerDetailReport}
options={{
gesturesEnabled: false,
headerBackTitleVisible: false,
headerBackTitle: null,
title: 'Detail Report',
headerStyle: {
backgroundColor: '#FE017E',
},
headerTintColor: '#fff',
headerTitleStyle: {
fontWeight: '300',
fontSize: 14,
fontStyle: 'italic',
},
headerTitleContainerStyle: {
left: Platform.OS === 'ios' ? -100 : 50,
},
}}
/>
<RootStack.Screen
name="plactivityplanner"
component={PLActivityPlanner}
options={{headerShown: false}}
/>
<RootStack.Screen
name="plactivityplannerdetail"
component={PLActivityPlannerDetail}
options={{headerShown: false}}
/>
<RootStack.Screen
name="plactivityplannerreport"
component={PLActivityPlannerReport}
options={{headerShown: false}}
/>
<RootStack.Screen
name="todaysgoal"
component={TodaysGoalScreen}
options={{headerShown: false}}
/>
<RootStack.Screen
name="mealdesc"
component={MealDescriptionScreen}
options={{headerShown: false}}
/>
</RootStack.Navigator>
);
}
export default function SwitchRootNavigator(props) {
const signedIn = props.signedIn;
return (
<NavigationContainer>
{signedIn != null && signedIn != undefined && signedIn != '' ? (
<RootNavigator />
) : (
<AuthNavigator />
)}
</NavigationContainer>
);
}
the console is showing up to be as follows:
we can clearly see from the above image that the object is null, hence my entrypoint file is rendering, however the app is not moving forward to the LoginScreen.
Kindly help, any lead would be great, thanks.

Looks like it is an infinite loop of useEffect because of no dependency and once it sets the state hook of setUserObject, function component got re-render and re-trigger useEffect.
Please add dependency array empty [] and let me know if it fixes.
Example :
useEffect(() => {
getData();
},[]);

Related

How to manage nested navigations so that Homepage displays Navbar when signed in?

I have two navigators and the idea is to have the main navigation container to hold the general pages: Home, SignIn, SignUp, confirmEmail and NewPassword but once the user login in to Home I would like the navigation bar to display and have its own navigation routings.
Navigation.js:
<NavigationContainer>
<Stack.Navigator screenOptions={{headerShown: false}}>
{user ? (
<Stack.Screen name="HomeScreen" component={HomeScreen} />
) : (
<>
<Stack.Screen name="SignIn" component={SignInScreen} />
<Stack.Screen name="SignUp" component={SignUpScreen} />
<Stack.Screen name="ConfirmEmail" component={ConfirmEmailScreen} />
<Stack.Screen
name="ResetPassword"
component={ResetPasswordScreen}
/>
<Stack.Screen name="NewPassword" component={NewPasswordScreen} />
</>
)}
</Stack.Navigator>
</NavigationContainer>
Navbar.js
const Navbar = () => {
const tabOffsetValue = useRef(new Animated.Value(0)).current;
return (
// <NavigationContainer>
<Tab.Navigator
screenOptions={{
tabBarShowLabel: false,
headerShown: false,
// Floating Tab Bar...
tabBarStyle: {
backgroundColor: 'white',
position: 'absolute',
// Max Height...
borderRadius: 10,
// Shadow...
},
}}>
{
// Tab Screens....
// Tab ICons....
}
<Tab.Screen
name={'Home'}
component={HomeScreen}
options={{
tabBarIcon: ({focused}) => (
<View
style={{
// centring Tab Button...
position: 'absolute',
top: 20,
}}>
<Icon
name="home"
size={20}
color={focused ? 'red' : 'gray'}></Icon>
</View>
),
}}
listeners={({navigation, route}) => ({
// Onpress Update....
tabPress: e => {
Animated.spring(tabOffsetValue, {
toValue: 0,
useNativeDriver: true,
}).start();
},
})}>
</Tab.Screen>
HomeScreen.Js
const HomeScreen = () => {
const signOut = () => {
Auth.signOut();
};
return (
<View>
<Navbar/>
<Text style={{fontSize: 24, alignSelf: 'center'}}>Welcome to Flimpi</Text>
<Text
onPress={signOut}
style={{
width: '100%',
textAlign: 'center',
color: 'red',
marginTop: 'auto',
marginVertical: 20,
fontSize: 20
}}>
Sign Out!
</Text>
</View>
);
};
Expectedly I am getting the following error:
Require cycle: src/screens/HomeScreen/index.js -> src/components/Navbar/index.js -> src/components/Navbar/Navbar.js -> src/screens/HomeScreen/index.js
Require cycles are allowed, but can result in uninitialized values. Consider refactoring to remove the need for a cycle.
The Error makes sense but I just do not know how to structure the code

React navigation open openDrawer() not working || when ever i reload my site then it's working fine

hope so doing well today. Currently am working on a project and but stucked in the navigation because am using both Navigations at the same time ( Tab and Drawer Navigation ) That's why am a little bit confused about it. When I login with the new user the try to open the Drawer it shows me an error ( TypeError: navigation.openDrawer is not a function. (In 'navigation.openDrawer()', 'navigation.openDrawer' is undefined) ) but when I reload my app it works fine for me. Here is my complete Navigation
============================main navigation Stack =======================================
import React, { useState, useEffect } from 'react';
import SignInScreen from '../sign-in-screen'
import { createStackNavigator, HeaderBackButton } from "#react-navigation/stack";
import SignUp from '../Sign-up-screen';
import HomeScreen from '../Home/index';
import Looking from "../LookingForScreen";
import CodingGigs from "../CodingGigs";
import LandingScreen from "../LadingScreen";
import OurPicksScreen from "../OurPicks/OurPicksScreen";
import SummaryScrren from "../PaymentScreen";
import ConfirmOrderScreen from "../PaymentScreen/ConfirmOrderScreen";
import InboxScreen from "../ChatScreen";
import { createDrawerNavigator } from "#react-navigation/drawer";
import UserTabNavigator from "./UserTabNavigator";
import MyRequestsScreen from "../MyRequests";
import PostRequests from "../MyRequests/Requests";
import MyDashboardScreen from "../MyDashboard";
import Header from '../../Components/molecules/Header';
import { Icons } from "../../Assets/icon";
import DrawerContentDetails from "./drawernavigator";
import ConversationScreen from "../ChatScreen/ConversationScreen";
import MyOrdersScreen from "../MyOrders";
import GigsScreen from "../MyGigs";
import { NavigationContainer, useNavigation } from "#react-navigation/native";
import Earnings from '../Earnings/Earnings'
import Template from '../../Screens/OfferTemplate/Template'
import SellerGig from '../../Screens/SellerGig/SellerGig'
import SellerProfile from '../../Screens/SellerProfile/SellerProfile'
import About from '../../Screens/Profile-Screen/About'
import CreateGigScreen from "../CreateGig/CreateGigScreen";
import ShowSeprateGig from "../ShowSeprateGig/ShowSeprateGig";
import ProfileScreen from "../../Screens/Profile-Screen/ProfileScreen"
import SellerInfo from '../../Components/Profile_screen_components/SellerInfo'
import BuyerInfo from '../../Components/Profile_screen_components/BuyerInfo';
import ForgetPasword from "../forgetPassword/ForgetPassword";
import SaveGigs from "../SaveGigs/SaveGigs";
import OrderDetails from "../OrderDetails/OrderDetails";
import SearchGigs from "../../Components/molecules/search-gigs-card/SearchGigs";
import { Text, View, StyleSheet, TouchableOpacity, Image } from 'react-native';
import IconName1 from 'react-native-vector-icons/FontAwesome';
import Searchgigs from '../SearchGigs/Searchgigs';
import GigDetailsScreen from '../GigDetailsScreen/GigDetailsScreen';
import AsyncStorage from "#react-native-community/async-storage";
import BuyerHome from '../../Components/organism/home/BuyerHome';
import Mydashboard from '../../Components/organism/MyDashboard/MyDashboard';
import RiderOrder from '../RiderOrder/RiderOrder';
import RiderOrderDetail from '../RiderOrderDetail/RiderOrderDetail';
const Stack = createStackNavigator();
const OnBoardStack = createStackNavigator();
const topbarComponent = ({ navigation }) => ({
headerTitleStyle: { fontSize: 25, color: '#f9f9f9', fontWeight: 'bold', textAlign: 'center' },
headerStyle: { backgroundColor: '#255ed6', height: 80, elevation: 0 },
title: 'Kamaee',
headerLeft: () => {
const[userimage, setuserimage] = useState('')
AsyncStorage.getItem('image').then((res)=>setuserimage(JSON.parse(res)))
return (
<View style={{ marginLeft: 10 }}>
<Image
style={{ height: 50, width: 50, borderRadius: 100 }}
source={{
uri:userimage
}} />
</View>
)
},
headerRight: () => (
<TouchableOpacity onPress={() => navigation.openDrawer()}
style={{ height: 110, backgroundColor: '#fff', borderBottomLeftRadius: 50, width: 65 }}>
<Image source={require('../../Assets/menu.png')} style={{ marginLeft: 20, marginTop: 30 }} />
</TouchableOpacity>
),
}
)
// Main Home Stack Navigation
export const MainStackNavigator = () => {
return (
<Stack.Navigator screenOptions={{ headerShown: true }}>
<Stack.Screen name="trending" component={HomeScreen} options={topbarComponent} />
<Stack.Screen name="BuyerHome" component={BuyerHome} options={topbarComponent} />
<Stack.Screen name="orders" component={MyOrdersScreen} options={topbarComponent} />
<Stack.Screen name="Mydashboard" component={Mydashboard} options={topbarComponent} />
<Stack.Screen name="looking" component={Looking} options={topbarComponent} />
<Stack.Screen name="ourpicks" component={OurPicksScreen} options={topbarComponent} />
<Stack.Screen name='orderdetail' component={OrderDetails} options={topbarComponent} />
<Stack.Screen name="codinggigs" component={CodingGigs} options={topbarComponent} />
<Stack.Screen name='gigsscreen' component={GigsScreen} options={topbarComponent} />
<Stack.Screen name="SearchGigs" component={Searchgigs} options={topbarComponent} />
<Stack.Screen name="SaveGigs" component={SaveGigs} options={topbarComponent} />
<Stack.Screen name="dashboard" component={MyDashboardScreen} options={topbarComponent} />
<Stack.Screen name="payment" component={SummaryScrren} options={topbarComponent} />
<Stack.Screen name="doneorder" component={ConfirmOrderScreen} options={topbarComponent} />
<Stack.Screen name="inboxx" component={InboxScreen} options={topbarComponent} />
<Stack.Screen name="conversation" component={ConversationScreen} options={topbarComponent} />
<Stack.Screen name="newrequest" component={MyRequestsScreen} options={topbarComponent} />
<Stack.Screen name="Gig" component={ShowSeprateGig} options={topbarComponent} />
<Stack.Screen name="myrequests" component={PostRequests} options={topbarComponent} />
<Stack.Screen name="GigDetails" component={GigDetailsScreen} options={topbarComponent} />
<Stack.Screen name="earnings" component={Earnings} options={topbarComponent} />
<Stack.Screen name="template" component={Template} options={topbarComponent} />
<Stack.Screen name="sellergig" component={SellerGig} options={topbarComponent} />
<Stack.Screen name="sellerprofile" component={SellerProfile} options={topbarComponent} />
<Stack.Screen name="about" component={About} options={topbarComponent} />
{/* <Stack.Screen name='SellerInfo' component={SellerInfo} options={topbarComponent} />
<Stack.Screen name="BuyerInfo" component={BuyerInfo} options={topbarComponent} /> */}
<Stack.Screen name="CreateGig" component={CreateGigScreen} options={topbarComponent} />
</Stack.Navigator>
);
}
// Inbox Screen Navigation
export const InboxScreens = () => {
return (
<Stack.Navigator>
<Stack.Screen name="inboxx" component={InboxScreen} options={topbarComponent} />
<Stack.Screen name="orders" component={MyOrdersScreen} options={topbarComponent} />
<Stack.Screen name="payment" component={SummaryScrren} options={topbarComponent} />
<Stack.Screen name="doneorder" component={ConfirmOrderScreen} options={topbarComponent} />
<Stack.Screen name="conversation" component={ConversationScreen} options={topbarComponent} />
<Stack.Screen name="newrequest" component={MyRequestsScreen} options={topbarComponent} />
{/* <Stack.Screen name='SellerInfo' component={SellerInfo} options={topbarComponent} />
<Stack.Screen name="BuyerInfo" component={BuyerInfo} options={topbarComponent} /> */}
<Stack.Screen name="myrequests" component={PostRequests} options={topbarComponent} />
</Stack.Navigator>
);
}
// Profile Tab Navigation
export const profiletabScreen = () => {
return (
<Stack.Navigator>
<Stack.Screen name="Profile" component={ProfileScreen} options={topbarComponent} />
<Stack.Screen name="codinggigs" component={CodingGigs} options={topbarComponent} />
<Stack.Screen name="orders" component={MyOrdersScreen} options={topbarComponent} />
{/* <Stack.Screen name='SellerInfo' component={SellerInfo} options={topbarComponent} />
<Stack.Screen name="BuyerInfo" component={BuyerInfo} options={topbarComponent} /> */}
<Stack.Screen name='gigsscreen' component={GigsScreen} options={topbarComponent} />
<Stack.Screen name="dashboard" component={MyDashboardScreen} options={topbarComponent} />
<Stack.Screen name="payment" component={SummaryScrren} options={topbarComponent} />
<Stack.Screen name="doneorder" component={ConfirmOrderScreen} options={topbarComponent} />
<Stack.Screen name="newrequest" component={MyRequestsScreen} options={topbarComponent} />
<Stack.Screen name="Gig" component={ShowSeprateGig} options={topbarComponent} />
<Stack.Screen name="SaveGigs" component={SaveGigs} options={topbarComponent} />
<Stack.Screen name="sellerprofile" component={SellerProfile} options={topbarComponent} />
<Stack.Screen name="myrequests" component={PostRequests} options={topbarComponent} />
<Stack.Screen name="earnings" component={Earnings} options={topbarComponent} />
<Stack.Screen name="template" component={Template} options={topbarComponent} />
<Stack.Screen name="sellergig" component={SellerGig} options={topbarComponent} />
<Stack.Screen name="about" component={About} options={topbarComponent}/>
<Stack.Screen name="CreateGig" component={CreateGigScreen} options={topbarComponent} />
<Stack.Screen name='orderdetail' component={OrderDetails} options={topbarComponent} />
</Stack.Navigator>
)
}
// Search Stack navigation
export const SearchGigStack = () => {
return (
<Stack.Navigator screenOptions={{ headerShown: true }}>
<Stack.Screen name="SearchGigs" component={Searchgigs} options={topbarComponent} />
<Stack.Screen name="ourpicks" component={OurPicksScreen} options={topbarComponent} />
{/* <Stack.Screen name="GigDetailsScreen" component={GigDetailsScreen} options={topbarComponent} /> */}
<Stack.Screen name="GigDetails" component={GigDetailsScreen} options={topbarComponent} />
{/* <Stack.Screen name='SellerInfo' component={SellerInfo} options={topbarComponent} />
<Stack.Screen name="BuyerInfo" component={BuyerInfo} options={topbarComponent} /> */}
</Stack.Navigator>
)
}
// Onboarding Navigation
export const OnBoardingStack = () => {
return (
<OnBoardStack.Navigator screenOptions={{ headerShown: false }}>
<OnBoardStack.Screen name="landing" component={LandingScreen} />
<OnBoardStack.Screen name="signup" component={SignUp} />
<OnBoardStack.Screen name="signin" component={SignInScreen} />
<OnBoardStack.Screen name="forgetPassword" component={ForgetPasword} />
</OnBoardStack.Navigator>
);
};
// Drawer Navigation
const Drawer = createDrawerNavigator()
export const DrawerStack = () => {
return (
<Drawer.Navigator id="LeftDrawer" drawerContent={(props) => <DrawerContentDetails {...props} />} drawerStyle={{ width: '100%' }}>
<Drawer.Screen name='jhg' component={UserTabNavigator} />
{/* <Drawer.Screen name='hg' component={MainStackNavigator} /> */}
</Drawer.Navigator>
)
}
// Rider Screens Stack
export const riderScreenStack = () =>{
return(
<Stack.Navigator initialRouteName='Rider' >
<Stack.Screen name='Rider' component={RiderOrder} options={{headerShown:false}}/>
<Stack.Screen name='RiderOrder' component={RiderOrderDetail} options={{headerShown:false}}/>
</Stack.Navigator>)
}
const Main = createStackNavigator()
export const Navigation = () => {
return (
<NavigationContainer>
<Main.Navigator screenOptions={{ headerShown: false }}>
<Main.Screen name='onboardingScreens' component={OnBoardingStack} />
<Main.Screen name='DrawerScreens' component={DrawerStack} />
<Drawer.Screen name='MainNavigator' component={UserTabNavigator} />
<Main.Screen name='RiderStack' component={riderScreenStack}/>
</Main.Navigator>
</NavigationContainer>
);
}
============================Drawer Componen=======================================
import React, { useState, useEffect } from 'react';
import { View, StyleSheet, TouchableOpacity, Image, ImageBackground } from 'react-native';
import { Avatar, Title, Caption, Drawer, Text, Switch } from 'react-native-paper';
import { DrawerContentScrollView, DrawerItem } from '#react-navigation/drawer';
import AsyncStorage from '#react-native-community/async-storage';
import IconName1 from 'react-native-vector-icons/FontAwesome';
import SellerInfo from '../../Components/Profile_screen_components/SellerInfo'
import BuyerInfo from '../../Components/Profile_screen_components/BuyerInfo';
import IconName from 'react-native-vector-icons/Ionicons';
import { BASEURL, EndPoint } from '../../services/ApiManager';
const DrawerContentDetails = (props) => {
const [tokeen, settokeen] = useState()
const [toggle, setToggle] = useState(true);
if (toggle == true) {
var raw = JSON.stringify({
"role": "seller"
});
var requestOptions = {
method: 'PATCH',
headers: {
'Authorization': 'Bearer ' + tokeen,
'Content-Type': 'application/json'
},
body: raw,
redirect: 'follow'
};
fetch(BASEURL + EndPoint.changeRole, requestOptions)
.then(response => response.json())
.catch(error => console.log('error', error));
}
else {
var raw = JSON.stringify({
"role": "buyer"
});
var requestOptions = {
method: 'PATCH',
headers: {
'Authorization': 'Bearer ' + tokeen,
'Content-Type': 'application/json'
},
body: raw,
redirect: 'follow'
};
fetch(BASEURL + EndPoint.changeRole, requestOptions)
.then(response => response.json())
.catch(error => console.log('error', error));
}
const token = () => {
var requestOptions = {
method: 'GET',
headers: {
'Authorization': 'Bearer ' + tokeen
},
redirect: 'follow'
};
fetch(BASEURL + EndPoint.logout, requestOptions)
.then(response => response.json())
.then(res => {
if (res.result == 'success') {
alert('Logout Successfully')
AsyncStorage.removeItem('token')
AsyncStorage.removeItem('username')
props.navigation.navigate('landing')
}
else {
'Network Error'
}
})
.catch(error => console.log('error', error));
}
async function toggleButton() {
setToggle(prevToggle => !prevToggle)
if (toggle) {
try {
await AsyncStorage.setItem('toggle', JSON.stringify(true));
} catch (error) {
}
} else {
try {
await AsyncStorage.setItem('toggle', JSON.stringify(false));
} catch (error) { }
}
};
const toggleSwitch = () => setToggle(previousState => !previousState);
const [userimage, setuserimage] = useState('')
const [username, setusername] = useState()
useEffect(() => {
const tokeeen = async () => {
let name = await AsyncStorage.getItem('token').then((res) => settokeen(res))
AsyncStorage.getItem('image').then((res) => setuserimage(JSON.parse(res)))
AsyncStorage.getItem('userename').then((res) => setusername(res))
}
tokeeen()
})
return (
<ImageBackground style={{ height: '100%', width: '100%' }}>
<View style={{ flex: 1, backgroundColor: '#255ed6', }}>
<DrawerContentScrollView {...props} >
<View style={{ flexDirection: 'row', justifyContent: 'space-between', height: 100, }}>
<View style={{ justifyContent: 'center' }}>
<Image style={{ marginLeft: 10, width: 60, height: 60, borderRadius: 100 }}
source={{
uri: userimage
}}
// size={50}
/>
</View>
<View style={{ justifyContent: 'center' }}>
<View style={{ height: 100, width: 60, backgroundColor: '#fff', borderBottomLeftRadius: 50, marginTop: -5 }}>
<TouchableOpacity onPress={() => props.navigation.closeDrawer()}>
<Image source={require('../../Assets/cross.png')} style={{ marginLeft: 20, marginTop: 30 }} />
</TouchableOpacity>
</View>
</View>
</View>
<View style={styles.drawerContent}>
<View style={styles.userInfoSection}>
<View>
<View style={{ marginLeft: 15, flexDirection: 'column', marginBottom: 20, }}>
<Title style={styles.title}>{username}</Title>
<Caption style={styles.caption}>Balance: $478</Caption>
</View>
<View style={styles.seller_container}>
<View style={styles.icon_container}>
<IconName name={"briefcase-outline"} size={25} color={"white"} />
</View>
<View style={styles.seller_text_container}>
<Text style={styles.seller_text}>{toggle == false ? ' Buyer Mode' : 'Seller Mode '}</Text>
</View>
<View style={styles.toggle_button_container}>
<IconName1 name={toggle == false ? "toggle-on" : "toggle-off"} size={25} color={"#00ff2b"} onPress={() => toggleButton()} />
</View>
</View>
</View>
{toggle == false ? <BuyerInfo {...props} /> : <SellerInfo {...props} />}
</View>
</View>
</DrawerContentScrollView>
<TouchableOpacity
onPress={token}
style={{ padding: 10, backgroundColor: 'white', width: 150, marginBottom: 60, borderRadius: 10, elevation: 30, marginHorizontal: 20 }}>
<Text style={{ fontSize: 18, textAlign: 'center', color: 'black', }}>Logout</Text>
</TouchableOpacity>
</View >
</ImageBackground>
);
}
export default DrawerContentDetails;
const styles = StyleSheet.create({
title: {
fontSize: 25,
marginTop: 3,
// fontWeight: 'bold',
color: 'white'
},
caption: {
fontSize: 15,
color: 'white'
},
seller_container: {
flexDirection: "row",
height: 40,
// width:400,
marginLeft: 20,
},
seller_text_container: {
// width: "20%",
marginLeft: 25,
height: "100%",
justifyContent: "center",
},
seller_text: {
fontSize: 19,
color: "white",
},
toggle_button_container: {
height: "100%",
// width: "20%",
justifyContent: "center",
marginLeft: 100,
// alignItems: "flex-end"
},
});
Please have a look at the code and waitin for suggestions by the Seniors

How to combine bottom tab navigator with drawer navigator

My tab below code is a bottom-tab navigator code and I want to display it on every screen by rendering it on app.js as I did for the drawer navigator
(in simple words I want to call the bottom tab navigator on screen)
const Stack = createStackNavigator();
const Drawer = createDrawerNavigator();
let user1=""
let data=""
export function DrwaerNav(props) {
if(props.route.params!=undefined){
console.log('props arent undefined')
user1=props.route.params.user.auth
data=props.route.params.user.auth
}
return (
<Drawer.Navigator initialRouteName="homeS" drawerContent={(props) => <DrawerContent props={props} data={user1}/>}
screenOptions={{
headerStyle:{
backgroundColor:'transparent',
},
headerTintColor:'black',
headerTitleStyle:{
fontWeight:'bold',
}
}}
>
<Drawer.Screen name="complaints" component={complaints}
options={{
title:'Home',
headerTitleAlign:'left',
headerRight:()=>(
<View style={{marginEnd:10,flexDirection:'row'}}>
<Text style={{paddingRight:15,paddingTop:13,fontWeight:"normal",}}>{user1.email}</Text>
<Avatar.Image
source={{ uri:base64.decode(user1.avatar)}}
size={40}
/>
{/* <Text>Email:{user1.email}</Text> */}
</View>
),
}}/>
<Drawer.Screen name="homeS" component={homeS} options={{
title:'Home',
headerTitleAlign:'left',
headerRight:()=>(
<View style={{marginEnd:10,flexDirection:'row'}}>
{/* <Text style={{paddingRight:15,paddingTop:13,fontWeight:"normal",fontSize:12,}}>{user1.email}</Text> */}
<TouchableOpacity
onPress={()=>{
props.navigation.navigate('Profile',data={data})
}
}>
<Avatar.Image
source={{ uri:base64.decode(user1.avatar)}}
size={40}
/>
</TouchableOpacity>
{/* <Text>Email:{user1.email}</Text> */}
</View>
),
}}/>
<Drawer.Screen name="Updates" component={updates}
options={{
title:'Home',
headerTitleAlign:'left',
headerRight:()=>(
<View style={{marginEnd:10,flexDirection:'row'}}>
<Text style={{paddingRight:15,paddingTop:13,fontWeight:"normal",}}>{user1.email}</Text>
<Avatar.Image
source={{ uri:base64.decode(user1.avatar)}}
size={40}
/>
{/* <Text>Email:{user1.email}</Text> */}
</View>
),
}}/>
<Drawer.Screen name="userComplaints" component={userComplaints}
options={{
title:'Home',
headerTitleAlign:'left',
headerRight:()=>(
<View style={{marginEnd:10,flexDirection:'row'}}>
<Text style={{paddingRight:15,paddingTop:13,fontWeight:"normal",}}>{user1.email}</Text>
<Avatar.Image
source={{ uri:base64.decode(user1.avatar)}}
size={40}
/>
{/* <Text>Email:{user1.email}</Text> */}
</View>
),
}}/>
<Drawer.Screen name="GuestReg" component={Guest}
options={{
title:'Home',
headerTitleAlign:'left',
headerRight:()=>(
<View style={{marginEnd:10,flexDirection:'row'}}>
<Text style={{paddingRight:15,paddingTop:13,fontWeight:"normal",}}>{user1.email}</Text>
<Avatar.Image
source={{ uri:base64.decode(user1.avatar)}}
size={40}
/>
{/* <Text>Email:{user1.email}</Text> */}
</View>
),
}}/>
<Drawer.Screen name="myGuests" component={myGuest}
options={{
title:'Home',
headerTitleAlign:'left',
headerRight:()=>(
<View style={{marginEnd:10,flexDirection:'row'}}>
<Text style={{paddingRight:15,paddingTop:13,fontWeight:"normal",}}>{user1.email}</Text>
<Avatar.Image
source={{ uri:base64.decode(user1.avatar)}}
size={40}
/>
{/* <Text>Email:{user1.email}</Text> */}
</View>
),
}}/>
<Drawer.Screen name="Updateguest" component={Updateguest}
options={{
title:'Home',
headerTitleAlign:'left',
headerRight:()=>(
<View style={{marginEnd:10,flexDirection:'row'}}>
<Text style={{paddingRight:15,paddingTop:13,fontWeight:"normal",}}>{user1.email}</Text>
<Avatar.Image
source={{ uri:base64.decode(user1.avatar)}}
size={40}
/>
{/* <Text>Email:{user1.email}</Text> */}
</View>
),
}}/>
<Drawer.Screen name="updateprofile" component={updateprofile}
options={{
title:'Update Profile',
headerTitleAlign:'left',
headerRight:()=>(
<View style={{marginEnd:10,flexDirection:'row'}}>
<Text style={{paddingRight:15,paddingTop:13,fontWeight:"normal",}}>{user1.email}</Text>
<Avatar.Image
source={{ uri:base64.decode(user1.avatar)}}
size={40}
/>
{/* <Text>Email:{user1.email}</Text> */}
</View>
),
}}/>
<Drawer.Screen name="Profile" component={Profile} />
</Drawer.Navigator>
);
}
My drawer navigator is working fine I want to add a bottom tab navigator its code is below:
const Tab = createMaterialBottomTabNavigator();
function MyTabs() {
return (
<Tab.Navigator
activeColor="#e91e63"
barStyle={{ backgroundColor: 'tomato' }}
>
<Tab.Screen
name="homes"
component={DrwaerNav}
options={{
tabBarLabel: 'Home',
tabBarIcon: ({ color }) => (
<MaterialCommunityIcons name="home" color={color} size={26} />
),
}}
/>
<Tab.Screen
name="Updates"
component={updates}
options={{
tabBarLabel: 'Updates',
tabBarIcon: ({ color }) => (
<MaterialCommunityIcons name="bell" color={color} size={26} />
),
}}
/>
<Tab.Screen
name="Profile"
component={Profile}
options={{
tabBarLabel: 'Profile',
tabBarIcon: ({ color }) => (
<MaterialCommunityIcons name="account" color={color} size={26} />
),
}}
/>
</Tab.Navigator>
);
}
export default function App() {
return (
<NavigationContainer>
<Stack.Navigator initialRouteName="Login" screenOptions={{
headerShown: false
}}>
{/* <Stack.Navigator initialRouteName="SignUp" headerShown="false"> */}
<Stack.Screen name="Login" component={Login} />
<Stack.Screen name="SignUp" component={SignUp} />
<Stack.Screen name="dashboard" component={DrwaerNav} />
</Stack.Navigator>
</NavigationContainer>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
Please try below code with basic setup
import React from 'react'
import {NavigationContainer} from '#react-navigation/native';
import { createStackNavigator } from '#react-navigation/stack'
import { createDrawerNavigator } from '#react-navigation/drawer'
import { createBottomTabNavigator } from '#react-navigation/bottom-tabs'
import { View, Text } from 'react-native'
const Stack = createStackNavigator()
const DrawerStack = createDrawerNavigator()
const BottomStack = createBottomTabNavigator()
// Drawer code
function AppDrawerStack() {
return (
<DrawerStack.Navigator drawerContent={props => <DrawerView {...props} />}>
<DrawerStack.Screen name='AppBottomStack' component={AppBottomStack} />
</DrawerStack.Navigator>
)
}
function DrawerView() {
return (
<View>
<Text>
Drawer View
</Text>
</View>
)
}
// Bottom Stack Part
function AppBottomStack() {
return (
<BottomStack.Navigator>
<BottomStack.Screen
name='BottomScreenOne'
component={BottomScreenOne}
/>
<BottomStack.Screen
name='BottomScreenTwo'
component={BottomScreenTwo}
/>
</BottomStack.Navigator>
)
}
function BottomScreenOne() {
return (
<View>
<Text>
BottomScreenOne
</Text>
</View>
)
}
function BottomScreenTwo() {
return (
<View>
<Text>
BottomScreenTwo
</Text>
</View>
)
}
export default function App() {
return (
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen name="AppDrawerStack" component={AppDrawerStack} />
</Stack.Navigator>
</NavigationContainer>
)
}
Please follow this GitHub repo here I have combined drawer, bottom and stack navigation
https://github.com/Gyanprakash73/DTSNavigator
Otherwise, Follow this below code
App.js
import 'react-native-gesture-handler';
import React from 'react';
import {createStackNavigator} from '#react-navigation/stack';
import {NavigationContainer} from '#react-navigation/native';
import DrawerNavigator from './src/navigation/DrawerNavigator';
const Stack = createStackNavigator();
const App = () => {
return (
<NavigationContainer>
<Stack.Navigator initialRouteName="DrawerNavigator">
<Stack.Screen
name="DrawerNavigator"
component={DrawerNavigator}
options={{headerShown: false}}
/>
</Stack.Navigator>
</NavigationContainer>
);
};
export default App;
DrawerNavigator.js
import * as React from 'react';
import {View, StyleSheet, Image, Text, TouchableOpacity} from 'react-native';
import {
createDrawerNavigator,
DrawerContentScrollView,
DrawerItemList,
} from '#react-navigation/drawer';
import MyRewardsStackNavigator from './stack-navigators/MyRewardsStackNavigator';
import LocationsStackNavigator from './stack-navigators/LocationsStackNavigator';
import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons';
import BottomTabNavigator from './BottomTabNavigator';
const Drawer = createDrawerNavigator();
const DrawerNavigator = () => {
const DrawerHeaderContent = props => {
return (
<DrawerContentScrollView contentContainerStyle={{flex: 1}}>
<View
style={{
backgroundColor: '#4f4f4f',
height: 100,
justifyContent: 'center',
alignItems: 'center',
top: -5,
}}>
<Text style={{color: '#fff'}}>Home</Text>
</View>
<DrawerItemList {...props} />
</DrawerContentScrollView>
);
};
return (
<Drawer.Navigator
screenOptions={{
drawerStyle: {
backgroundColor: '#fff',
},
}}
drawerContent={DrawerHeaderContent}>
<Drawer.Screen
name={'BottomTabNavigator'}
component={BottomTabNavigator}
options={{
drawerLabel: 'Home Screen',
drawerIcon: ({focused, size, color}) => (
<MaterialCommunityIcons name="home" color={color} size={size} />
),
}}
/>
<Drawer.Screen
name={'MyRewardsStackNavigator'}
component={MyRewardsStackNavigator}
options={{
drawerLabel: 'My Rewards Screen',
drawerIcon: ({focused, size, color}) => (
<MaterialCommunityIcons name="firewire" color={color} size={size} />
),
}}
/>
<Drawer.Screen
name={'LocationsStackNavigator'}
component={LocationsStackNavigator}
options={{
drawerLabel: 'Locations Screen',
drawerIcon: ({focused, size, color}) => (
<MaterialCommunityIcons
name="location-enter"
color={color}
size={size}
/>
),
}}
/>
</Drawer.Navigator>
);
};
const styles = StyleSheet.create({
headerLeft: {
marginLeft: 15,
},
headerTitle: {
color: 'white',
fontSize: 18,
fontWeight: '500',
},
headerRight: {
marginRight: 15,
},
// drawer content
drawerLabel: {
fontSize: 14,
},
drawerLabelFocused: {
fontSize: 14,
color: '#551E18',
fontWeight: '500',
},
drawerItem: {
height: 50,
justifyContent: 'center',
},
drawerItemFocused: {
backgroundColor: '#ba9490',
},
});
export default DrawerNavigator;
BottomTabNavigator.js
import * as React from 'react';
import {createBottomTabNavigator} from '#react-navigation/bottom-tabs';
import {Text, StyleSheet, View} from 'react-native';
import HomeStackNavigator from './stack-navigators/HomeStackNavigator';
import BookStackNavigator from './stack-navigators/BookStackNavigator';
import ContactStackNavigator from './stack-navigators/ContactStackNavigator';
import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons';
const Tab = createBottomTabNavigator();
const BottomTabNavigator = () => {
return (
<Tab.Navigator initialRouteName="HomeScreen" screenOptions={{}}>
<Tab.Screen
name={'HomeStackNavigator'}
component={HomeStackNavigator}
options={{
tabBarLabel: 'Home Screen',
headerShown: false,
tabBarIcon: ({color, size}) => (
<MaterialCommunityIcons name="home" color={color} size={size} />
),
}}
/>
<Tab.Screen
name={'BookStackNavigator'}
component={BookStackNavigator}
options={{
tabBarLabel: 'Book Screen',
headerShown: false,
tabBarIcon: ({color, size}) => (
<MaterialCommunityIcons
name="book-open-blank-variant"
color={color}
size={size}
/>
),
}}
/>
<Tab.Screen
name={'ContactStackNavigator'}
component={ContactStackNavigator}
options={{
tabBarLabel: 'Contact Screen',
headerShown: false,
tabBarIcon: ({color, size}) => (
<MaterialCommunityIcons name="contacts" color={color} size={size} />
),
}}
/>
</Tab.Navigator>
);
};
const styles = StyleSheet.create({
tabBarLabel: {
color: '#292929',
fontSize: 12,
},
tabContainer: {
height: 60,
},
});
export default BottomTabNavigator;

how to create a drawer using React Native?

I want to create a drawer that appears only on my homescreen,
had tried using React Native side menu but that just hides the drawer behind then tried using createdrawernavigator
but I have a bottomtabnavigator inside stacknavigator, and am stuck on how to implement drawer navigator on top of that
below is my navigation.js
const RootStack = createStackNavigator();
const Tab = createBottomTabNavigator();
const AuthStack = createStackNavigator();
// const Drawer = createDrawerNavigator();
function AuthNavigator() {
function LogoTitle(props) {
return (
<View
style={{
flexDirection: 'row',
alignItems: 'center',
marginVertical: 10,
}}>
<Image
style={{width: 31.44, height: 31.2}}
source={Images.symptomcheck_bot1}
/>
<Text
style={{
marginLeft: 10,
color: '#FFFFFF',
fontStyle: 'italic',
fontSize: 14,
}}>
{props.children}
</Text>
</View>
);
}
return (
<AuthStack.Navigator initialRouteName="login">
<AuthStack.Screen
name="login"
component={LoginScreen}
options={{headerShown: false}}
/>
<AuthStack.Screen
name="otp"
component={OtpScreen}
options={{headerShown: false}}
/>
<AuthStack.Screen name="addchild" component={AddChild} />
<AuthStack.Screen
name="acceptinvitescreen"
component={AcceptInviteScreen}
/>
<AuthStack.Screen
name="Home"
component={BottomTabBar}
options={{
headerShown: false,
}}
/>
<AuthStack.Screen
name="online"
component={OnlineConsultationWebviewScreen}
/>
<AuthStack.Screen
name="actual"
component={ActualConsultationWebviewScreen}
/>
<AuthStack.Screen name="baby" component={BabyAccuteIllnessScreen} />
<AuthStack.Screen name="vaccinelist" component={VaccinationListScreen} />
<AuthStack.Screen
name="vaccinationdetail"
component={VaccinationDetailScreen}
/>
<AuthStack.Screen
name="vaccinereadmore"
component={VaccinationDetailreadMoreScreen}
/>
<AuthStack.Screen
name="symptomChecker"
component={SymptomChecker}
options={{
gesturesEnabled: false,
headerBackTitleVisible: false,
headerBackTitle: null,
title: 'Symptom Checker',
headerStyle: {
backgroundColor: '#FE017E',
},
headerTintColor: '#fff',
headerTitleStyle: {
fontWeight: '300',
fontSize: 14,
fontStyle: 'italic',
width: '100%',
},
headerTitleContainerStyle: {
left: Platform.OS === 'ios' ? -70 : 50,
},
headerTitle: (props) => <LogoTitle {...props} />,
}}
/>
<AuthStack.Screen
name="symptomCheckerSearch"
component={SymptomCheckerSearch}
options={{
gesturesEnabled: false,
headerBackTitleVisible: false,
headerBackTitle: null,
title: 'Hi! I’m ISHA, your health care assistant',
headerStyle: {
backgroundColor: '#FE017E',
},
headerTintColor: '#fff',
headerTitleStyle: {
fontWeight: '300',
fontSize: 14,
fontStyle: 'italic',
},
headerTitleContainerStyle: {
left: Platform.OS === 'ios' ? 0 : 50,
},
headerTitle: (props) => <LogoTitle {...props} />,
}}
/>
<AuthStack.Screen
name="symptomCheckerQA"
component={SymptomCheckerQA}
options={{
gesturesEnabled: false,
headerBackTitleVisible: false,
headerBackTitle: null,
title: 'Hi! I’m ISHA, your health care assistant',
headerStyle: {
backgroundColor: '#FE017E',
},
headerTintColor: '#fff',
headerTitleStyle: {
fontWeight: '300',
fontSize: 14,
fontStyle: 'italic',
},
headerTitleContainerStyle: {
left: Platform.OS === 'ios' ? 0 : 50,
},
headerTitle: (props) => <LogoTitle {...props} />,
}}
/>
<AuthStack.Screen
name="symptomCheckerAssessmentReport"
component={symptomCheckerAssessmentReport}
options={{
gesturesEnabled: false,
headerBackTitleVisible: false,
headerBackTitle: null,
title: 'Assessment Report',
headerStyle: {
backgroundColor: '#FE017E',
},
headerTintColor: '#fff',
headerTitleStyle: {
fontWeight: '300',
fontSize: 14,
fontStyle: 'italic',
},
headerTitleContainerStyle: {
left: Platform.OS === 'ios' ? -70 : 50,
},
}}
/>
<AuthStack.Screen
name="symptomCheckerDetailReport"
component={SymptomCheckerDetailReport}
options={{
gesturesEnabled: false,
headerBackTitleVisible: false,
headerBackTitle: null,
title: 'Detail Report',
headerStyle: {
backgroundColor: '#FE017E',
},
headerTintColor: '#fff',
headerTitleStyle: {
fontWeight: '300',
fontSize: 14,
fontStyle: 'italic',
},
headerTitleContainerStyle: {
left: Platform.OS === 'ios' ? -100 : 50,
},
}}
/>
<AuthStack.Screen
name="plactivityplanner"
component={PLActivityPlanner}
options={{headerShown: false}}
/>
<AuthStack.Screen
name="plactivityplannerdetail"
component={PLActivityPlannerDetail}
options={{headerShown: false}}
/>
<AuthStack.Screen
name="plactivityplannerreport"
component={PLActivityPlannerReport}
options={{headerShown: false}}
/>
<AuthStack.Screen
name="todaysgoal"
component={TodaysGoalScreen}
options={{headerShown: false}}
/>
<AuthStack.Screen
name="mealdesc"
component={MealDescriptionScreen}
options={{headerShown: false}}
/>
<AuthStack.Screen
name="nutritionassessment"
component={NutritionAssessment}
options={{
gesturesEnabled: false,
headerBackTitleVisible: false,
headerBackTitle: null,
title: 'Nutrition Assessment',
headerStyle: {
backgroundColor: '#FE017E',
},
headerTintColor: '#fff',
headerTitleStyle: {
fontWeight: '300',
fontSize: 20,
width: '100%',
},
headerTitleContainerStyle: {
left: Platform.OS === 'ios' ? -70 : 50,
},
}}
/>
<AuthStack.Screen
name="nutritionassessmentreport"
component={NutritionAssessmentReport}
options={{
gesturesEnabled: false,
headerBackTitleVisible: false,
headerBackTitle: null,
title: 'NutriCheck',
headerStyle: {
backgroundColor: '#FE017E',
},
headerTintColor: '#fff',
headerTitleStyle: {
fontWeight: '300',
fontSize: 20,
width: '100%',
},
headerTitleContainerStyle: {
left: Platform.OS === 'ios' ? -70 : 50,
},
}}
/>
</AuthStack.Navigator>
);
}
function BottomTabBar() {
return (
<Tab.Navigator
lazy={false}
initialRouteName="Home"
tabBarOptions={{
labelStyle: {
color: '#FF1493',
fontSize: 12,
},
}}>
<Tab.Screen
name="Home"
// uncommnet below line to see new Home Tab
component={HomeTabScreen}
// uncomment below see old Home Tab
// component={HomeScreen}
options={{
tabBarLabel: 'Home',
tabBarIcon: ({color, size}) => (
<MaterialIcon name="home" color="#FF1493" size={30} />
),
}}
/>
<Tab.Screen
name="Consult"
component={ConsultationHomeScreen}
initialParams={{
uri: 'https://qa.parentlane.com/doctors/launch-home?app_type=0',
}}
options={{
tabBarLabel: 'Consult',
tabBarIcon: ({color, size}) => (
<FontAwesomeIcon name="stethoscope" color="#FF1493" size={30} />
),
}}
/>
<Tab.Screen
name="Plans"
component={PlansTabScreen}
options={{
tabBarLabel: 'Plans',
tabBarIcon: ({color, size}) => (
<MaterialCommunityIcons
name="crown-outline"
color="#FF1493"
size={30}
/>
),
}}
/>
<Tab.Screen
name="Chat"
component={ChatTabScreen}
options={{
tabBarLabel: 'Chat',
tabBarIcon: ({color, size}) => (
<MaterialCommunityIcons
name="chat-outline"
color="#FF1493"
size={30}
/>
),
}}
/>
</Tab.Navigator>
);
}
function RootNavigator() {
function LogoTitle(props) {
return (
<View
style={{
flexDirection: 'row',
alignItems: 'center',
marginVertical: 10,
}}>
<Image
style={{width: 31.44, height: 31.2}}
source={Images.symptomcheck_bot1}
/>
<Text
style={{
marginLeft: 10,
color: '#FFFFFF',
fontStyle: 'italic',
fontSize: 14,
}}>
{props.children}
</Text>
</View>
);
}
return (
<RootStack.Navigator initialRouteName="Home">
<RootStack.Screen
name="Home"
component={BottomTabBar}
options={{headerShown: false}}
/>
<RootStack.Screen
name="online"
component={OnlineConsultationWebviewScreen}
/>
<RootStack.Screen
name="actual"
component={ActualConsultationWebviewScreen}
/>
<RootStack.Screen name="baby" component={BabyAccuteIllnessScreen} />
<RootStack.Screen name="vaccinelist" component={VaccinationListScreen} />
<RootStack.Screen
name="vaccinationdetail"
component={VaccinationDetailScreen}
/>
<RootStack.Screen
name="vaccinereadmore"
component={VaccinationDetailreadMoreScreen}
/>
<RootStack.Screen
name="symptomChecker"
component={SymptomChecker}
options={{
gesturesEnabled: false,
headerBackTitleVisible: false,
headerBackTitle: null,
title: 'Symptom Checker',
headerStyle: {
backgroundColor: '#FE017E',
},
headerTintColor: '#fff',
headerTitleStyle: {
fontWeight: '300',
fontSize: 14,
fontStyle: 'italic',
width: '100%',
},
headerTitleContainerStyle: {
left: Platform.OS === 'ios' ? -70 : 50,
},
headerTitle: (props) => <LogoTitle {...props} />,
}}
/>
<RootStack.Screen
name="symptomCheckerSearch"
component={SymptomCheckerSearch}
options={{
gesturesEnabled: false,
headerBackTitleVisible: false,
headerBackTitle: null,
title: 'Hi! I’m ISHA, your health care assistant',
headerStyle: {
backgroundColor: '#FE017E',
},
headerTintColor: '#fff',
headerTitleStyle: {
fontWeight: '300',
fontSize: 14,
fontStyle: 'italic',
},
headerTitleContainerStyle: {
left: Platform.OS === 'ios' ? 0 : 50,
},
headerTitle: (props) => <LogoTitle {...props} />,
}}
/>
<RootStack.Screen
name="symptomCheckerQA"
component={SymptomCheckerQA}
options={{
gesturesEnabled: false,
headerBackTitleVisible: false,
headerBackTitle: null,
title: 'Hi! I’m ISHA, your health care assistant',
headerStyle: {
backgroundColor: '#FE017E',
},
headerTintColor: '#fff',
headerTitleStyle: {
fontWeight: '300',
fontSize: 14,
fontStyle: 'italic',
},
headerTitleContainerStyle: {
left: Platform.OS === 'ios' ? 0 : 50,
},
headerTitle: (props) => <LogoTitle {...props} />,
}}
/>
<RootStack.Screen
name="symptomCheckerAssessmentReport"
component={symptomCheckerAssessmentReport}
options={{
gesturesEnabled: false,
headerBackTitleVisible: false,
headerBackTitle: null,
title: 'Assessment Report',
headerStyle: {
backgroundColor: '#FE017E',
},
headerTintColor: '#fff',
headerTitleStyle: {
fontWeight: '300',
fontSize: 14,
fontStyle: 'italic',
},
headerTitleContainerStyle: {
left: Platform.OS === 'ios' ? -70 : 50,
},
}}
/>
<RootStack.Screen
name="symptomCheckerDetailReport"
component={SymptomCheckerDetailReport}
options={{
gesturesEnabled: false,
headerBackTitleVisible: false,
headerBackTitle: null,
title: 'Detail Report',
headerStyle: {
backgroundColor: '#FE017E',
},
headerTintColor: '#fff',
headerTitleStyle: {
fontWeight: '300',
fontSize: 14,
fontStyle: 'italic',
},
headerTitleContainerStyle: {
left: Platform.OS === 'ios' ? -100 : 50,
},
}}
/>
<RootStack.Screen
name="plactivityplanner"
component={PLActivityPlanner}
options={{headerShown: false}}
/>
<RootStack.Screen
name="plactivityplannerdetail"
component={PLActivityPlannerDetail}
options={{headerShown: false}}
/>
<RootStack.Screen
name="plactivityplannerreport"
component={PLActivityPlannerReport}
options={{headerShown: false}}
/>
<RootStack.Screen
name="todaysgoal"
component={TodaysGoalScreen}
options={{headerShown: false}}
/>
<RootStack.Screen
name="mealdesc"
component={MealDescriptionScreen}
options={{headerShown: false}}
/>
<RootStack.Screen
name="nutritionassessment"
component={NutritionAssessment}
options={{
gesturesEnabled: false,
headerBackTitleVisible: false,
headerBackTitle: null,
title: 'Nutrition Assessment',
headerStyle: {
backgroundColor: '#FE017E',
},
headerTintColor: '#fff',
headerTitleStyle: {
fontWeight: '300',
fontSize: 20,
width: '100%',
},
headerTitleContainerStyle: {
left: Platform.OS === 'ios' ? -70 : 50,
},
}}
/>
<RootStack.Screen
name="nutritionassessmentreport"
component={NutritionAssessmentReport}
options={{
gesturesEnabled: false,
headerBackTitleVisible: false,
headerBackTitle: null,
title: 'NutriCheck',
headerStyle: {
backgroundColor: '#FE017E',
},
headerTintColor: '#fff',
headerTitleStyle: {
fontWeight: '300',
fontSize: 20,
width: '100%',
},
headerTitleContainerStyle: {
left: Platform.OS === 'ios' ? -70 : 50,
},
}}
/>
<RootStack.Screen
name="developmentscreening"
component={DevelopmentScreeningInfo}
options={{headerShown: false}}
/>
<RootStack.Screen
name="login"
component={LoginScreen}
options={{headerShown: false}}
/>
<RootStack.Screen
name="otp"
component={OtpScreen}
options={{headerShown: false}}
/>
</RootStack.Navigator>
);
}
// function DrawerRootNavigator() {
// return (
// <Drawer.Navigator>
// <Drawer.Screen name="Home" component={RootNavigator} />
// </Drawer.Navigator>
// );
// }
// function DrawerAuthNavigator(){
// return(
// <Drawer.Navigator>
// <Drawer.Screen name="login" component={AuthNavigator}/>
// </Drawer.Navigator>
// )
// }
export default function SwitchRootNavigator(props) {
const signedIn = props.signedIn;
return (
<NavigationContainer>
{signedIn != null &&
signedIn != undefined &&
signedIn != '' &&
signedIn != {} ? (
<RootNavigator />
) : (
<AuthNavigator />
)}
</NavigationContainer>
);
}
Could anyone please guide me how do I wrap my "Home" with a drawernavigator which would have a button navigating to the login screen?
have been stuck since long, any leads would be great.
I might have overcomplicated things in my initial comment. Those screens you would like to have a TabBar on; put those into a bottomTabNavigator. Screens with drawer on are placed into a different drawerNavigator; and these navigators are then nested in a stackNavigator which holds the rest of the screens of your app.
// Navigators
const Tab = createBottomTabNavigator();
const Drawer = createDrawerNavigator();
const Stack = createStackNavigator();
// screens you want bottom tabs on
function TabScreens() {
return (
<Tab.Navigator>
<Tab.Screen name="A" component={A} />
<Tab.Screen name="B" component={B} />
</Tab.Navigator>
);
}
// screens you want drawer on
function DrawerScreens() {
return (
<Drawer.Navigator>
<Drawer.Screen name="C" component={C} />
<Drawer.Screen name="D" component={D} />
</Tab.Navigator>
);
}
// and both Drawer and Tabs are then nested into Stack
function App() {
return (
<Stack.Navigator>
<Stack.Screen name="Home" component={TabScreens} />
<Stack.Screen name="Drawer" component={DrawerScreens} />
<Stack.Screen name="E" component={E} />
<Stack.Screen name="F" component={F} />
<Stack.Screen name="G" component={G} />
</Stack.Navigator>
);
}
To navigate between the screens call:
navigation.navigate("navigatorName",{screen: "screenName"})
I might have overcomplicated things in my initial comment.
Example on how it is done with bottomTabNavigator instead of a drawer can be found here:
https://reactnavigation.org/docs/hiding-tabbar-in-screens/

React Native Navigation Custom Border

I am a beginner in React Native. I want to configure the React Navigation 5.x with custom style. And I am unable to trim border-bottom like following. Please help me with This.
Custom Style for React Navigation
My Current Code:
function StackNavigator() {
return (
<NavigationContainer>
<Stack.Navigator
screenOptions={{
headerStyle: styles.header,
headerBackImage: () => (
<Image
style={styles.headerBack}
source={require("../assets/icons/64x/chevron-left.png")}
/>
),
headerLeftContainerStyle: {
alignItems: "flex-start",
paddingHorizontal: theme.sizes.padding / 2
},
headerTitleStyle: styles.headerTitle
}}
>
<Stack.Screen
name="Login"
component={LoginScreen}
options={{ headerShown: true }}
/>
</Stack.Navigator>
</NavigationContainer>
);
}
const styles = StyleSheet.create({
header: {
height: theme.sizes.base * 5,
backgroundColor: Colors.white,
borderWidth: 0,
elevation: 0,
borderBottomWidth: 1,
borderBottomColor: Colors.grayLight
},
headerBack: {
height: 20,
width: 20
},
headerTitle: {
fontSize: 18,
fontFamily: "Quicksand",
letterSpacing: -1
}
});
Thank you in advance.
You can add this style to the cardStyle property of the screenOptions:
function StackNavigator() {
<NavigationContainer>
<Stack.Navigator
screenOptions={{
cardStyle : { backgroundColor : 'lightgray', margin : 15 },
headerStyle: styles.header,
headerBackImage: () => (
<Image
style={styles.headerBack}
source={require("../assets/icons/64x/chevron-left.png")}
/>
),
headerLeftContainerStyle: {
alignItems: "flex-start",
paddingHorizontal: theme.sizes.padding / 2
},
headerTitleStyle: styles.headerTitle
}}
>
<Stack.Screen
name="Login"
component={LoginScreen}
options={{ headerShown: true }}
/>
</Stack.Navigator>
</NavigationContainer>
}
Which will produce something like this:

Resources