navigatorIOS的小例子,facebook文档太坑爹,这是一个可用版本

'use strict';


import React, { Component, PropTypes } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  NavigatorIOS,
  TouchableHighlight,
} from 'react-native';


class RNHighScores extends React.Component {
  render() {
    var contents = this.props["scores"].map(
      score => <Text key={score.name}>{score.name}:{score.value}{"\n"}</Text>
    );
    const routes = [
    {title: 'First Scene', index: 0},
    {title: 'Second Scene', index: 1},
  ];
    return (
      <NavigatorIOS
        initialRoute={{
          component: MyScene,
          title: 'My Initial Scene',
          passProps: { myProp: 'foo' }
        }}
        style={{flex: 1}} />
  
    );
  }
}




class MyScene extends Component {
  static propTypes = {
    //title: PropTypes.string.isRequired,
    navigator: PropTypes.object.isRequired,
  }


  constructor(props, context) {
    super(props, context);
    this._onForward = this._onForward.bind(this);
    //this._onBack = this._onBack.bind(this);
  }


  _onForward() {
    this.props.navigator.push({
       component: MyView,
      title: 'Genius',
      passProps: { myProp: 'genius' },
    });
  }




  render() {
    console.log("rendering");
    return (
      <View style={styles.container}>
        <Text>Current Scene: { this.props.title }</Text>
        <TouchableHighlight onPress={this._onForward}>
          <Text>Tap me to load the next scene</Text>
        </TouchableHighlight>
      
      </View>
    )
  }
}


class MyView extends Component {
  _handleBackPress() {
    this.props.navigator.pop();
  }


  _handleNextPress(nextRoute) {
    this.props.navigator.push(nextRoute);
  }




   _onBack() {
    this.props.navigator.pop();
  }
  render() {
    const nextRoute = {
      component: MyView,
      title: 'Bar That',
      passProps: { myProp: 'bar' }
    };
    return(
      <View>
      <TouchableHighlight onPress={() => this._handleNextPress(nextRoute)}>
        <Text style={{marginTop: 200, alignSelf: 'center'}}>
          See you on the other nav {this.props.myProp}!
        </Text>
      </TouchableHighlight>
        <TouchableHighlight onPress={this._onBack.bind(this)}>
          <Text style={{marginTop: 200, alignSelf: 'center'}}>Tap me to  the last scene</Text>
        </TouchableHighlight>
      </View>
    );


  }
}


const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#FFFFFF',
  },
  highScoresTitle: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  scores: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
});


// Module name
AppRegistry.registerComponent('RNHighScores', () => RNHighScores);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值