Giter Club home page Giter Club logo

navigationdemo's Introduction

Navigator(导航)

导航器通过路由对象(route)来分辨不同的场景。每个路由对象都对应一个路由组件,开发者设置什么, 导航器显示什么,所以route是导航器中重要的一个对象。

三步操作实现导航功能:

  1. 设置路由对象,(告诉导航器要显示哪个页面)

创建路由对象,对象的内容自定义,但是必须包含该场景需要展示的页面组件

  1. 场景渲染配置,告诉导航器需要什么样的页面跳转效果

  2. 渲染场景(告诉导航器如何渲染页面)

利用第一步设置的路由对象进行渲染场景

Navigator传值

  • 例子

      import React, { Component } from 'react';
      import {
          AppRegistry,
          StyleSheet,
          Text,
          View,
          Platform,
          Button
      } from 'react-native';
      
      import {StackNavigator} from 'react-navigation';
      
      class HomeScreen extends Component {
          static navigationOptions={
              title:'Home'
          }
      
          render() {
              const {navigate}=this.props.navigation;
              return (
                  <View>
                      <Text>home</Text>
                      <Button onPress={()=>navigate('Chat',{user:'lucy',password:'123'})} title='go to chat'></Button>
                  </View>
              );
          }
      }
      
      class ChatScreen extends Component{
          static navigationOptions=({navigation})=>{
              title:`Chat with ${navigation.state.params.user}`
          };
      
          render(){
              const {params}=this.props.navigation.state
              return (
                  <View>
                      <Text>chat with {params.user} ;password:{params.password}</Text>
                  </View>
              );
          }
      }
      
      const styles = StyleSheet.create({
          container: {
              flex: 1,
              justifyContent: 'center',
              alignItems: 'center',
              backgroundColor: '#F5FCFF',
          },
      
      });
      
      const SimpleApp=StackNavigator({
          Home:{screen:HomeScreen},
          Chat:{screen:ChatScreen}
      })
      
      AppRegistry.registerComponent('NavigationDemo', () => SimpleApp);
    

navigationdemo's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.