一、安装Navigator

1.安装react-native-deprecated-custom-components

npm install react-native-deprecated-custom-components  --save 

2.若npm安装报错,则执行下面命令

npm i react-native-deprecated-custom-components  --save

3.若还未解决则使用yarn命令(前提是自己有yarn的配置环境)

yarn add react-native-deprecated-custom-components  --save 

二、使用Navigator

说明:本demo为男生给女生送一枝玫瑰,女生回赠巧克力。包含了父子组件的通信

1.引入Navigator

import {Navigator} from "react-native-deprecated-custom-components" 

2.页面A(用于放置父组件Boy和子组件Girl):

<Navigator
initialRoute={{
//Boy为默认显示组件
component: Boy
}}
renderScene={(route,navigator)=>{
let Component = route.component;
return <Component navigator={navigator} {...route.params}/>
}}
></Navigator>

3.父组件Boy(父组件):

<View style={styles.container}>
<Text style={styles.text}>I am Boy</Text>
<Text
style={styles.text}
onPress={
()=>{
this.props.navigator.push({
component:Girl,
params:{
word:'一枝玫瑰',
onCallBack:(word)=>{
this.setState({
word:word
})
}
}
})
}
}
>送女孩一支玫瑰</Text>
<Text style={styles.text}>{this.state.word}</Text>
</View>

4.子组件Girl(子组件):

<View style={styles.container}>
<Text style={styles.text}>
I am Girl.
</Text>
<Text style={styles.text}>
我收到了男孩送的玫瑰{this.props.word}
</Text>
<Text
style={styles.text}
onPress={
()=>{
this.props.onCallBack('一盒巧克力');
//删除组件
this.props.navigator.pop()
}
}
>
回赠巧克力
</Text>
</View>

React Native中Navigator的安装与使用的更多相关文章

  1. [转] 在React Native中使用ART

    http://bbs.reactnative.cn/topic/306/%E5%9C%A8react-native%E4%B8%AD%E4%BD%BF%E7%94%A8art 前半个月捣腾了一下Rea ...

  2. react native中使用echarts

    开发平台:mac pro node版本:v8.11.2 npm版本:6.4.1 react-native版本:0.57.8 native-echarts版本:^0.5.0 目标平台:android端收 ...

  3. 在 React Native 中使用 Redux 架构

    前言 Redux 架构是 Flux 架构的一个变形,相对于 Flux,Redux 的复杂性相对较低,而且最为巧妙的是 React 应用可以看成由一个根组件连接着许多大大小小的组件的应用,Redux 也 ...

  4. React Native导航器Navigator

    React Native导航器Navigator 使用导航器可以让你在应用的不同场景(页面)间进行切换.导航器通过路由对象来分辨不同的场景.利用renderScene方法,导航栏可以根据指定的路由来渲 ...

  5. React Native 中 CSS 的使用

    首先声明,此文原作者为黎 跃春 React Native中CSS 内联样式 对象样式 使用Stylesheet.Create 样式拼接 导出样式对象 下面的代码是index.ios.js中的代码: / ...

  6. react native中的欢迎页(解决首加载白屏)

    参照网页: http://blog.csdn.net/fengyuzhengfan/article/details/52712829 首先是在原生中写一些方法,然后通过react native中js去 ...

  7. React Native中的网络请求fetch和简单封装

    React Native中的网络请求fetch使用方法最为简单,但却可以实现大多数的网络请求,需要了解更多的可以访问: https://segmentfault.com/a/1190000003810 ...

  8. [转] 「指尖上的魔法」 - 谈谈 React Native 中的手势

    http://gold.xitu.io/entry/55fa202960b28497519db23f React-Native是一款由Facebook开发并开源的框架,主要卖点是使用JavaScrip ...

  9. react native中一次错误排查 Error:Error: Duplicate resources

    最近一直在使用react native中,遇到了很多的坑,同时也学习到了一些移动端的开发经验. 今天在做一个打包的测试时,遇到了一个问题,打包过程中报错“Error:Error: Duplicate ...

随机推荐

  1. js实现复制 、剪切功能-clipboard.min.js 示例

    html: <div id="txt">我是要复制的内容</button> <button id="copyBtn">点击复 ...

  2. 2.03_01_Python网络爬虫urllib2库

    一:urllib2库的基本使用 所谓网页抓取,就是把URL地址中指定的网络资源从网络流中抓取出来.在Python中有很多库可以用来抓取网页,我们先学习urllib2. urllib2 是 Python ...

  3. PAT Basic 1084 外观数列 (20 分)

    外观数列是指具有以下特点的整数序列: d, d1, d111, d113, d11231, d112213111, ... 它从不等于 1 的数字 d 开始,序列的第 n+1 项是对第 n 项的描述. ...

  4. anaconda环境中---py2.7下安装tf1.0 + py3.5下安装tf1.5

    anaconda环境中---py2.7下安装tf1.0 + py3.5下安装tf1.5 @wp20181030 环境:ubuntu18.04, anaconda2, ubuntu系统下事先安装了pyt ...

  5. JAVA遇见HTML——JSP篇(案例项目)

  6. dcm4che-core导包失败! mvn pom文件导包总是失败

    原因可能是所导的包不在共有项目中,可能在个人项目中,需要添加远程仓库 <!--远程仓库部署--><repositories> <repository> <id ...

  7. metal2 里 programmable blending 和image block的区别 语法以及persistent thread group的语法

    programmable blending 刚接触这个概念的时候 挺激动的 因为能解决很多管线里面的问题 比如 切一次rt再切回来 为了做read write same rt 有了这个 就不用切啦 可 ...

  8. 隐藏IDEA project 中的指定文件

    例如隐藏project下的.idea文件目录,以及.iml文件 在 Settings>File Types > ignore files and folders 中添加    .idea; ...

  9. Maven手动将jar导入本地仓库

    1.使用cmd进入maven安装目录下的bin 2.运行mvn install:install-file -Dfile=jar包的路径 -DgroupId=gruopId中的内容 -Dartifact ...

  10. luogu 1169 [ZJOI2007]棋盘制作 悬线dp

    悬线法,虽然得不到局部最优解,但是一定能得到全局最优解的算法,十分神奇~ #include <cstdio> #include <algorithm> #define N 20 ...