React Native - undefined不是对象(评估'RNGestureHandlerModule.state')

squ*_*ave 2 react-native react-native-ios react-native-navigation

我收到这个错误,它让我疯了,我甚至无法在React Native上启动一个简单的应用程序.我正在使用最基本的示例,一个新项目仍然会抛出此错误.我使用react-navigation v3xx 有人请帮助,因为我失去了理智,谢谢.这是我的代码:

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;
Run Code Online (Sandbox Code Playgroud)

Las*_*ath 5

Hellow

由于反应导航现在依赖于手势,因此您必须在安装react-navigation库之后安装其他库

从终端在项目中运行此命令

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

然后运行这个

react-native link react-native-gesture-handler

这些说明在这里有很好的解释

https://reactnavigation.org/docs/en/getting-started.html#installation

用于新的反应导航版本

最好的祝福