I am trying to create new drawer navigation but getting this below error
Unable to resolve "react-native-screens" from "node_modules\@react-navigation\drawer\src\views\DrawerView.tsx"
Failed building JavaScript bundle.
but same code i tried in new empty project it worked with react-native-drawer in older version of "react-navigation": "^2.6.2" but the same not working in "react-navigation": "^4.0.10", it shows that react-native-drawer is removed and @react-native/drawer is latest so we need to use that but its not working kindly help me resolving this...Code is in below
import * as React from 'react';
import { View, Text } from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import { createDrawerNavigator } from '@react-navigation/drawer';
function Feed() {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>Feed Screen</Text>
</View>
);
}
function Article() {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>Article Screen</Text>
</View>
);
}
const Drawer = createDrawerNavigator();
function MyDrawer() {
return (
<Drawer.Navigator>
<Drawer.Screen name="Feed" component={Feed} />
<Drawer.Screen name="Article" component={Article} />
</Drawer.Navigator>
);
}
export default function DrawerNavigator() {
return (
<NavigationContainer>
<MyDrawer />
</NavigationContainer>
);
}
I know this is not a right solution but anyway it worked for me...
instead of @react-navigation/drawer we can use
import { createDrawerNavigator,DrawerItems} from 'react-navigation-drawer';
this works and I have pasted my working code below
In ReactNative update they moved createDrawerNavigator and DrawerItems from react-navigation to react-navigation-drawer...
import React from 'react';
import { StyleSheet, Text, View, SafeAreaView, ScrollView,Dimensions,Image } from 'react-native';
import { createAppContainer} from 'react-navigation';
import {createStackNavigator} from 'react-navigation-stack';
import { createDrawerNavigator,DrawerItems} from 'react-navigation-drawer';
import Login from '../screens/Login';
import Home from '../screens/Home';
const CustomDrawComponent=(props) => (
<SafeAreaView style={{flex:1}}>
<View style={{paddingTop:45, backgroundColor:'green'}}>
<View style={{height:150,alignItems:'center', justifyContent:'center'}}>
<Image source={require('../assets/Logos/userPic.png')}
style={{height:120,width:120,borderRadius:60}} />
</View>
</View>
<ScrollView>
<DrawerItems {...props}/>
</ScrollView>
<Text style={{paddingBottom:100, paddingLeft:65}}>Vision Cultura V1.0</Text>
</SafeAreaView>
)
const screens = createDrawerNavigator({
Main: {
screen: createStackNavigator({
Home: {screen: Home},
Login: {screen: Login},
}, {initialRouteName: "Login"})
},
Home: Home,
Login: Login
},
{
contentComponent:CustomDrawComponent
});
const index = createAppContainer(screens);
export default index;