React Native-未定义不是对象(正在评估'RNGestureHandlerModule.state')

时间:2018-11-20 21:06:29

标签: react-native react-native-ios react-native-navigation

我收到此错误,这让我发疯,我什至无法在React Native上启动一个简单的应用程序。我使用的是最基本的示例,带有一个新项目,仍然会抛出此错误。 我使用反应导航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;

2 个答案:

答案 0 :(得分:5)

Hellow

由于反应导航现在取决于手势,因此您必须在安装了反应导航库后再安装一个附加库

从终端在项目内部运行此命令

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

然后运行这个

react-native link react-native-gesture-handler

这些说明在这里得到了很好的解释

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

用于新的React导航版本

最诚挚的问候

答案 1 :(得分:2)

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