react native的Navigator组件示例
2024-08-24 22:10:45
import React, {Component} from 'react';
import {ScrollView, StyleSheet, Text, View, PixelRatio} from 'react-native';
import { Navigator } from 'react-native-deprecated-custom-components'; // 0.45以上的版本要从这个模块获取导航 export default class NavigatorList extends Component {
render() {
let defaultName = 'List2' // 定义默认的组件名称
let defaultComponent = List2 //定义默认显示的组件
return (
<Navigator
initialRoute={{ name: defaultName, component: defaultComponent}} //初始化路由,有name和component属性,即默认显示的组件信息
// 配置场景
configureScene = {
(route) => {
// 这个是页面之间跳转的动画,VerticalDownSwipeJump是一种动画方式
return Navigator.SceneConfigs.VerticalDownSwipeJump;
}
}
// 将组件显示出来
renderScene={
(route, navigator) => {
let Component = route.component;
return <Component {...route.params} navigator={navigator}/>
}
}
/>
);
}
}
class List2 extends Component {
constructor(props) {
super (props);
this.state = {};
}
_pressButton() {
const {navigator} = this.props;
if(navigator) {
navigator.push({
name: 'Detail',
component: Detail,
})
}
}
render() {
return (
<View style={{flex: 1, backgroundColor: 'red'}}>
<Text onPress={this._pressButton.bind(this)}>内容1</Text>
<Text onPress={this._pressButton.bind(this)}>内容2</Text>
<Text onPress={this._pressButton.bind(this)}>内容3</Text>
</View>
)
}
}
class Detail extends Component {
constructor(props) {
super (props);
this.state = {};
}
_pressButton() {
const {navigator} = this.props;
if(navigator) {
navigator.pop(); //将路由弹出去
}
}
render() {
return (
<ScrollView>
<Text onPress={this._pressButton.bind(this)}>点我跳回去</Text>
</ScrollView>
)
}
}
最新文章
- jsonp的三种跨域方式
- BZOJ 3437: 小P的牧场 斜率优化DP
- hdu 3590 PP and QQ
- Android实现网络多线程文件下载
- 【CLR】奇妙的String
- delphi 为应用程序添加提示
- 【转载】Linux小白福利:《超容易的Linux系统管理入门书》(三)在虚拟机上安装Linux
- [PeterDLax著泛函分析习题参考解答]第1章 线性空间
- ArcGIS 在地图上添加标注
- 【剑指offer】面试题35:第一个只出现一次的字符
- activity的生命周期详解
- Natas Wargame Level20 Writeup(会话状态注入/篡改)
- Object类----toString,equals,hashcode
- LeetCode之“树”:Balanced Binary Tree
- Floyed-Warshall【弗洛伊德算法】
- nginx 代理 https 后,应用变成 http
- IntelliJ IDEA 注册码 (秘钥)
- Spring Boot(Spring的自动整合框架)
- scrapy中css选择器初识
- “AS3.0高级动画编程”学习:第三章等角投影(上)
热门文章
- IOS 文件夹结构
- 腾讯云服务器申请免费SSL证书,实现Https。
- shapes
- volley get post json imagerequest imageloader networkimageview 加载网络本地图片
- Python序列——列表
- Linux ARM交叉编译工具链制作过程【转】
- hdu1198 Farm Irrigation —— dfs or 并查集
- ansible 文件模块,很实用
- 2016.4.23浙江省赛(zoj3936 zoj3938 zoj3940 zoj3944 zoj3946 zoj3947 )
- CodeForces - div1 -650D:Zip-line(主席树 占位)