本文针对react-navigation^3.0.0版本,版本不对的话,请不要看本文,直接看官方英文文档

​ 最近一直在学习RN,没找到什么好的视频,所以一直看文档,一路上来虽然遇到一些乱七八糟的bug,但是能比较友好的解决掉

直到我使用react-navigation,这个官方文档上说简单易用的导航组件,搞的我心态爆照,调试了一下午

首先我按网上的例子来

import {StackNavigator} from 'react-navigation';
const HomeScreen = () => (
<View style={{flex: 1, justifyContent: 'center', alignItems: 'center'}}>
<Text>Home Screen</Text>
</View>
); const DetailScreen = () => (
<View style={{flex: 1, justifyContent: 'center', alignItems: 'center'}}>
<Text>Detail Screen</Text>
</View>
); const RootNavigator = StackNavigator({
Home: {
screen: HomeScreen
},
Detail: {
screen: DetailScreen
}
}); export default RootNavigator;

上来就是报错

undefined is not a function (evaluating'_reactNavigation.StackNavigator....')

我一看,这说我导入的不是函数????

查看道路部分,发现新的文档,方法名字都变了???

import {
createStackNavigator,
} from 'react-navigation'; const App = createStackNavigator({
Home: { screen: HomeScreen },
Profile: { screen: ProfileScreen },
}); export default App;

重启

依旧报错

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

在这里google查了半天,都没有看到解决方案

因为一直这看中文文档,狗中文文档根本就不是3.0.0版本,最后直接去看英文文档!!

react-navigation英文文档

文档上有一句

Next, install react-native-gesture-handler. If you’re using Expo you don’t need to do anything here, it’s included in the SDK. Otherwise:

接下来,安装react-native-gesture-handler。 如果你正在使用Expo,你不需要在这里做任何事情,它包含在SDK中。 除此以外

// 我完全不知道Expo指什么,但是我还是跑了他下面的命令

yarn add react-native-gesture-handler
react-native link

我们看看官方的demo

import React from "react";
import { View, Text } from "react-native";
import { createStackNavigator, createAppContainer } from "react-navigation"; class HomeScreen extends React.Component {
render() {
return (
<View style={{ flex: 1, alignItems: "center", justifyContent: "center" }}>
<Text>Home Screen</Text>
</View>
);
}
} const AppNavigator = createStackNavigator({
Home: {
screen: HomeScreen
}
}); export default createAppContainer(AppNavigator);

这demo怎么和我看过的都不一样???

于是我改动了写的代码

App.js

import React, { Component } from 'react'
import { Platform, StyleSheet, Text, View } from 'react-native'
import { createStackNavigator, createAppContainer } from 'react-navigation'
import HomeScreen from './pages/HomeScreen'
import ProfileScreen from './pages/ProfileScreen' const navigator = createStackNavigator({
Home: { screen: HomeScreen },
Profile: { screen: ProfileScreen }
}) const App = createAppContainer(navigator) export default App const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF'
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5
}
})

pages/ProfileScreen

import React, { Component } from 'react'
import { Text, StyleSheet, View } from 'react-native' export default class ProfileScreen extends Component {
static navigationOptions = {
title: 'ProfileScreen'
}
render() {
return (
<View>
<Text> 2 </Text>
</View>
)
}
} const styles = StyleSheet.create({})

pages/HomeScreen

import React, { Component } from 'react'
import { Text, StyleSheet, View, Button } from 'react-native'
import { createStackNavigator, createAppContainer } from 'react-navigation';
export default class HomeScreen extends Component {
static navigationOptions = {
title: 'HomeScreen'
}
render() {
return (
<View>
<Text> one </Text>
<Button title="go to two" onPress={() => this.props.navigation.navigate('Profile')} />
</View>
)
}
} const styles = StyleSheet.create({})

终于使用成功了

react-navigation的超级大坑的更多相关文章

  1. react-native 学习 ----- React Navigation

    很久没有的登陆博客园了,密码都是找回的,从当年的大学生已经正常的走上了程序员的道路,看到之前发的博客还是写的android,现在自己已经在使用了react-native了. 大学毕业了,做了java后 ...

  2. react-native导航器 react navigation 介绍

    开发环境搭建好之后,想要进一步了解react-native,可以先从react-native官网上的电影列表案例入手: https://reactnative.cn/docs/0.51/sample- ...

  3. React Navigation & React Native & React Native Navigation

    React Navigation & React Native & React Native Navigation React Navigation https://facebook. ...

  4. [RN] 04 - React Navigation

    react-navigation和react-router的对比: 支持的平台: react-navigation: react-native react-router: react-native.r ...

  5. React Native常用组件之TabBarIOS、TabBarIOS.Item组件、Navigator组件、NavigatorIOS组件、React Navigation第三方

    以下内容为老版本React Native,faceBook已经有了新的导航组件,请移步其他博客参考>>[我是传送门] 参考资料:React Navigation  react-native ...

  6. React-native 导航插件React Navigation 4.x的使用

    React-native 导航插件React Navigation 4.x的使用 文档 英文水平可以的话,建议直接阅读英文文档 简单使用介绍 安装插件 yarn add react-navigatio ...

  7. [RN] React Navigation 使用中遇到的显示 问题 汇总

    React Navigation 使用中遇到的显示 问题 汇总 https://www.jianshu.com/p/8b1f18affc5d

  8. react navigation goBack()返回到任意页面(不集成redux) 一

    方案一: 一.适用场景:在app端开发的时候,相反回到某一个页面的时候保持跳转页面的所有状态不更新,也就是说不触发新的生命周期. 例如:A——>B——>C——>D 要想从D页面直接返 ...

  9. React Navigation / React Native Navigation 多种类型的导航结合使用,构造合理回退栈

    React Navigation 更新到版本5已经是非常完善的一套导航管理组件, 提供了Stack , Tab , Drawer 导航方式 , 那么我们应该怎样设计和组合应用他们来构建一个完美的回退栈 ...

  10. React Navigation基本用法

    /** * Created by apple on 2018/9/23. */ import React, { Component } from 'react'; import {AppRegistr ...

随机推荐

  1. PyCharm添加Selenium与Appium依赖

  2. Software Testing Techniques Homework 3

    1. a.This is the chart b. initial numPrimes = 4, t1 would over the loop. c. t = ( n = 1) d. node cov ...

  3. Oracle PL/SQL Dev工具(破解版)被植入勒索病毒的安全预警及自查通告

    [问题描述] 近日,有项目组遇到了勒索软件攻击:勒索代码隐藏在Oracle PL/SQL Dev软件中(网上下载的破解版),里面的一个文件afterconnet.sql被黑客注入了病毒代码.这个代码会 ...

  4. 笔记:Xen虚拟机如何迁移到KVM上?

    众所周知如果是在Linux上使用虚拟化技术的话,就会有基于Xen Hypervisor部署一个系统的机会.因为基于内核的虚拟机(KVM:Kernel-Based Virtual Machine)已经逐 ...

  5. [翻译] FLAnimatedImage

    FLAnimatedImage FLAnimatedImage is a performant animated GIF engine for iOS: FLAnimatedImage是一个播放gif ...

  6. 企业办公领域: Windows + Office的组合在未来能抵挡住 Google Apps的冲击么

    从个人角度讲,我基本上不怎么喜欢微软的产品,即便是其无处不见的Windows. Windows 8用了几个月的后,实在无法忍受其某些SB的设计,还是换回Win7.另外自从用上了MacBook 以后, ...

  7. December 20th 2016 Week 52nd Tuesday

    With the wonder of your love, the sun above always shines. 拥有你美丽的爱情,太阳就永远明媚. To accept the love from ...

  8. [COGS 0407][NOIP 2009] 靶形数独

    407. [NOIP2009] 靶形数独 ★★   输入文件:sudoku.in   输出文件:sudoku.out   简单对比时间限制:5 s   内存限制:128 MB [问题描述] 小城和小华 ...

  9. 对volatile不具有原子性的理解

    在阅读多线程书籍的时候,对volatile的原子性产生了疑问,问题类似于这篇文章所阐述的那样.经过一番思考给出自己的理解. 我们知道对于可见性,Java提供了volatile关键字来保证可见性.有序性 ...

  10. h5标签

    1.<abbr> 标签指示简称或缩写,比如 "WWW" 或 "NATO". IE 6 或更早版本的 IE 浏览器不支持 <abbr> 标 ...