react-navigation导航入门

A. 导入相关库

a. 安装react-navigation库

npm install react-navigation

b. 安装react-native-gesture-handler库

npm install react-native-gesture-handler

c. 安装react-native-reanimated库

npm install react-native-reanimated

另:要求react-native在0.60之上

B. iOS需要pod install

安装react-native-gesture-handler

C. 一个简单的Demo

import React from 'react';

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

import { createStackNavigator, createAppContainer } from 'react-navigation';

class HomeScreen extends React.Component {

  render() {

    return (

     

        Home Screen

     

    );

  }

}

class DetailsScreen extends React.Component {

  render() {

    return (

     

        Details Screen

     

    );

  }

}

const RootStack = createStackNavigator(

  {

    Home: HomeScreen,

    Details: DetailsScreen,

  },

  {

    initialRouteName: 'Home',

  }

);

const AppContainer = createAppContainer(RootStack);

export default class App extends React.Component {

  render() {

    return ;

  }

}


react-navigation导航入门_第1张图片

D. 页面切换---跳转到新的页面

class HomeScreen extends React.Component {

  render() {

    return (

     

        Home Screen

       

你可能感兴趣的:(react-navigation导航入门)