ReactNative Demo - Navigator 使用
来源:互联网 发布:数据中心网络拓扑图 编辑:程序博客网 时间:2024/05/18 16:58
import React, { Component } from 'react'; import { AppRegistry, StyleSheet, Text, View, Image, DrawerLayoutAndroid, ListView, PixelRatio, Navigator, ScrollView, } from 'react-native'; const Header = require("./Header") class AwesomeProject extends Component { render() { let defaultName='List'; let defaultComponent=List; return ( <Navigator initialRoute={{name: defaultName, component: defaultComponent}} configureScene={ (route) => { return Navigator.SceneConfigs.HorizontalSwipeJumpFromRight; } } renderScene={ (route,navigator)=> { let Component = route.component; return <Component {...route.params} navigator={navigator}/> } }/> ); } } class List extends Component{ constructor(props) { super(props); this.state = {author:"zcw",id:1,user:null,}; } _pressButton(){ const {navigator} = this.props; const self = this; if(navigator) { navigator.push({ name : 'Detail', component : Detail, params : { author: this.state.author, id:this.state.id, getUser:function(user) { self.setState({ user:user }) } } }) } } render(){ if(this.state.user) { return( <ScrollView style={styles.flex}> <Text style={styles.list_item} onPress={this._pressButton.bind(this)}>用户信息:{JSON.stringify(this.state.user)}</Text> </ScrollView> ); }else { return( <ScrollView style={styles.flex}> <Text style={styles.list_item} onPress={this._pressButton.bind(this)}>* 豪华游轮济州岛3日游</Text> <Text style={styles.list_item} onPress={this._pressButton.bind(this)}>* 豪华游轮台湾3日游</Text> <Text style={styles.list_item} onPress={this._pressButton.bind(this)}>* 豪华游轮塔克拉玛干岛3日游</Text> </ScrollView> ); } } } class Detail extends Component{ constructor(props) { super(props); this.state={}; } componentDidMount(){ this.setState({ author:this.props.author, }); } _pressButton (){ const {navigator} = this.props; if(this.props.getUser) { let user = MODEL_USERS[this.props.id]; this.props.getUser(user); } if(navigator) { navigator.pop(); } } render(){ return( <ScrollView> <Text style={styles.list_item} onPress={this._pressButton.bind(this)}>作者是:{this.state.author}</Text> </ScrollView> ); } } const styles = StyleSheet.create({ flex: { flex:1, }, news_item:{ marginLeft:10, marginRight:10, justifyContent:'center', height:40, }, news_title_font:{ fontSize:20, color:'red', }, list_item_font:{ fontSize:16, }, list_item:{ marginLeft:10, marginRight:10, justifyContent:'center', height:40, borderBottomWidth:1/PixelRatio.get(), borderBottomColor: '#ddd', }, }); const MODEL_USERS={ 1:{name:'mot',age:23}, 2:{name:'zcw',age:22} }; AppRegistry.registerComponent('AwesomeProject', () => AwesomeProject);
0 0
- ReactNative Demo - Navigator 使用
- ReactNative-Navigator组件简单使用
- ReactNative Demo - ImageVIew 使用
- ReactNative Demo - NavigationView 使用
- ReactNative的Navigator组件使用方式
- ReactNative的Navigator组件使用方式
- ReactNative的Navigator组件使用方式
- ReactNative Demo - Dimensions 的使用
- ReactNative页面跳转Navigator
- ReactNative页面跳转Navigator
- reactNative Navigator导航组件
- ReactNative页面跳转Navigator
- reactnative Navigator api解释
- ReactNative Navigator 页面跳转
- ReactNative 导航栏Navigator的使用及参数navigator的传递
- ReactNative Navigator 页面传值
- ReactNative学习实例(四) 使用Navigator实现页面跳转和信息传递
- ReactNative学习十-Tab-Navigator
- Pykd——Python extension for WinDbg
- nginx.conf详解
- @PathVariable和@RequestParam的区别,理解 @PathVariable 、@RequestHeader、@CookieValue、@RequestParam, @Request
- 9. Palindrome Number
- leetcode:word-break
- ReactNative Demo - Navigator 使用
- mongoDB 入门指南、示例
- 2016/07/20 对闭包、构造函数的理解
- 内存泄漏之内部类new Handler();
- UVA 846-Steps
- ReactNative Demo -SearchInput
- 社会化三方分享集成详细介绍(友盟)
- Ajax开发步骤解析
- hive变量传递