1. 程式人生 > >Navigator實現頁面跳轉

Navigator實現頁面跳轉

reaact-native version:0.57

app.js

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 *
 * @format
 * @flow
 */

import React, {Component} from 'react';
import {
  Platform,
  StyleSheet,
  Text,
  View,
  Image
} from 'react-native';

// https://github.com/ptomasroos/react-native-tab-navigator
import TabNavigator from 'react-native-tab-navigator'; // npm install react-native-deprecated-custom-components --save import {Navigator} from 'react-native-deprecated-custom-components'; import Boy from './Boy'; const instructions = Platform.select({ ios: 'Press Cmd+R to reload,\n' + 'Cmd+D or shake for dev menu'
, android: 'Double tap R on your keyboard to reload,\n' + 'Shake or press menu button for dev menu', }); type Props = {}; export default class App extends Component<Props> { constructor(props) { super(props); this.state = { selectedTab: 'home' } } render() {
return ( <View style={styles.container}> <Navigator initialRoute={{ // 跳轉到哪個頁面 component: Boy }} // 固定寫法 renderScene={ (route, navigator) => { let Component = route.component; return <Component {...route.params} navigator={navigator} /> } } /> </View> ); } } const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: '#F5FCFF', }, page1: { flex: 1, backgroundColor: 'red' }, page2: { flex: 1, backgroundColor: 'yellow' }, image: { height: 22, width: 22 } });

Boy.js

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


import Girl from './Girl'

export default class Boy extends Component{
  constructor(props){
    super(props);
    this.state = {
      word:''
    }
  }

  render(){
    return (
      <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>
    );
  }
}

const styles = StyleSheet.create({
  container:{
    flex: 1,
    backgroundColor: 'gray',
    justifyContent: 'center'
  },
  text:{
    fontSize:20
  }
});

Girl.js

import React, {Component} from 'react';
import {
  View,
  StyleSheet,
  Text
} from 'react-native'
export default class Girl extends Component{
  constructor(props){
    super(props);
    this.state = {
      word:''
    }
  }

  render(){
    return (
      <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>
    );
  }
}

const styles = StyleSheet.create({
  container:{
    flex: 1,
    backgroundColor: 'gray',
    justifyContent: 'center'
  },
  text:{
    fontSize:20
  }
});

相關推薦

Navigator實現頁面

reaact-native version:0.57 app.js /** * Sample React Native App * https://github.com/facebook/rea

php中實現頁面的幾種方式

腳本 timeout location clas replace asc idt lee 實現 親測,not復制粘貼 PHP中實現頁面跳轉有一下幾種方式,看了幾個人寫的不是很條理,自己整理一下 在PHP腳本代碼中實現 <?php header("locati

ui li 形式的菜單 實現頁面

頁面跳轉 app /*跳轉*/ jumpEditRectificatBill:function(){ $("#getEquipLegerFrom li").each(function(){ //var jumpid=$(this).attr("id")

用js實現頁面的幾種方式

head 註意 ont rem text pla http bsp cat 通過js或者html或者PHP等動態程序都可以方便的實現跳轉,這裏搜集了幾種頁面跳轉的方式js方式的頁面跳轉1.window.location.href方式 <script langua

ASP.NET MVC中如何實現頁面

pub ring 項目 再見 name ati 方法 技術 mod 1,最簡單的方式:超鏈接 以下分別是連接到HomeController控制器下的SharpL動作方法,以及百度首頁。代碼如下: 1 <a href="Home\SharpL">打開S

php實現頁面方法彙總

一共有三種方法實現頁面跳轉,分別利用php提供的header()、html meta標籤、JavaScript指令碼。 header() header()方法通過設定http響應頭中的location域實現跳轉。這種跳轉實現對使用者是不可見的,有瀏覽器直接執行

實現頁面——Intent

Intent可以理解為信使(意圖),由Intent來協作完成Android各個元件之間的通訊。 Intent實現頁面跳轉 1.直接實現A頁面跳轉到B頁面:startActivity(intent) 2.直接A啟動B頁面,切B頁面可以把資料回傳給A:startActivi

Axure中實現頁面倒計時

在瀏覽一個頁面時,如果跳轉到下一個頁面,一般需要等待幾秒,有些網站就會產生倒計時等待的狀態,這樣一個效果暫且稱為Axure頁面跳轉倒計時。在Axure(http://www.axurechina.cc/)中要實現這樣一個效果需要用到幾個簡單的互動效果,以下將是具體操作流程。關於頁面跳轉的設定

AngularJS進階 八 實現頁面並進行參數傳遞

res 初始化 .get web js進階 頁面 city 過程 元素 angularjs實現頁面跳轉並進行參數傳遞 註:請點擊此處進行充電! Angular頁面傳參有多種辦法,我在此列舉4種最常見的: 1. 基於ui-router的頁面跳轉傳參 (1) 在Angular

AngularJS進階 八 實現頁面並進行引數傳遞

angularjs實現頁面跳轉並進行引數傳遞 注:請點選此處進行充電! Angular頁面傳參有多種辦法,我在此列舉4種最常見的: 1. 基於ui-router的頁面跳轉傳參 (1) 在AngularJS的app.js中用ui-router定義路由,比如現在

微信小程式例子——點選文字實現頁面

1、效果展示 .w 2、關鍵程式碼 index.js檔案 Page({ data:{ // text:"這是一個頁面" }, onLoad:function(options){

使用AJAX實現頁面

$.ajax({ type:"POST", url: //你的請求程式頁面隨便啦 async:false,//同步:意思是當有返回值以後才會進行後面的js程式。 dat

Springboot中使用thymeleaf模板引擎實現頁面

1、建立一個Springboot專案2、在pom.xml中加入thymeleaf模板引擎的依賴 <!-- springboot web開發thymeleaf模板 --> <depend

Java後端實現頁面

頁面跳轉分類有兩種:重定向和轉發,即redirect和forward。具體區別和含義最後介紹,先給出使用方法。一:重定向redirect    第一種方式:controller中返回值為Stringpublic String login(HttpServletRequest

Vue整合vue-router實現頁面出現的問題

1、配置router資料夾下index.js,配置方式一 import Vue from 'vue' import Router from 'vue-router' Vue.use(Router) const routes = [ { path: '/', // 首頁

Laravel通過ajax的POST方式傳值並實現頁面

1.新增測試按鈕 <button class='test' >ajax測試</button> 2.ajax部分程式碼 @section('js') <scr

vue三種不同方式實現頁面

Vue:router-lin <router-link to="/">[跳轉到主頁]</router-link> <router-link to="/login">[登入]</router-link> <router-li

js實現頁面選單選中

<div class="headerpanel"> <div class="headerlist"> <ul> <li class="active" role="cashierMenu

swift UI專項訓練42 用Swift程式碼實現頁面與傳值

   之前我們做過如果要點選一個按鈕實現跳轉到另一個按鈕的辦法,有時候我們需要通過一些動作來觸發頁面的跳轉,比如搖動手機,這樣就不能直接用連線的辦法來實現跳轉了,那麼如何通過程式碼的方式來實現跳轉呢?依舊使用過渡的方法,在storyboard中把要實現跳轉的兩張頁面連線,注

微信小程式實現頁面傳值以及獲取值的方法分析

本文例項講述了微信小程式實現頁面跳轉傳值以及獲取值的方法。分享給大家供大家參考,具體如下:在安卓中頁面跳轉傳值都是通過bundle,現在研究一下小程式的列表跳轉及頁面傳值。my.wxml<view class="container"> <view bind