How to hide tab bar in profile screen in react native? - reactjs

MyDrawer.js
function BottomTabNavigator() {
return (
<Tab.Navigator
initialRouteName="MainHome"
screenOptions={({ route }) => ({
headerShown: false,
tabBarLabelStyle: { fontSize: RFPercentage(1.60) },
tabBarInactiveTintColor: "#444444",
tabBarActiveTintColor: "#444444",
tabBarStyle: {
height: verticalScale(70),
paddingBottom: scale(10),
},
})}>
<Tab.Screen
name={"AccountsScreen"}
component={AccountsScreen}
options={{
title: "ACCOUNTS",
tabBarIcon: ({ color, size }) => (
<Image source={require("./img/bankTab.png")}
style={{ width: scale(30), height: scale(30), borderRadius: 0 }} />
),
}}
/>
<Tab.Screen
name={"McoinScreen"}
component={McoinScreen}
options={{
title: "MCOINS",
tabBarIcon: ({ color, size }) => (
<Image source={require("./img/dollar.png")}
style={{ width: scale(30), height: scale(30), borderRadius: 24 }} />
),
}}
/>
<Tab.Screen
name={"MainHome"}
component={MainHome}
options={{
title: "GET CASH",
tabBarIcon: ({ color, size }) => (
<Image source={require("./img/coinimg.png")}
style={{ width: scale(30), height: scale(30), borderRadius:0 }} />
),
}}
/>
<Tab.Screen
name={"ActivityScreen"}
component={ActivityScreen}
options={{
title: "ACTIVITY",
tabBarIcon: ({ color, size }) => (
<Image source={require("./img/activity.png")}
style={{ width: scale(30), height: scale(28), borderRadius: 0 }} />
),
}}
/>
<Tab.Screen
name={"ProfileScreen"}
component={ProfileScreen}
options={{
title: "PROFILE",
tabBarIcon: ({ color, size }) => (
<Image source={require("./img/profileimg.png")}
style={{ width: scale(26), height: scale(26), borderRadius:0 }} />
),
}}
/>
</Tab.Navigator>
);
}
const MyDrawer = () => {
return (
<Drawer.Navigator
drawerContent={props => <CustomeDrawer {...props} />}
initialRouteName="MainHome"
screenOptions={{
headerShown: false,
headerTransparent: false,
drawerActiveBackgroundColor: '#fff',
drawerActiveTintColor: '#fff',
drawerInactiveBackgroundColor: '#fff',
drawerStyle: {
width: scale(250),
},
drawerLabelStyle: { fontSize: RFPercentage(3), color: '#000' }
}}>
<Drawer.Screen
name="Home"
component={BottomTabNavigator}
options={{
title: "Get Cash",
drawerIcon: ({ color }) => (
<Image style={{ width: scale(25), height: scale(25), }}
source={require('./img/rupee.png')} />
)
}}
screenOptions={{
headerShown: true,
}}
/>
<Drawer.Screen
name="AccountsScreen"
component={AccountsScreen}
options={{
title: "Activity",
drawerIcon: ({ color }) => (
<Image style={{ width: scale(25), height: scale(25), }}
source={require("./img/page.png")} />
)
}}
screenOptions={{
headerShown: true,
}}
/>
<Drawer.Screen
name="FriendsScreen"
component={FriendsScreen}
options={{
title: "Friends",
drawerIcon: ({ color }) => (
<Image style={{ width: scale(25), height: scale(25), }}
source={require("./img/friends.png")} />
)
}}
screenOptions={{
headerShown: true,
}}
/>
<Drawer.Screen
name="ReferEnrnScreen"
component={ReferEnrnScreen}
options={{
title: "Refer & Earn",
drawerIcon: ({ color }) => (
<Image style={{ width: scale(25), height: scale(25), }}
source={require("./img/invite.png")} />
)
}}
screenOptions={{
headerShown: true,
}}
/>
<Drawer.Screen
name="ShopScreen"
component={ShopScreen}
options={{
title: "Shop",
drawerIcon: ({ color }) => (
<View style={{ flexDirection: 'row' }}>
<Image style={{ width: scale(25), height: scale(25), }}
source={require("./img/cart.png")} />
<View style={{
marginLeft:deviceWidth/2.10, position: 'absolute',
backgroundColor: "#2192FF", height: verticalScale(25),
width: scale(50), borderRadius: 5,
marginTop:verticalScale(5),
alignItems: 'center', justifyContent: 'center'
}}>
<Text style={{ color: "#fff",fontSize: RFPercentage(2) }}>New</Text>
</View>
</View>
)
}}
screenOptions={{
headerShown: true,
}}
/>
<Drawer.Screen
name="HelpScreen"
component={HelpScreen}
options={{
title: "Help",
drawerIcon: ({ color }) => (
<Image style={{ width: scale(25), height: scale(25),}}
source={require("./img/help.png")} />
)
}}
screenOptions={{
headerShown: true,
}}
/>
<Drawer.Screen
name="AboutusScreen"
component={AboutusScreen}
options={{
title: "About us",
drawerIcon: ({ color }) => (
<Image style={{ width: scale(25), height: scale(25)}}
source={require('./img/information.png')}/>
)
}}
screenOptions={{
headerShown: true,
}}
/>
</Drawer.Navigator>
);
}
App.js
const App = () => {
return (
<NavigationContainer>
<StatusBar backgroundColor="#000" />
<Stack.Navigator initialRouteName="Language" screenOptions={{ headerShown: false }}>
<Stack.Screen name="Splash" component={Splash} />
<Stack.Screen name="HomeScreen" component={HomeScreen} options={horizontalAnimation} />
<Stack.Screen name='PermissionPage' component={PermissionPage} options={horizontalAnimation} />
<Stack.Screen name='Login' component={Login} options={horizontalAnimation} />
<Stack.Screen name='MobileNumber' component={MobileNumber} options={verticalAnimation} />
<Stack.Screen name='PhoneSetting' component={PhoneSetting} />
<Stack.Screen name='ConformOtp' component={ConformOtp} options={verticalAnimation} />
<Stack.Screen name='StatusScreen' component={StatusScreen} options={horizontalAnimation} />
<Stack.Screen name='IncomeReceive' component={IncomeReceive} options={verticalAnimation} />
<Stack.Screen name='ReferralCode' component={ReferralCode} options={horizontalAnimation} />
<Stack.Screen name='Language' component={Language} options={horizontalAnimation} />
<Stack.Screen name='MainHome' component={MyDrawer} options={verticalAnimation} />
<Stack.Screen name='Notification' component={Notification} options={horizontalAnimation} />
<Stack.Screen name='KycForm' component={KycForm} options={horizontalAnimation} />
</Stack.Navigator>
</NavigationContainer>
);
}
Output:
here img active screen is get coin
but when I navigate to profile screen tab bar is hide
I'm creating a app,it's releted to loan
I want output like this if I click only profile screen then my tab bar is hide only for profile screen,
I don't know how to do that,
any one can help me ?
Thank you!

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

How to set the background color of Tab.Navigator in 2023?

The below code is for bottom tab navigator how do I change color of it!
I tried many things like changing the color of the background using style options tried screen options color but it was not working I even activetint color and other but it was only icons and all .If anyone can help me regarding this I would be grateful :)
<Tab.Navigator initialRouteName='CustomerStack'
screenOptions={({ route, }) => ({
tabBarIcon: ({ focused, color, size }) => {
let iconName;
let rn = route.name;
if (rn === "CustomDrawer") {
iconName = focused ? 'home' : 'home'
}
else if (rn === "CustomerStack") {
iconName = focused ? 'home' : 'home'
}
else if (rn === "Cart") {
iconName = focused ? 'shopping-cart' : 'shopping-cart'
} else if (rn === "Account") {
iconName = focused ? 'user' : 'user'
}
return <User name={iconName} size={size} color={color} />
},
})}>
This is what I tried
<Tab.Navigator
tabBarOptions={{
activeTintColor: '#e91e63',
style: {
backgroundColor: 'orange',
},
}}
>
<Tab.Screen name="Home" component={HomeScreen} />
<Tab.Screen name="Profile" component={ProfileScreen} />
</Tab.Navigator>
Try in this way:
<Tab.Navigator
screenOptions={{
tabBarStyle: {
backgroundColor: 'orange',
},
}}>
<Tab.Screen name="Home" component={HomeScreen} />
<Tab.Screen name="Profile" component={ProfileScreen} />
</Tab.Navigator>
According to the new official document you can check below code:
<Tab.Navigator
initialRouteName="Feed"
activeColor="white"
labelStyle={{ fontSize: 12 }}
shifting={true}
labeled={true}
>
<Tab.Screen
name="Feed"
component={Feed}
options={{
tabBarLabel: 'Home',
tabBarColor: 'red',
tabBarIcon: ({ color }) => (
<MaterialCommunityIcons name="home" color={color} size={26} />
),
}}
/>
<Tab.Screen
name="Notifications"
component={Notifications}
options={{
tabBarLabel: 'Updates',
tabBarColor: 'blue',
tabBarIcon: ({ color }) => (
<MaterialCommunityIcons name="bell" color={color} size={26} />
),
}}
/>
<Tab.Screen
name="Profile"
component={Profile}
options={{
tabBarLabel: 'Profile',
tabBarColor: 'green',
tabBarIcon: ({ color }) => (
<MaterialCommunityIcons name="account" color={color} size={26} />
),
}}
/>
</Tab.Navigator>
Set the background color of Tab.Navigator like below and also you can set tabBarActiveTintColor and tabBarInactiveTintColor so no need to set tintcolor on particular component:
import * as React from 'react';
import { Text, View } from 'react-native';
import { NavigationContainer } from '#react-navigation/native';
import { createBottomTabNavigator } from '#react-navigation/bottom-tabs';
function HomeScreen() {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>Home!</Text>
</View>
);
}
function SettingsScreen() {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>Settings!</Text>
</View>
);
}
const Tab = createBottomTabNavigator();
function MyTabs() {
return (
<Tab.Navigator screenOptions={{
tabBarStyle: {
backgroundColor: 'orange',
},
tabBarActiveTintColor: 'red',
tabBarInactiveTintColor: 'green',
}}>
<Tab.Screen name="Home" component={HomeScreen} />
<Tab.Screen name="Settings" component={SettingsScreen} />
</Tab.Navigator>
);
}
export default function App() {
return (
<NavigationContainer>
<MyTabs />
</NavigationContainer>
);
}

How to make Bottom tab transparent #react-navigation/bottom-tabs V6

I am using #react-navigation/bottom-tabs V6. I am trying to have transparent background on bottom. So far I cannot figure it out how to do it. Any ideas?
Result so far:
Code so far:
import { createBottomTabNavigator } from "#react-navigation/bottom-tabs";
const theme = {
colors: {
background: "transparent",
},
};
<NavigationContainer theme={theme}>
<Tab.Navigator
screenOptions={{ headerShown: false }}
tabBarOptions={{
style: {
backgroundColor: 'transparent',
borderTopWidth: 0,
elevation: 0,
}
}}
>
<Tab.Screen
name="HomeNavigation"
component={HomeNavigation}
options={{
tabBarLabel: "Home",
tabBarIcon: ({ color, size }) => <Icon />,
}}
/>
<Tab.Screen name="Home" component={Home} />
</Tab.Navigator>
</NavigationContainer>
How can I get rid off this background?
Ok so this is the solution
first:
<Tab.Navigator
screenOptions={{
headerShown: false,
tabBarStyle: {
position: "absolute",
left: 0,
bottom: 0,
elevation: 0,
borderTopWidth: 0,
},
}}
>
and also this have to be added to the container:
const theme = {
colors: {
background: "transparent",
},
};
<NavigationContainer theme={theme}>
<BottomUserNavigation />
</NavigationContainer>
The Tab.Navigator Not have props called tabBarOptions.
the tabBarOptions found in screenOptions.
You can do that ->
<NavigationContainer theme={theme}>
<Tab.Navigator
screenOptions={{
headerShown: false,
tabBarStyle: { backgroundColor: "transparent" },
}}
>
<Tab.Screen
name="HomeNavigation"
component={HomeNavigation}
options={{
tabBarLabel: "Home",
tabBarIcon: ({ color, size }) => <Icon />,
}}
/>
<Tab.Screen name="Home" component={Home} />
</Tab.Navigator>
</NavigationContainer>
Just add tabBarStyle props in the tabBarStyle and set the styles
Or you can add screen options for only one screen like that.
<NavigationContainer theme={theme}>
<Tab.Navigator
screenOptions={{
headerShown: false,
}}
>
<Tab.Screen
name="HomeNavigation"
component={HomeNavigation}
options={{
tabBarLabel: "Home",
tabBarIcon: ({ color, size }) => <Icon />,
tabBarStyle:{backgroundColor:"transparent"}
}}
/>
<Tab.Screen name="Home" component={Home} />
</Tab.Navigator>
</NavigationContainer>

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/

not able to logging out from the app in react native?

i am working on a react native project using redux. i have one stack navigator and one drawer navigator.
i am not able to logout from the app. i want to change store value while logging out. when i am dispatching the action from the logout onPress. it throws error: props.dispatch is not a function. how do i call. i tried many ways it always throwing an error. and how to set all reducers value to intial state while logout? Thank you in advance
App.js
<RootStack.Navigator screenOptions={{
headerShown: false
}}>
{/* <StatusBar backgroundColor={isLoading ? '#000000' : '#F3F3F3'} /> */}
{this.props.data.splashScreen.loading ?
(<RootStack.Screen name={'SplashScreen'} component={SplashScreen} />) :
this.props.data.login.isAuthorized ?
(<RootStack.Screen name="MainNavigator" component={MainNavigator} />)
:
(
<RootStack.Screen name="Login" component={MainStack} />)}
</RootStack.Navigator>
splashScreen and login are reducer store value
MainNavigator.js
const GradientHeader = (props) => (
<View style={{ backgroundColor: "transparent" }}>
<LinearGradient
colors={["#6CCFF6", "#596AB2"]}
start={{ x: 0, y: 0 }}
end={{ x: 1, y: 0 }}
style={
{
/* height: 128 */
/* height: Header.HEIGHT */
}
}
>
<Header {...props} />
</LinearGradient>
</View>
);
const DashboardStackScreen = ({ navigation }) => {
return (
<DashboardStack.Navigator
screenOptions={{
headerTitle: "Good Morning, John",
header: (props) => <GradientHeader {...props} />,
headerLeft: () => (
<TouchableOpacity onPress={navigation.openDrawer} style={{ padding: 20 }}>
<Image source={require("../assets/images/menu_bar.png")} style={{ width: 18, height: 12 }} />
</TouchableOpacity>
),
headerTransparent: true,
headerStyle: {
backgroundColor: "transparent",
},
headerTintColor: "#fff",
headerTitleStyle: { fontFamily: "OpenSans-SemiBold", fontSize: 20 },
}}
>
<DashboardStack.Screen name="Dashboard" component={Dashboard} />
</DashboardStack.Navigator>
);
};
export default ({ navigation }) => {
return (
<Drawer.Navigator
initialRouteName="Dashboard"
drawerContent={(props) => <DrawerContent {...props} />}
hideStatusBar={false}
focused={true}
labelStyle={{ fontSize: 14, fontFamily: "OpenSans-SemiBold" }}
drawerContentOptions={{ activeBackgroundColor: "#F1F1F1", activeTintColor: "#000000", inactiveTintColor: "#818181", itemStyle: { marginLeft: 0, paddingHorizontal: 10, width: "100%", borderRadius: 0 } }}
>
<Drawer.Screen
name="Dashboard"
component={DashboardStackScreen}
options={{
drawerIcon: ({ focused, size }) => <Image source={require("../assets/images/dashboard.png")} style={{ height: 17.78, width: 16 }} resizeMode="contain" />,
}}
/>
<Drawer.Screen
name="My Profile"
component={MyProfileStackScreen}
options={{
drawerIcon: ({ focused, size }) => <Image source={require("../assets/images/profile.png")} style={{ height: 16, width: 16 }} resizeMode="contain" />,
}}
/>
</Drawer.Navigator>
);
};
DrawerContent.js
import { resetData } from "../Storage/Storage";
export function DrawerContent(props) {
return (
<SafeAreaView style={styles.baseContainer}>
<KeyboardAvoidingView behaviour="padding" style={styles.baseContainer}>
<TouchableWithoutFeedback style={styles.baseContainer} onPress={Keyboard.dismiss}>
<View style={styles.baseContainer}>
<TouchableOpacity
style={{ flex: 2, alignItems: "center", justifyContent: "center" }}
onPress={() => {
props.navigation.navigate("Dashboard");
}}
>
<Image source={require("../assets/images/MJB_Logo.png")} style={{ width: 197, height: 59 }} />
</TouchableOpacity>
<View style={{ flex: 5 }}>
<DrawerContentScrollView {...props}>
<DrawerItemList {...props} />
<DrawerItem
labelStyle={{ fontSize: 14, fontFamily: "OpenSans-SemiBold" }}
activeBackgroundColor="#F1F1F1"
activeTintColor="#000000"
inactiveTintColor="#818181"
label="Logout"
icon={({ focused, color, size }) => {
return <Image source={require("../assets/images/logout.png")} style={{ height: 14.36, width: 14.36 }} resizeMode="contain" />;
}}
onPress={() => resetData()}
/>
</DrawerContentScrollView>
</View>
</View>
</TouchableWithoutFeedback>
</KeyboardAvoidingView>
</SafeAreaView>
);
}
Storage.js
export const resetData = async () => {
try {
//await AsyncStorage.removeItem('isRemembered')
await AsyncStorage.removeItem("userDetails");
} catch (e) {
// saving error
}
};

Resources