React Stack Navigator V5 does not response when headerMode="float" - react-native

im useing react-native-drawer v5, and in the header i have hamburger icon.
when headerMode!=float -> its worked like expected and open and close the drawer.
when i change to headerMode="float", the header is not response to the click, and nothing happend,
note that im checking it on Android device. I dont need to know about IOS..
here my stack and drawer nav:
import...
const MainStack = createStackNavigator();
const Drawer = createDrawerNavigator();
const stackScreenOptions = {
cardStyleInterpolator: CardStyleInterpolators.forHorizontalIOS,
gestureEnabled: true,
gestureDirection: "horizontal",
headerTitleAlign: "center",
headerStyle: {
borderBottomWidth: 0.5,
elevation: 2,
borderColor: "white",
backgroundColor: "#1d2731",
height: 82,
},
headerTitleStyle: {
color: "white",
},
};
const MainStackScreen = ({ navigation }) => (
<MainStack.Navigator headerMode="float" screenOptions={stackScreenOptions}>/////////HERE THE PROBLEM OCCURE -> when i declare headerMode="float
<MainStack.Screen
name="Main"
component={MainScreen}
options={{
title: "ליאור",
headerLeft: () => (
<Icon
style={{ position: "absolute", left: 15 }}
name="bars"
color="white"
size={30}
onPress={() => {
navigation.openDrawer();
}}
/>
),
}}
/>
<MainStack.Screen name="MeetingPicker" component={MeetingPicker} />
<MainStack.Screen name="MyMeetings" component={UserHistory} />
<MainStack.Screen name="About" component={AboutScreen} />
<MainStack.Screen name="Gallery" component={GalleryScreen} />
<MainStack.Screen name="Location" component={LocationScreen} />
<MainStack.Screen name="Logout" component={LogoutModal} />
</MainStack.Navigator>
);
export const DrawerNavigator = () => {
return (
<Drawer.Navigator drawerStyle={styles.drawerStyle} drawerContent={props => <DrawerContent {...props} />}>
<Drawer.Screen name="Main" component={MainStackScreen} />
</Drawer.Navigator>
);
};

Related

Independent stack navigation outside tab and drawer navigation in React-Native

I use
react-native:0.68.2
react-navigation/bottom-tabs:6.3.1
react-navigation/drawer:6.4.1
react-navigation/native:6.0.10
react-navigation/stack:6.2.1
And I have next navigation structure:
<Drawer.Navigator>
<Tab.Navigator>
<Stack.Navigator>
<Screen1>
<Screen2>
</Stack.Navigator>
</Tab.Navigator>
</Drawer.Navigator>
It looks like drawer slide menu from left side and bottom tabs on the main screen. You can see short video of it by next link
What do I want
I want to open new screen from Screen1 like independent screen (without tabs and drawer). It looks like new Activity in Android or new view controller in iOS.
you need to try this
const TabStack = () => {
return (
<Tab.Navigator
initialRouteName="LiveRate"
screenOptions={{
tabBarActiveBackgroundColor: colors.activeTabColor,
tabBarInactiveBackgroundColor: colors.inactiveTabColor,
tabBarStyle: {
backgroundColor: '#f46023',
height:60
},
}}>
<Tab.Screen
name="LiveRate"
component={LiveRateScreen}
options={{
tabBarLabel: () => {
return (<Text style={{color:'white', fontSize:12, marginBottom:5}}>Live Rate</Text>)
},
headerShown: false,
tabBarIcon: ({ focused }) => (
<Image
source={
focused
? Images.liverate
: Images.liverate
}
style={{
width: 30,
height: 30,
resizeMode:'contain'
// padding:5
}}
/>
),
}}
/>
<Tab.Screen
name="AboutUs"
component={AboutUsScreen}
options={{
tabBarLabel: () => {
return (<Text style={{color:'white', fontSize:12, marginBottom:5}}>About Us</Text>)
},
headerShown: false,
tabBarIcon: ({ focused, color, size }) => (
<Image
source={
focused
? Images.aboutus
: Images.aboutus
}
style={{
width: 30,
height: 30,
resizeMode:'contain'
// padding:5
}}
/>
),
}}
/>
<Tab.Screen
name="booking"
component={BookingNumberScreen}
options={{
tabBarLabel: () => {
return (<Text style={{color:'white', fontSize:12, marginBottom:5}}>Booking Number</Text>)
},
headerShown: false,
tabBarIcon: ({ focused, color, size }) => (
<Image
source={
focused
? Images.booking
: Images.booking
}
style={{
width: 30,
height: 30,
resizeMode:'contain'
}}
/>
),
}}
/>
<Tab.Screen
name="notification"
component={NotificationScreen}
options={{
tabBarLabel: () => {
return (<Text style={{color:'white', fontSize:12, marginBottom:5}}>Notification</Text>)
},
headerShown: false,
tabBarIcon: ({ focused, color, size }) => (
<Image
source={
focused
? Images.notificationbell
: Images.notificationbell
}
style={{
width: 30,
height: 30,
resizeMode:'contain'
}}
/>
),
}}
/>
</Tab.Navigator>
);
};
const NavigationUtil = () => {
return (
<NavigationContainer ref={navigationRef}>
<Stack.Navigator initialRouteName="SlpashScreen">
<Stack.Screen
name="tabStack"
component={TabStack} <----- you also pass your drawer stack
options={{headerShown: false}}
/>
<Stack.Screen
name="Registration"
component={RegistrationScreen}
options={{headerShown: false}}
/>
<Stack.Screen
name="SlpashScreen"
component={SlpashScreen}
options={{headerShown: false}}
/>
</Stack.Navigator>
</NavigationContainer>
);
};
this is my code
hop it's working

How to align the drawer navigation items to bottom of the screen in react native?

I have a drawer navigation with permanent drawer type and I want to align the drawer items to bottom of the screen instead of the top.
Like this photo:
The code I used to align the did not work for me:
drawerStyle: {
backgroundColor: '#000',
width: 80,
justifyContent:'flex-end',
alignItems:'flex-end'
},
Code for: https://i.stack.imgur.com/Ulr2r.png
export default function App() {
const renderTabIcon = (sourceIcon) => () => {
return (
<Image
style={{
height: 20,
width: 20,
resizeMode: "contain",
}}
source={sourceIcon}
/>
);
};
return (
<NavigationContainer>
<Drawer.Navigator
initialRouteName="Home"
screenOptions={{
drawerStyle: {
width: 57,
},
drawerContentStyle: {
flexDirection: "column-reverse",
},
drawerLabel: "",
}}
>
<Drawer.Screen
name="Home"
component={HomeScreen}
options={{
drawerIcon: renderTabIcon(require("./home.png")),
}}
/>
<Drawer.Screen
name="Search"
component={SearchScreen}
options={{
drawerIcon: renderTabIcon(require("./search.png")),
}}
/>
</Drawer.Navigator>
</NavigationContainer>
);
}
More information: https://reactnavigation.org/docs/drawer-navigator/#screenoptions

How can we create a App header in reactNative

I have a requirement of showing a app header with hamburger icon on left , and dropDown Selection in middle , and icon on the right side and below this , I'm showing a search bar . All these has to be added in the header part. below the searchView basically ,I have a list . How can we create the custom header like that?
samplecode:
const Drawer = createDrawerNavigator();
function MyDrawer({ navigation }) {
return (
<Drawer.Navigator
initialRouteName='HomeScreen'
screenOptions={{
headerTitle: (props) => <HeaderComp {...props} />,
headerStyle: {
backgroundColor: '#051E42', //Set Header color
height: 100,
elevation: 15,
shadowColor: '#000'
},
headerRight: () => (
<TouchableOpacity style={{marginRight:10}}>
<Image style={{ height: 30, width: 30, resizeMode: 'contain' }}
source={require('./assets/cart_img.png')}
// source={{ uri: 'asset:/images/cart_img.png' }}
/>
</TouchableOpacity>
),
headerTintColor: 'white'
}}
>
<Drawer.Screen name="HomeScreen"
component={HomeScreen}
/>
<Drawer.Screen name="Profile" component={ProfileScreen} />
<Drawer.Screen name="Settings" component={Settings} />
</Drawer.Navigator>
);
}
export default function App() {
return (
<NavigationContainer>
<MyDrawer />
</NavigationContainer>
);
}
Header Component:
const HeaderComp = () => {
const [searchValue, setValue] = useState('');
return (
<View >
<Text style={style.headerTitle}>Custom Header</Text>
{/* <Text style={{top:20}}>dsfskdfsfdjhsfjhs</Text> */}
</View>
)
}
const style = StyleSheet.create({
headerTitle: {
fontWeight: 'bold',
alignItems: 'center',
color: 'white',
left: 60
}
})
export default HeaderComp;

React navigation v5, add a stack navigation to my application header

I'm using react navigation 5 to build my app navigation system.
I want to add a link to open Notifications scree:
I created a RenderHeaderRight component to override the right component of all my stacks
navigation :
const RenderHeaderRight = ({navigation}) => {
return (
<View style={{flexDirection: 'row-reverse'}}>
<TouchableHighlight
underlayColor={COLORS.DEFAULT}
style={styles.iConMenuContainer}
onPress={() => navigation.openDrawer()}>
<Image source={menu} style={styles.iConMenu} />
</TouchableHighlight>
<TouchableHighlight
underlayColor={COLORS.DEFAULT}
style={styles.notificationsIconContainer}
onPress={() => navigation.navigate('Notifications')}>
<>
<Image source={notifications} style={styles.notificationsIcon} />
<Image source={notifMark} style={styles.badge} />
</>
</TouchableHighlight>
</View>
);
};
In my HomeStackScreen i'm using the RenderHeaderRight :
const HomeStackScreen = ({navigation}) => (
<HomeStack.Navigator
initialRouteName="Home"
headerMode="screen"
mode="modal"
screenOptions={{
headerStyle: {
backgroundColor: COLORS.WHITE,
elevation: 0, // remove shadow on Android
shadowOpacity: 0, // remove shadow on iOS
borderBottomWidth: 0,
},
headerTintColor: COLORS.GREY,
headerTitleStyle: {
fontFamily: 'Montserrat-SemiBold',
fontWeight: '600',
fontSize: 18,
},
}}>
<HomeStack.Screen
name="Home"
component={Home}
options={{
title: 'Expanded',
headerLeft: () => <RenderHeaderLeft />,
headerRight: () => <RenderHeaderRight navigation={navigation} />,
headerTitleAlign: 'left',
}}
/>
<HomeStack.Screen name="HomeDetails" component={HomeDetails} />
</HomeStack.Navigator>
);
When i click on the Header right button to open the Notifications screen i got an error :
The action 'NAVIGATE' with payload {"name":"Notifications"} was not handled by any navigator.
Where shoud i create the stack navigation of Notifications screen ?
I triend to add the notifications like this :
const HomeStackScreen = ({navigation}) => (
<HomeStack.Navigator
initialRouteName="Home"
headerMode="screen"
mode="modal"
screenOptions={{
headerStyle: {
backgroundColor: COLORS.WHITE,
elevation: 0, // remove shadow on Android
shadowOpacity: 0, // remove shadow on iOS
borderBottomWidth: 0,
},
headerTintColor: COLORS.GREY,
headerTitleStyle: {
fontFamily: 'Montserrat-SemiBold',
fontWeight: '600',
fontSize: 18,
},
}}>
<HomeStack.Screen
name="Home"
component={Home}
options={{
title: 'Expanded',
headerLeft: () => <RenderHeaderLeft />,
headerRight: () => <RenderHeaderRight navigation={navigation} />,
headerTitleAlign: 'left',
}}
/>
<HomeStack.Screen name="HomeDetails" component={HomeDetails} />
<HomeStack.Screen
name="Notifications". // add the screen here
component={Notifications}
options={{headerShown: false}}
/>
</HomeStack.Navigator>
);
Removed the unnecessary styling / images
From my understanding you need to have a root Drawer.Navigator and from inside your Home screen, you need a Stack.Navigator there
This article explains the details of combining react-native-navigators
import React from "react"
import { TouchableHighlight, View, Text } from "react-native"
import { NavigationContainer } from "#react-navigation/native"
import { createDrawerNavigator } from "#react-navigation/drawer"
import { createStackNavigator } from "#react-navigation/stack"
const RenderHeaderRight = ({ navigation }) => {
return (
<View style={{ flexDirection: "row-reverse" }}>
<TouchableHighlight onPress={() => navigation.openDrawer()}>
<View>
<Text>Menu</Text>
</View>
</TouchableHighlight>
<TouchableHighlight onPress={() => navigation.navigate("Notifications")}>
<>
<View>
<Text>Image 1</Text>
</View>
<View>
<Text>Image 2</Text>
</View>
</>
</TouchableHighlight>
</View>
)
}
const Stack = createStackNavigator()
const Drawer = createDrawerNavigator()
const Notifications = () => (
<View>
<Text>Notifications</Text>
</View>
)
const Home = () => (
<View>
<Text>Home</Text>
</View>
)
const NotificationsScreen = () => (
<View>
<Text>Notifications Screen</Text>
</View>
)
const HomeScreen = () => (
<View>
<Stack.Navigator>
<Stack.Screen
name="Home"
component={Home}
options={({ navigation }) => ({
title: "Home",
headerRight: () => <RenderHeaderRight navigation={navigation} />,
})}
navigationOptions={({ navigation }) => ({
headerTitleAlign: "left",
})}
/>
<Stack.Screen name="Notifications" component={Notifications} />
</Stack.Navigator>
</View>
)
export default function App() {
return (
<NavigationContainer>
<Drawer.Navigator initialRouteName="Home">
<Drawer.Screen name="Home" component={HomeScreen} />
<Drawer.Screen name="Notifications" component={NotificationsScreen} />
</Drawer.Navigator>
</NavigationContainer>
)
}

react navigation 5 header is not shown

Using react navigation 5, I want to create a dynamic map for all my Drawer Screens, but the header is not shown with code:
<NavigationContainer>
<Drawer.Navigator
drawerContent={props => <DrawerContent {...props} />}>
{stackNavigItens.map((props, r) => (
<Drawer.Screen
key={r.name}
name={r.name}
component={({navigation}) => (
<Stack.Navigator
initialRouteName="Home"
headerMode="screen"
screenOptions={{
headerTitle: r.label,
headerStyle: {
backgroundColor: '#2e72e8',
},
headerTintColor: '#fff',
headerTitleStyle: {
fontWeight: 'bold',
},
}}
{...props}>
<Stack.Screen
name={r.name}
component={r.component}
options={{
title: r.label,
headerLeft: () => (
<Icon.Button
name="ios-menu"
size={25}
backgroundColor="#2e72e8"
onPress={() => {
navigation.openDrawer();
}}
/>
),
}}
{...props}
/>
</Stack.Navigator>
)}
{...props}
/>
))}
</Drawer.Navigator>
</NavigationContainer>
If I use every createStackNavigator in a const like below, and then call inside component of the Drawer the header shows correctly, I don't know Why ? I think maybe because of the {navigation} arrow function, but don't work too.
const HomeStackScreen = ({navigation}) => (
<HomeStack.Navigator
screenOptions={{
headerStyle: {
backgroundColor: '#2e72e8',
},
headerTintColor: '#fff',
headerTitleStyle: {
fontWeight: 'bold',
},
}}>
<HomeStack.Screen
name="Home"
component={HomeScreen}
options={{
headerLeft: () => (
<Icon.Button
name="ios-menu"
size={25}
backgroundColor="#2e72e8"
onPress={() => {
navigation.openDrawer();
}}
/>
),
}}
/>
</HomeStack.Navigator> );