Bottom Tab

Bottom Tab Layout คือ view ที่ใช้รับค่า หน้าของ children views ที่เกี่ยวข้องกับ tab แต่ละปุ่ม

Source Code

React Native
Copy
import { createBottomTabNavigator } from "@react-navigation/bottom-tabs";

export default function BottomTab({
  tabList,
  onTab,
  backgroundColor = "#fff",
}) {
  const Tab = createBottomTabNavigator();

  const screenOptions = {
    tabBarShowLabel: false,
    tabBarHideOnKeyboard: true,
    headerShown: false,
    tabBarItemStyle: { paddingTop: 4 },
    tabBarStyle: {
      backgroundColor: backgroundColor,
      elevation: 10,
      height: 60,
    },
  };

  return (
    <Tab.Navigator screenOptions={screenOptions}>
      {tabList?.map((item, index) => (
        <Tab.Screen
          key={"tab-item-" + index}
          listeners={{
            tabPress: (e) => {
              if (onTab) {
                onTab(index);
              }
            },
          }}
          name={item.name}
          component={item.component}
          options={{
            tabBarIcon: () => item.icon,
          }}
        />
      ))}
    </Tab.Navigator>
  );
}

Usage

React Native
Copy
import { NavigationContainer } from "@react-navigation/native";
import { useState } from "react";

import Home from "../../page/Home";
import Option from "../../page/Option";

import IconHome from "../element/output/IconHome";
import BottomTab from "./BottomTab";

export default function TestView() {
  
  const tabBackGround = "#efefef";
  const iconColor = "#444";
  const iconActiveColor = "#00f";

  const [selectTab, setSelectTab] = useState(0);

  const tabList = [
    {
      name: "Home",
      component: Home,
      icon: (
        <IconHome
          color={0 == selectTab ? iconActiveColor : iconColor}
          width={25}
        />
      ),
    },
    {
      name: "Option",
      component: Option,
      icon: (
        <IconHome
          color={1 == selectTab ? iconActiveColor : iconColor}
          width={25}
        />
      ),
    },
  ];

  const handleClickTab = (e) => {
    setSelectTab(e);
  };

  return (
    <NavigationContainer>
      <BottomTab
        backgroundColor={tabBackGround}
        onTab={handleClickTab}
        tabList={tabList}
      />
    </NavigationContainer>
  );
}

Properties

Property

Description

Type

Default

tabList

array of tab data for render view example:[{name: "Home", component: Home, icon: ,},]

array

onTab

function ดูทำงานเมื่อมีการกด จะส่งค่า index ที่ tab 

function

backgroundColor

สีพื้นหลัง tab bar

string

"#fff"

Requirements

@react-navigation/native @react-navigation/bottom-tabs

ยักซ่า (Yakxar)
สร้างสรรค์และแบ่งปันสื่อดิจิทัลง่ายๆ ที่นี่
© 2025 ยักซ่า (Yakxar)