首页 > 其他 > 详细

use react-navigation@2.18.2

时间:2020-06-11 11:52:30      阅读:58      评论:0      收藏:0      [点我收藏+]

react-native@0.59.10

1.install

npm install react-navigation@2.18.2

2.in App.js

import React from ‘react‘;
import { View, Text, Button } from ‘react-native‘;
import { createStackNavigator, StackActions, NavigationActions } from ‘react-navigation‘; // Version can be specified in package.json

class HomeScreen extends React.Component {
  render() {
    return (
      <View style={{ flex: 1, alignItems: ‘center‘, justifyContent: ‘center‘ }}>
        <Text>Home Screen</Text>
        <Button
          title="Go to Details"
          onPress={() => {
            this.props.navigation.dispatch(StackActions.reset({
              index: 0,
              actions: [
                NavigationActions.navigate({ routeName: ‘Details‘ })
              ],
            }))
          }}
        />
      </View>
    );
  }  
}

class DetailsScreen extends React.Component {
  render() {
    return (
      <View style={{ flex: 1, alignItems: ‘center‘, justifyContent: ‘center‘ }}>
        <Text>Details Screen</Text>
      </View>
    );
  }  
}
const RootStack = createStackNavigator({
  Home: {
    screen: HomeScreen,
  },
  Details: {
    screen: DetailsScreen,
  },
}, {
    initialRouteName: ‘Home‘,
});

export default class App extends React.Component {
  render() {
    return <RootStack />;
  }
}

 

use react-navigation@2.18.2

原文:https://www.cnblogs.com/dch0/p/13091735.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!