RN0.57新版本实现TabNavigator自定义中间凸出Tab

第一次写技术博客_(:°з」∠)_

第一次写技术博客,以往都是伸手党,这次难得自己想写个博客,最近才从游戏转行做RN,所以很多东西都不懂,这次的博客中代码也是很多借鉴了其他大佬的博客内容。项目中要实现一个Tabber中凸出一个按钮的效果,类似闲鱼App中“+”按钮的样式。参考了很多大佬的写法,我同事找到最方便的是tabBarButtonComponent这个东东,有兴趣的可以去看一下,我这里介绍的是大佬们重新渲染TabBar的方式。

代码部分

// An highlighted block
import React, {
   
    Component } from 'react';
import {
   
   
    Text,
    View,
    TouchableOpacity,
} from 'react-native';

export default class Tab extends Component {
   
   

    renderItem = (route, index) => {
   
   
        const {
   
   
            navigation,
        } = this.props;

        const focused = index === navigation.state.index;
        const color = focused ? this.props.activeTintColor : this.props.inactiveTintColor;
        let TabScene = {
   
   
            focused: focused,
            route: route,
            tintColor: color
        };

        if (index === 1) {
   
   
            return (<View
                key={
   
   route.key}
                style={
   
   [styles.tabItem, {
   
    backgroundColor: 'transparent' }]}>
            </View>
            );
        }

        return (
            <TouchableOpacity
                key={
   
   route.key}
                style={
   
   styles.tabItem}
                onPress={
   
   () => this.props.jumpTo(route.key)}
            >
                <View
                    style={
   
   styles.tabItem}>
                    {
   
   this.props.renderIcon(TabScene)}
                    <Text style={
   
   {
   
    ...styles.tabText, marginTop: SCALE(10), color }}>{
   
   this.props.getLabelText(TabScene)}</Text>
                
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值