Loading [MathJax]/jax/output/CommonHTML/config.js
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >如何自定义材料底部标签导航在反应本机?

如何自定义材料底部标签导航在反应本机?
EN

Stack Overflow用户
提问于 2021-04-25 19:36:07
回答 2查看 4.7K关注 0票数 2

我试图自定义颜色的材料底部选项卡导航到LinearGradient。

为了实现这一点,我使用了expo线性梯度,我使用道具来传递方法,但是我不知道如何访问customTabBar函数中的这些道具。

下面是包含选项卡的代码

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
import React from "react";
import { View, Text, StyleSheet, Image, ImageBackground } from "react-native";
import { createMaterialBottomTabNavigator } from "@react-navigation/material-bottom-tabs";

import MainHomeScreen from "./MainHomeScreen";
import CustomTabBar from "./CustomTabBar";

import * as Icons from "@expo/vector-icons";
import { LinearGradient } from "expo-linear-gradient";

const Tab = createMaterialBottomTabNavigator();

const BottomTabScreen = () => {
  return (
    <>
      <Tab.Navigator
        screenOptions={{ tabBarLabel: false }}
        barStyle={(props) => <CustomTabBar {...props} />}
      >
        <Tab.Screen
          name="MainHomeScreen"
          component={MainHomeScreen}
          options={{
            tabBarIcon: ({ focused }) => (
              <>
                <Icons.Feather name="home" color="#fff" size={24} />
              </>
            ),
          }}
        />
      </Tab.Navigator>
    </>
  );
};

export default BottomTabScreen;

const styles = StyleSheet.create({
  shadow: { elevation: 5 },
  dot: {
    width: 4,
    height: 4,
    borderRadius: 7,
    marginTop: 5,
    backgroundColor: "#fff",
  },
  linearGradient: {
    height: 30,
    width: 50,
  },
});

这是自定义选项卡栏的代码:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
import React from "react";
import { View, Text, StyleSheet } from "react-native";

const CustomTabBar = ({ state, navigationState }) => {
  console.log(navigationState);
  return <View style={styles.tabs}>
    {state.route.map((route, index) => {
      
    })}
  </View>;
};

export default CustomTabBar;

const styles = StyleSheet.create({
  tabs: {
    position: "absolute",
    bottom: 15,
    left: 20,
    right: 20,
    elevation: 2,
    borderRadius: 20,
    backgroundColor: "transparent",
    borderTopLeftRadius: 15,
    borderTopRightRadius: 15,
    overflow: "hidden",
  },
});
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-04-25 21:18:54

CustomTabBar for createBottomTabNavigator

你的方法是正确的。检查快餐店的实现。你会知道如何实现这一目标的。

编写完下面的代码后,只需按需要更改Gradient color arrays即可。

你的BottomTabNavigator应该是这样..。

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
import * as React from 'react';
import { View } from 'react-native';
import { useTheme } from '@react-navigation/native';
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';

import CustomTabBar from '../components/CustomTapBar';
import ScreenOne from '../screens/ScreenOne';
import Favourites from '../screens/Favourites';

const Tab = createBottomTabNavigator();

function RootNavigation() {
  const { colors } = useTheme();

  return (
    <View style={{ flex: 1, backgroundColor: colors.background }}>
      <Tab.Navigator tabBar={(props) => <CustomTabBar {...props} />}>
        <Tab.Screen name="ScreenOne" component={ScreenOne} />
        <Tab.Screen name="Favourites" component={Favourites} />
      </Tab.Navigator>
    </View>
  );
}

export default RootNavigation;

你的CustomTabBar应该是这样的-

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
import React, { Component } from 'react';
import { View, Text, TouchableOpacity } from 'react-native';
import { LinearGradient } from 'expo-linear-gradient';

const FocusedGradient = ['#4c669f', '#3b5998', '#192f6a'];
const NotFocusedGradient = ['#ffffff', '#ffffff'];

function CustomTabBar({ state, descriptors, navigation }) {
  const focusedOptions = descriptors[state.routes[state.index].key].options;

  if (focusedOptions.tabBarVisible === false) {
    return null;
  }

  return (
    <View style={{ flexDirection: 'row' }}>
      {state.routes.map((route, index) => {
        const { options } = descriptors[route.key];
        const label =
          options.tabBarLabel !== undefined
            ? options.tabBarLabel
            : options.title !== undefined
            ? options.title
            : route.name;

        const isFocused = state.index === index;

        const onPress = () => {
          const event = navigation.emit({
            type: 'tabPress',
            target: route.key,
            canPreventDefault: true,
          });

          if (!isFocused && !event.defaultPrevented) {
            navigation.navigate(route.name);
          }
        };

        const onLongPress = () => {
          navigation.emit({
            type: 'tabLongPress',
            target: route.key,
          });
        };

        return (
          <LinearGradient
            colors={isFocused ? FocusedGradient : NotFocusedGradient}
            style={{
              flex: 1,
              backgroundColor: isFocused ? 'dodgerblue' : 'white',
            }}>
            <TouchableOpacity
              accessibilityRole="button"
              accessibilityState={isFocused ? { selected: true } : {}}
              accessibilityLabel={options.tabBarAccessibilityLabel}
              testID={options.tabBarTestID}
              onPress={onPress}
              onLongPress={onLongPress}
              style={{
                minHeight: 50,
                justifyContent: 'center',
                alignItems: 'center',
              }}>
              <Text style={{ color: isFocused ? 'white' : '#222' }}>
                {label}
              </Text>
            </TouchableOpacity>
          </LinearGradient>
        );
      })}
    </View>
  );
}

export default CustomTabBar;
票数 2
EN

Stack Overflow用户

发布于 2021-04-25 21:53:56

createBottomTabNavigator.中创建CustomTabBar使用世博遵循下面的示例。createBottomTabNavigator (CustomTabBar)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67260538

复制
相关文章
微信小程序|底部标签导航
制作标签导航首先需要我们自己将找到的图片保存进目录文件夹里,小程序界面会自动更新,然后再在App.json配置文件。
算法与编程之美
2020/02/13
1.6K0
微信小程序|底部标签导航
Flutter 中自定义动画底部导航栏
在这个博客中,我们将探索Flutter中的自定义动画底部导航栏。我们将看到如何实现自定义动画底部导航栏的演示程序以及如何在您的 Flutter 应用程序中使用它。
老孟Flutter
2021/07/15
9K0
Flutter 中自定义动画底部导航栏
taro+react导航条组件/自定义底部Tabbar导航
最近在研究taro框架技术,发现官方提供的实例基本都是H5、小程序,对于RN端实例甚少,如是自己就实现了自定义导航栏+tabbar组件,支持自定义背景、颜色、左侧图标、标题居中、搜索框,右侧按钮支持图标/文字/图片,还可以设置样式,红点提示、事件处理
andy2018
2019/11/27
7.8K1
taro+react导航条组件/自定义底部Tabbar导航
手把手教你如何自定义 React Native 底部导航栏
如果你觉得 React Navigation 默认 Tab 组件看起来太平淡,或者想创造一些更现代的东西,那么你想法就和我一样。 在本指南中,我将向你演示如何创建自定义标签栏以并与 React Navigation 一起使用。
前端小智@大迁世界
2019/04/25
7.7K0
手把手教你如何自定义 React Native  底部导航栏
【Flutter】底部导航栏实现 ( BottomNavigationBar 底部导航栏 | BottomNavigationBarItem 导航栏条目 | PageView )
Flutter 中的 Scaffold 组件实现了基础的材料设计 ( Material Design ) 可视化布局结构 ;
韩曙亮
2023/03/29
6.2K0
【Flutter】底部导航栏实现 ( BottomNavigationBar 底部导航栏 | BottomNavigationBarItem 导航栏条目 | PageView )
底部导航栏效果
<template> <view class="me"> 消息列表界面 </view> </template> <script> import wepy from 'wepy'; export default class Me extends wepy.component { components = { } methods = { }; } </script> <template> <view class="me"> 联系人界面
达达前端
2022/04/29
3.8K0
底部导航栏效果
在 Flutter 中创建漂亮的底部导航栏
ConvexBottomBar是一个底部导航栏组件,用于展现凸起的TAB效果,支持多种内置样式与动画交互。你可以在https://appbar.codemagic.app上找到在线样例。
徐建国
2022/03/30
8.2K0
在 Flutter 中创建漂亮的底部导航栏
小程序底部导航
"navigationBarBackgroundColor": "#1296db",
万泉
2019/11/06
8980
小程序底部导航
【Flutter】底部导航栏页面框架 ( BottomNavigationBar 底部导航栏 | PageView 滑动页面 | 底部导航与滑动页面关联操作 )
在 Scaffold 的 bottomNavigationBar 属性设置底部导航栏 ;
韩曙亮
2023/03/29
4.6K0
【Flutter】底部导航栏页面框架 ( BottomNavigationBar 底部导航栏 | PageView 滑动页面 | 底部导航与滑动页面关联操作 )
添加网站手机底部导航 [FONT AWESOME图标版]
代码引用:(放入主题footer.php文件中) <div id="mobile-footer"> <ul id="mobile-menu"> <li> <a href="https://wuzuhua.cn/"> <span class="fa fa-home"></span> 首页 </a></li> <li> <a href="https://wuzuhua.cn/wy"> <span class="fa fa-twitch"></span> 微语 </a
空木白博客
2019/05/25
3.9K0
仿qq底部Tab导航
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/gdutxiaoxu/article/details/52826810
程序员徐公
2018/09/18
2K0
仿qq底部Tab导航
Handsome底部页脚标签样式
在 usr/themes/handsome/component/footer.php中删掉以下代码
kenvie
2022/01/20
8320
Handsome底部页脚标签样式
点击加载更多

相似问题

反应本机材料-底部标签标签对齐布局

16

反应本机导航-底部标签位置绝对

11

反应本机导航-底部标签和抽屉

21

如何去除反应本机中材料的背景颜色-底部标签

18

反应本机底部导航隐藏

21
添加站长 进交流群

领取专属 10元无门槛券

AI混元助手 在线答疑

扫码加入开发者社群
关注 腾讯云开发者公众号

洞察 腾讯核心技术

剖析业界实践案例

扫码关注腾讯云开发者公众号
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文