RN 的scrollable-tab-view控件(同一页面选择切换)

一. 基础选项卡

这里写图片描述


1.引入依赖:

在终端引入依赖:     npm install react-native-scrollable-tab-view –save


2. 在   index.ios.js   文件中

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

var ScrollableTabView = require('react-native-scrollable-tab-view'); //引入控件,并在终端添加依赖    npm install react-native-scrollable-tab-view --save
var MoveList = require("./movieListView"); //也可以引入一个页面使用
var MyList = require("./myListView"); //也可以引入一个页面使用
var Movie = require("./movieList"); //也可以引入一个页面使用

var App = React.createClass({
    render() {
        return (
            <ScrollableTabView>
                <MoveList tabLabel="React" />
                <Movie tabLabel="Flow" />
                <MyList tabLabel="Jest" />
            </ScrollableTabView>
        );
    }
});


AppRegistry.registerComponent('HelloReactNative', () => App);






二. 具有导航功能的选项卡

这里写图片描述



1.引入依赖

在终端引入依赖:     npm install react-native-scrollable-tab-view –save
在终端引入依赖:     npm install react-navigation –save


2. 在   index.ios.js   文件中

import React from 'react';
import {
    AppRegistry,
    Text,
    Button,
    View,
} from 'react-native';
import { StackNavigator } from 'react-navigation';
var ScrollableTabView = require('react-native-scrollable-tab-view'); //引入控件,并在终端添加依赖    npm install react-native-scrollable-tab-view --save
var MoveList = require("./movieListView"); //也可以引入一个页面使用
var MyList = require("./myListView"); //也可以引入一个页面使用
var Movie = require("./movieList"); //也可以引入一个页面使用

var App = React.createClass({
    render() {
        return (
            <ScrollableTabView
                tabBarPosition='bottom' >
                {/*tabBarPosition   //可以设置顶部或者底部选项*/}
                {/*{...this.props} //指定导航页*/}
                <RecentChatsScreen tabLabel="React" {...this.props} />
                <AllContactsScreen tabLabel="Flow" {...this.props} />

            </ScrollableTabView>
        );
    }
});

class ChatScreen extends React.Component {
    // Nav options can be defined as a function of the screen's props:
    static navigationOptions = ({ navigation }) => ({
        title: `Chat with ${navigation.state.params.user}`,
    });
    render() {
        // The screen's current route is passed in to `props.navigation.state`:
        const { params } = this.props.navigation.state;
        return (
            <View>
                <Text>Chat with {params.user}</Text>
            </View>
        );
    }
}

class RecentChatsScreen extends React.Component {
    render() {
        const { navigate } = this.props.navigation;
        return (
            <View>
                <Text>List of recent chats</Text>
                <Button
                    onPress={() => navigate('Chat', {user: 'Lucy'})} //Passing params
                    title="Chat with Lucy"
                />
            </View>
        );
    }
}

class AllContactsScreen extends React.Component {
    render() {
        const { navigate } = this.props.navigation;
        return (
            <View>
                <Text>List of all contacts</Text>
                <Button
                    //跳转
                    onPress={() => navigate('Chat', {user: 'Jane'})} //Passing params
                    title="Chat with Jane"
                />
            </View>
        );
    }
}



App.navigationOptions = {
    title: 'My Chats',
};

const SimpleAppReactNavigation = StackNavigator({
    Home: { screen: App },  //第一栈
    Chat: { screen: ChatScreen },           //第二栈
});

AppRegistry.registerComponent('HelloReactNative', () => SimpleAppReactNavigation);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小毅哥哥

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值