(??)012_ReactNative: Navigators

(問(wèn)渠那得清如許,為有源頭活水來(lái)。 雙手奉上RN官網(wǎng))

Navigators: 多界面之間切換

  • 關(guān)于Scenes場(chǎng)景概念(可以簡(jiǎn)單理解為一屏的展現(xiàn))

①創(chuàng)建一個(gè)名為"MyScene.js"的新文件,并寫入以下內(nèi)容

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

//export defaul 聲明使得該組件可以被其他組件導(dǎo)入使用
export default class MyScene extends Component {
  static propTypes = {
    title: PropTypes.string.isRequired,
    onForward: PropTypes.func.isRequired,
    onBack: PropTypes.func.isRequired,
  }
  render() {
    return (
      <View>
        <Text>Current Scene: { this.props.title }</Text>
        <TouchableHighlight onPress={this.props.onForward}>
          <Text>Tap me to load the next scene</Text>
        </TouchableHighlight>
        <TouchableHighlight onPress={this.props.onBack}>
          <Text>Tap me to go back</Text>
        </TouchableHighlight>
      </View>
    )
  }
}

②可以在index中引入

import React, { Component } from 'react';
import { AppRegistry, Navigator, Text, View } from 'react-native';

import MyScene from './MyScene';

class SimpleNavigationApp extends Component {
  render() {
    return (
      <Navigator
        initialRoute={{ title: 'My Initial Scene', index: 0 }}
        renderScene={(route, navigator) =>
          <MyScene
            title={route.title}

            // Function to call when a new scene should be displayed           
            onForward={ () => {    
              const nextIndex = route.index + 1;
              navigator.push({
                title: 'Scene ' + nextIndex,
                index: nextIndex,
              });
            }}

            // Function to call to go back to the previous scene
            onBack={() => {
              if (route.index > 0) {
                navigator.pop();
              }
            }}
          />
        }
      />
    )
  }
}

AppRegistry.registerComponent('ReactNativeLearn', () => SimpleNavigationApp);
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • (問(wèn)渠那得清如許,為有源頭活水來(lái)。 雙手奉上RN官網(wǎng)) Integration With Existing App...
    莫_名閱讀 359評(píng)論 0 0
  • (問(wèn)渠那得清如許,為有源頭活水來(lái)。 雙手奉上RN官網(wǎng)) 在index.ios.js中寫入 你需要理解一些基礎(chǔ)的Re...
    莫_名閱讀 326評(píng)論 0 0
  • 基本概念(問(wèn)渠那得清如許,為有源頭活水來(lái)。 雙手奉上RN官網(wǎng)) react|—react.js(web端js框架,...
    莫_名閱讀 385評(píng)論 0 0
  • (問(wèn)渠那得清如許,為有源頭活水來(lái)。 雙手奉上RN官網(wǎng)) Images 圖片 靜態(tài)圖片: 可以使用如 的方式獲取加載...
    莫_名閱讀 254評(píng)論 0 0
  • (問(wèn)渠那得清如許,為有源頭活水來(lái)。 雙手奉上RN官網(wǎng)) 固定尺寸: Height and Width 用于確定組件...
    莫_名閱讀 320評(píng)論 0 0

友情鏈接更多精彩內(nèi)容