React navigation drawer v5x - react-native

I have tried to use minSwipeDistance property of drawer navigator.But It gives me error like Inviolant object.After trying a lot I didn't know what to do.Anyone can help me?
<NavigationContainer ref={navigationRef}>
<Loader loading={this.state.loading} close={()=>{}} />
<Drawer.Navigator
drawerStyle={{
width:Dimensions.get('window').width,
}} drawerContent={ ()=>{return(<MenuDrawer cats={this.state.cat_list} />)}}>
screenOptions={{
minSwipeDistance:0.5
}}
<Drawer.Screen
name="Main"
component={MainComponent}
/>
</Drawer.Navigator>
</NavigationContainer>

Related

NavigationContainer with multiple entries

I am trying to change an already develop react native application. I am new to react native. I am trying to write some Navigator
In App.js the original NavigationContained using GalioProvider. I know the traditional way to navigate to different pages but can anyone suggest me how to work with GalioProvider?
<NavigationContainer>
<GalioProvider theme={nowTheme}>
<Block flex>
<Screens />
</Block>
</GalioProvider>
</NavigationContainer>
I need to add below lines to it as well:
<Stack.Navigator>
<Stack.Screen name="Register" component={Register} />
<Stack.Screen name="Pro" component={Pro} />
</Stack.Navigator>
My final changes are like below:
<NavigationContainer>
<GalioProvider theme={nowTheme}>
<Block flex>
<Screens />
</Block>
</GalioProvider>
<Stack.Navigator>
<Stack.Screen name="Register" component={Register} />
<Stack.Screen name="Pro" component={Pro} />
</Stack.Navigator>
</NavigationContainer>
But I am getting below error:
Error: Another navigator is already registered for this container. You likely have multiple navigators under a single "NavigationContainer" or "Screen". Make sure each navigator is under a separate "Screen" container.

How to link from drawer Item to external website react-native-expo

I have here this drawer
return (
<NavigationContainer >
<Drawer.Navigator initialRouteName="MetalDetector" screenOptions={{
drawerStyle: {
backgroundColor: '#8e9dad',
width: 220
}
}}>
<Drawer.Screen name="MetalDetector" component={Home} options={{
headerRight: () => (
<Entypo name="sound" size={24} color="black" />
),
drawerLabel: '๐Ÿ›  MetalDetector'
}} />
<Drawer.Screen name="Settings" component={Settings} options={{drawerLabel: '๐Ÿ›  Settings'}} />
<Drawer.Screen name="Calibrate" component={Home} options={{drawerLabel: '๐Ÿ’ก Calibration'}}/>
<Drawer.Screen name="Feedback" component={Home} options={{drawerLabel: '๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ Feedback'}}/>
<Drawer.Screen name="Website" component={Home} options={{drawerLabel: '๐ŸŒŽ Website'}} />
</Drawer.Navigator>
</NavigationContainer>
);
}
I have added a few drawerScreens, like settings calibration feedback and website, but how can i make it that when someone clicks on website that he gets actually redirected to a website?
Currently I have
<Drawer.Screen name="Website" component={Home} options={{drawerLabel: '๐ŸŒŽ Website'}} />
I tried to add an onclick and onPress function but when removing the component I get an error and with using the component I cant link to anywhere
How can i fix this?
You can do this using drawerContent prop. Check out this Snack to see how it's done.

How to create a menu Icon in a drawer navigation? React Native

I nested a Drawer Navigator in a Stack Navigator, it works well and opens when I swipe it, I want to put a Menu Icon above it when it's pressed the drawer gets open. Every method I tried always ends up with navigation can't be found error.
Here's my code:
export class App extends Component {
.....
function DrawerNav() {
return (
<Drawer.Navigator
drawerType="front"
initialRouteName="Main" drawerPosition="right">
<Drawer.Screen name="Main" component={MainScreen} />
<Drawer.Screen name="Wallet" component={WalletScreen} />
<Drawer.Screen name="Appointments" component={Appointments} />
</Drawer.Navigator>
);}
return (
<Provider store={store}>
<NavigationContainer>
<Stack.Navigator initialRouteName="Menu">
<Stack.Screen name="Menu" component={DrawerNav} />
<Stack.Screen name="Add" component={AddScreen} navigation={this.props.navigation}/>
<Stack.Screen name="Save" component={SaveScreen} navigation={this.props.navigation}/>
</Stack.Navigator>
</NavigationContainer>
</Provider>
)}}
I want to open and close the drawer when I press on this icon:
<MaterialIcons name='menu' size={28} onPress={??} />
<MaterialIcons name='menu' size={28} onPress={()=>this.props.navigation.openDrawer()} />

How to make drawerContentOptions work in React navigation 6.x

I don't know how to style my drawer with React navigation 6.x. They say to replace it with 'screenOptions' but it doesn't work. Here is my code:
<NavigationContainer>
<Drawer.Navigator
initialRouteName="Home"
screenOptions={{
activeTintColor:"blue",
itemStyle:{marginTop:20},
labelStyle:{fontSize:30},
style:{backgroundColor:'purple'}
}}>
<Drawer.Screen name="Home" component={Home}/>
<Drawer.Screen
name="Users"
component={Users}
/>
</Drawer.Navigator>
</NavigationContainer>
How can i make it work with my styling? I am a beginner, thanks for your help and time.
you can reed here about options here
<Drawer.Navigator
screenOptions={{
//options for drawer
drawerLabel
drawerIcon
drawerActiveTintColor
drawerActiveBackgroundColor
drawerInactiveTintColor
drawerInactiveBackgroundColor
drawerItemStyle
drawerLabelStyle
drawerContentContainerStyle
drawerContentStyle
drawerStyle
}}
>
{/* screens */}
</Drawer.Navigator>

Got both 'component' and 'children' props for the screen 'Search'. You must only pass one of them

I work on a react-native app and this project used react-navigation 4.x to navigate around the app.
I recently upgraded the project to 5.x of react-navigation and while trying to upgrade I ran into a problem. The problem is that my project has both a FooterNavigator and a DrawerNavigator, they both call on the same component.
We already figured out a way to fix the problem in react-navigation 4.x but the new version of react-navigation requires a name and a component for each Screen. Is there any way for me to have both the navigators at the same time or is it better to downgrade?
Image of the error
This is my FooterNavigator
const Tab = createBottomTabNavigator();
export const FooterNavigator = () => {
return (
<Tab.Navigator>
<Tab.Screen name="Search" component={Search}>
<Button>
<Icon name="magnify" type="MaterialCommunityIcons"/>
<Text style={footerStyle.footerText}>Zoeken</Text>
</Button>
</Tab.Screen>
<Tab.Screen name="Count" component={Count}>
<Button>
<Icon name="counter" type="MaterialCommunityIcons"/>
<Text style={footerStyle.footerText}>Tellen</Text>
</Button>
</Tab.Screen>
<Tab.Screen name="Identify" component={Identify}>
<Button>
<Icon name="file-question" type="MaterialCommunityIcons"/>
<Text style={footerStyle.footerText}>Herken</Text>
</Button>
</Tab.Screen>
<Tab.Screen name="Program" component={Program}>
<Button>
<Icon name="chip" type="MaterialCommunityIcons"/>
<Text style={footerStyle.footerText}>Wijzig</Text>
</Button>
</Tab.Screen>
</Tab.Navigator>
)
}
And this is my DrawerNavigator
export const RootNavigator = () => {
let DrawerScreens = [];
Routes.forEach(function (route) {
DrawerScreens.push(<Drawer.Screen name={route.name} component={route.component}/>)
});
return (
<Drawer.Navigator>
{DrawerScreens}
</Drawer.Navigator>
)
}
They are both called and rendered in my Layout.js
render() {
return (
<NavigationContainer>
<RootNavigator />
<FooterNavigator/>
</NavigationContainer>
)
}
Many thanks in advance !!
use this
<Stack.Screen name="Home" component={HomeScreen} />
instead of this
<Stack.Screen name="Home" component={HomeScreen}> </Stack.Screen>
solve your problem
<NavigationContainer>
<Stack.Navigator initialRouteName="Home">
<Stack.Screen name="Home" component={HomeScreen}/>
<Stack.Screen name="Details" component={DetailScreen} />
</Stack.Navigator>
</NavigationContainer>
Just remove component prop from stack screen. if you are passing custom values through navigation stack
I get this error when I use a <Stack.Screen> and provide a component and a child to it, as the error mentions.
<Stack.Screen name="Home" component={Home}>
{props => <Home {...props} sampleProperty="XXXXXXXX" />}
</Stack.Screen>
removing this bit component={Home} on line1 fixes the error.