react-native-tab-navigator 拓展 - 隐藏和显示底部导航

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/mytxooqq/article/details/71642143
react-native-tab-navigator 拓展 - 隐藏和显示底部导航


/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 * @flow
 */

import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  Image
} from 'react-native';

import TabNavigator from 'react-native-tab-navigator';
var _this = null;
export default class D20170510 extends Component {
    constructor(props){
        super(props);
        this.state = {
           defaultSelected:'1',
           defaultTabHeight:52
        }
        _this = this;
    }

    onPress(data){
        var height = _this.state.defaultTabHeight;

        //1
        // var timer = setInterval(() => {
        //
        //     if(data) {
        //         //显示
        //         height+=;
        //         if(height > 52){
        //             clearInterval(timer);
        //             return;
        //         }
        //     }else{
        //         //隐藏
        //         height--;
        //         if(height < 0){
        //             clearInterval(timer);
        //             return;
        //         }
        //     }
        //
        //     _this.setState({
        //         defaultTabHeight:height
        //     });
        // },10);

        //2
        var height = 0;
        if(data){
            height = 52;
        }else{
            height = 0;
        }

        _this.setState({
            defaultTabHeight:height
        });
    }
  render() {
    return (
        <TabNavigator
            sceneStyle={{
                backgroundColor:'green',
                paddingBottom:this.state.defaultTabHeight
            }}
            tabBarStyle={{
                backgroundColor:'pink',
                height:this.state.defaultTabHeight,
                overflow:'hidden'
            }}
            tabBarShadowStyle={{
                backgroundColor:'green'
            }}
            hidesTabTouch={true}
            >

            <TabNavigator.Item
                allowFontScaling={false}
                tabStyle={{
                    backgroundColor:'blue'
                }}
                titleStyle={{
                    color:'red',
                    paddingBottom:10
                }}
                selectedTitleStyle={{
                    color:'green',
                    paddingBottom:0
                }}
                badgeText={2}
                renderBadge={() => {
                    return (
                        <Text style={{
                                backgroundColor:'red',
                            }}>{'666'}</Text>
                    );
                }}
                renderIcon={() => {
                    return (
                        <Image
                            source={require("./img/未标题-1.png")}
                            style={{
                                height:26,
                                width:26
                            }}
                            />
                    );
                }}
                renderSelectedIcon={() => {
                    return (
                        <Image
                            source={require("./img/未标题-2.png")}
                            style={{
                                height:26,
                                width:26
                            }}
                            />
                    );
                }}
                selected={this.state.defaultSelected == 1}
                title={'第一个'}
                onPress={() => {
                    this.setState({
                        defaultSelected:1
                    });
                }}
                >
                {<Main1
                    op={this.onPress}
                    />}
            </TabNavigator.Item>

            <TabNavigator.Item
                selected={this.state.defaultSelected == 2}
                title={'第二个'}
                onPress={() => {
                    this.setState({
                        defaultSelected:2
                    });
                }}
                >
                {<Main2/>}
            </TabNavigator.Item>

            <TabNavigator.Item
                selected={this.state.defaultSelected == 3}
                title={'第三个'}
                onPress={() => {
                    this.setState({
                        defaultSelected:3
                    });
                }}
                >
                {<Main3/>}
            </TabNavigator.Item>


        </TabNavigator>
    );
  }
}


class Main1 extends Component {


    render (){
        return (
            <View style={styles.container}>
                <Text>{'main1'}</Text>
                <Text onPress={this.props.op.bind('',false)}>{'点击隐藏底部导航'}</Text>
                <Text onPress={this.props.op.bind('',true)}>{'点击显示底部导航'}</Text>
            </View>
        );
    }
}

class Main2 extends Component {
    render (){
        return (
            <View style={styles.container}>
                <Text>{'main2'}</Text>
            </View>
        );
    }
}

class Main3 extends Component {
    render (){
        return (
            <View style={styles.container}>
                <Text>{'main3'}</Text>
            </View>
        );
    }
}



const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor:'#fff'
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
});

AppRegistry.registerComponent('D20170510', () => D20170510);

阅读更多

没有更多推荐了,返回首页