React Native - undefined is not an object(evaluating 'RNGestureHandlerModule.state') - react-native

I get this error and it's driving me insane, I cannot even start a simple application on React Native. I am using the most basic example, with a fresh project and still throws this error.
I use react-navigation v3xx
Someone please help because I am losing my mind, thank you.
Here is the code I have:
import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View, Button, TouchableHighlight} from 'react-native';
import { createAppContainer, createStackNavigator, StackActions, NavigationActions } from 'react-navigation'; // Version can be specified in package.json
class Home extends React.Component {
static navigationOptions = {
title: "Home",
}
render() {
return (
<View style={styles.container}>
<Text>Home Page</Text>
<Button onPress={() => this.props.navigation.navigate('About')} title="All about me" />
</View>
);
}
}
class AboutMeMe extends React.Component {
static navigationOptions = {
title: "All Me",
}
render() {
return (
<View style={styles.container}>
<Text>Home Page</Text>
<Button onPress={() => this.props.navigation.goBack()} title="<< Back" />
</View>
);
}
}
const AppScreens = createStackNavigator({
Home: Home,
About: AboutMeMe
})
const App = createAppContainer(AppScreens);
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
});
export default App;

Hellow
As react navigation now depends on gesture so you must install an additional library to go after you have installed the react-navigation library
Run this command inside your project from your terminal
npm install --save react-native-gesture-handler
Then run this one
react-native link react-native-gesture-handler
These instructions are well explained here
https://reactnavigation.org/docs/en/getting-started.html#installation
for new react navigation version
Best regards

npm install --save react-native-gesture-handler
react-native link react-native-gesture-handler

Related

Can't tigger Drawer by toggledrawer and got white screen

iOS 13(simulator ) |
xcode13 |
react-navigation6.x |
react-native 0.68.2
Drawer Navigator works fine But an Error occurres when adding useLegacyImplementation.
Also,I can't touch off my sidebar by navigation.openDrawer
and If I add useLegacyImplementation={true} the screen while turns white.
This is src_Drawer
import React ,{Component}from 'react';
import { Button, View ,Text,StyleSheet} from 'react-native';
import { createDrawerNavigator } from '#react-navigation/drawer';
const Drawer=createDrawerNavigator()
//two function
function HomeScreen(prop){
return(
<View style={styles.container}>
<Text style={styles.text}>Home Screen</Text>
<Button title={"Open Drawer"} onPress={()=>prop.navigation.openDrawer()}/>
<Button title={"Toggle Drawer"} onPress={()=>prop.navigation.toggleDrawer()}/>
</View>
)
}
function NewsScreen(prop){
return(
<View style={styles.container}>
<Text style={styles.text}>News Screen</Text>
<Button title={"jump to Home"} onPress={()=>prop.navigation.navigate('Home')}/>
</View>
)
}
export default class index extends Component{
render(){
return(
<Drawer.Navigator >
<Drawer.Screen name="Home" component={HomeScreen} />
<Drawer.Screen name="News" component={NewsScreen} />
</Drawer.Navigator>
)
}
}
const styles=StyleSheet.create({
container:{
flex:1,
justifyContent:'center',
alignItems: 'center',
},
text:{
fontSize:40
}
})
app.js :
import 'react-native-gesture-handler';
import React, { Component } from 'react'
import { View, Text } from 'react-native';
import { NavigationContainer } from '#react-navigation/native';
import Index from './src_Drawer';
export default class App extends Component{
render(){
return(
<NavigationContainer>
<Index/>
</NavigationContainer>
)
}
}
I want to know how to fix it.
I resolve this problem!!
Error Reason:
have incorrect react-native-reanimated
First I do this according to official interpretation:
npm install react-native-reanimated
But it doesn’t work.
Also it Not warning me in debugger
Till I run it On my iPhone
This is how i resolve it:
link:https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/installation/
1.First step is to install react-native-reanimated as a dependency in your project:
yarn add react-native-reanimated
2.Add Reanimated's Babel plugin to your babel.config.js:
module.exports = {
presets: [
...
],
plugins: [
...
'react-native-reanimated/plugin',
],
};
3.yarn start --reset-cache

React Native Webview Library is not working in my app

I'm just trying to make a ReactNative app that will display a simple webpage. But all I can see is a blank screen in my browser (Google) and my Expo Go says Network response timed out. Could somebody help me out, please?
I have given my code below:
import { StatusBar } from 'expo-status-bar';
import React from 'react';
import { StyleSheet, Text, View, } from 'react-native';
import {WebView} from 'react-native-webview';
export default function App() {
const GOOGLE = "https://www.google.com/"
return (
<View style={styles.container}>
<View>
<WebView
source = {{uri : GOOGLE}}
/>
</View>
<StatusBar style="auto" />
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
Blank screen image...
I have done npm install react-native-webview
you cant npm install react-native-webview because it has native dependencies.
You need to install it through expo by going
expo install react-native-webview
you can read this for more
https://docs.expo.dev/versions/latest/sdk/webview/

Unable to resolve #react-navigation/drawer in react native to create drawer navigation

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>
);
}
Yup! this is old question but I want to answer for this. However we know that react native packages varies based on version updates. Follow the below steps if your using (version)V5x I am sure it works.
npm install --save react-navigation-drawer (Install Packages)
import { createDrawerNavigator } from 'react-navigation-drawer'; (Import Navigator using 'react-navigation-drawer')
npm install #react-navigation/drawer
or
npm install #react-navigation/drawer
To use this drawer navigator, import it from #react-navigation/drawer:
import { createDrawerNavigator } from '#react-navigation/drawer';
Add react-native-reanimated/plugin in babel.config.js file
module.exports = {
presets: ['module:metro-react-native-babel-preset'],
Plugin: ['react-native-reanimated/plugin'],
};
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;

Expo Client does not save changes

Im very new to react-native and expo.
I can't solve this problem myself.
My previous code was this.
import React, {Component} from 'react';
import { View, Text, StyleSheet, TouchableOpacity } from 'react-native';
import firebase from 'firebase';
export default class Home extends React.Component {
handleSignOut = () => {
firebase
.auth()
.signOut()
.then(result => alert('sign out success'))
.catch(error => console.error(error));
};
render() {
return (
<View style={styles.container}>
<Text>Main</Text>
<TouchableOpacity onPress={this.handleSignOut}>
<Text>Sign Out</Text>
</TouchableOpacity>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center'
}
});
Then I just changed the text 'Main' to 'Home' and saved.
After that expo client was reloaded but nothing changed :(
I would appreciate it if you could give me any advices!
Not sure which version of Expo you're using (expo --version), but I spun off a quick Expo project, copy pasted your code (minus the Firebase parts) and it works seamlessly.
Maybe try closing and reopening your emulator/simulator.

react native vector icons showing X instead of icon

I cant seem to figure this out. I can get something to show, but its a box with an X in it, so im assuming its not picking up the vector icons. Any advice?
I have the show icon true, I have the tint color, I have the vector icons (i have tried both ionicons and font awesome, to no avail.
Code:
import React, { Component} from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { createBottomTabNavigator, createAppContainer } from 'react-
navigation';
import Icon from 'react-native-vector-icons/FontAwesome';
class HomeScreen extends Component {
static navigationOptions = {
title: 'Home'
};
render(){
return (
<View style={{ flex:1, alignItems:'center', justifyContent:'center'
}}>
<Text>Home Screen</Text>
</View>
);
}
}
const RootStack = createBottomTabNavigator(
{
Home: {
screen: HomeScreen,
navigationOptions: {
tabBarLabel: 'Home',
tabBarIcon: ({ tintColor }) => (
<Icon name = 'home' size={25} color={tintColor} />
)
}
},
},
{
tabBarOptions: {
showIcon:true,
tintColor:'red'
}
}
);
const AppContainer = createAppContainer(RootStack);
const styles = StyleSheet.create({
})
export default class App extends Component{
render(){
return <AppContainer />;
}
}
I am using react-native version 0.62 and I encountered this error too. Though 0.60+ versions of react native provide auto-linking feature, but for react-native-vector-icons this is an exception. You need to link it manually. To solve it, follow below steps
rm -rf node_modules
yarn
yarn react-native link
Hope that helps.
Fixed this. Once i realized it was the vectors, i just linked react-native with react-native-vectors.