加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

react-navigation使用

发布时间:2020-12-15 07:18:34 所属栏目:百科 来源:网络整理
导读:index.android.js import { AppRegistry,} from 'react-native';import SimpleApp from './app/SimpleApp'AppRegistry.registerComponent('SimpleApp',() = SimpleApp); SimpleApp.js 'use strict'import React from 'react';import { AppRegistry,Text,View

index.android.js

import {
    AppRegistry,} from 'react-native';
import SimpleApp from './app/SimpleApp'
AppRegistry.registerComponent('SimpleApp',() => SimpleApp);

SimpleApp.js

'use strict'
import React from 'react';
import {
    AppRegistry,Text,View,Button,} from 'react-native';
import { StackNavigator } from 'react-navigation';
import ChatScreen from './ChatScreen';
class HomeScreen extends React.Component {
    static navigationOptions = {
        title: 'Welcome',//设置标题内容
    };

    render() {
        const { navigate } = this.props.navigation;
        return (
            <View>
                <Text>Hello,Navigation!</Text>
                <Button
                    onPress={() => navigate('Chat',{user:'Lucy'})}
                    title="Chat with Lucy"/>
            </View>
        );
    }
}

const SimpleApp = StackNavigator({
    Home: {screen: HomeScreen},Chat:{screen:ChatScreen},});

export default SimpleApp;
ChatScreen.js

'use strict'
import React,{Component} from 'react';
import {View,Text} from 'react-native';
class ChatScreen extends Component{
    static navigationOptions = {
        title:'Chat with Lucy',};
    render(){
        const {params} = this.props.navigation.state;
        return(
            <View>

                <Text>Chat with {params.user}</Text>
            </View>
        );
    }
}
export default ChatScreen;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读