Thuta Learning
ရှာဖွေရန်
IntermediateMobile Developmentintermediate

Tab & Drawer Navigation

စိတ်လျှော့ပါ။ ဒီခန်းကို စာအုပ်လိုမဟုတ်ဘဲ စကားပြောသလိုပဲ၊ နားလည်လွယ်အောင် ရှင်းပါမယ်။

ဒီခန်းပြီးရင် ဘာတတ်သွားမလဲ

  • Tab & Drawer Navigation ကို ကြောက်စရာမလိုအောင် နားလည်မယ်
  • ကိုယ်တိုင် code ရေးပြီး Expo Go ပေါ်မှာ run ကြည့်တတ်မယ်
  • Real app project ထဲမှာ ဒီ concept ကို ချက်ချင်း အသုံးချတတ်မယ်

ခဏလေး ဒီလိုပဲ စဉ်းစားကြည့်

Bottom Tab Navigator က screen major section (Home, Search, Profile) ကို screen အောက်ခြေက tab icon တွေနဲ့ ပြသပြီး, tab တစ်ခုစီက ကိုယ်ပိုင် Stack Navigator ကို ကိုင်ဆောင်နိုင်ပါတယ် (nested navigator pattern)။ Drawer Navigator က side menu (hamburger icon နှိပ်ရင် ဘေးက slide ထွက်လာတဲ့ menu) ကို implement လုပ်ပါတယ် — setting, secondary feature တွေအတွက် သုံးလေ့ရှိပါတယ်။

လက်တွေ့ scenario နဲ့ ချိတ်ကြည့်မယ်

Instagram/Twitter type app တွေမှာ Bottom Tab (Home, Search, Notifications, Profile) ကို အများဆုံးတွေ့ရပါတယ် — user thumb-reach (phone အောက်ခြေ) ကို ထိတွေ့လွယ်လို့ mobile UX pattern အနေနဲ့ standard ဖြစ်ပါတယ်။ Nested navigation (Tab ထဲမှာ Stack ထပ်ထည့်) ကို လုပ်ရင် Home tab ထဲက post တစ်ခု click လိုက်ရင် Home tab's stack ထဲကနေ Detail screen ကို push လုပ်ပြီး, Tab bar ကတော့ ဆက်ရှိနေပါတယ်။

Code နမူနာ

javascript
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import HomeScreen from './HomeScreen';
import ProfileScreen from './ProfileScreen';

const Tab = createBottomTabNavigator();

function MainTabs() {
  return (
    <Tab.Navigator>
      <Tab.Screen name="Home" component={HomeScreen} />
      <Tab.Screen name="Profile" component={ProfileScreen} />
    </Tab.Navigator>
  );
}
You should see
App ရဲ့ အောက်ခြေမှာ Home/Profile tab icon ၂ ခု ပေါ်လာပြီး tap လိုက်ရင် screen ပြောင်းသွားမည်။

၅ မိနစ် စမ်းကြည့်

createBottomTabNavigator ကို install ပြီး Home/Profile tab ၂ ခု ကိုယ်တိုင် ဆောက်ကြည့်ပါ။

သတိလေးတစ်ချက်

Bottom Tab Navigator ရေးတဲ့အခါ package name ကို @react-navigation/native-stack (Stack) နဲ့ @react-navigation/bottom-tabs (Tab) ကွဲပြားနေတာ သတိထားပါ — install command မှားရင် import error ဖြစ်ပါလိမ့်မယ်။

ဒီနေရာမှာ လူအများမှားတတ်တယ်

  • Bottom Tab ထဲမှာ screen အများကြီးထည့်ပြီး (၅ ခုကျော်) UX overload ဖြစ်ခြင်း — tab item ၅ ခုအောက် ဆက်ထားသင့်
  • Nested navigator (Tab ထဲက Stack) ကို setup လုပ်ခင် architecture ကို အရင်ကြိုမစဉ်းစားထားခြင်း

အခု ကိုယ်တိုင် စမ်းကြည့်

createBottomTabNavigator ကို install ပြီး Home/Profile tab ၂ ခု ကိုယ်တိုင် ဆောက်ကြည့်ပါ။

You'll know it worked when: App ရဲ့ အောက်ခြေမှာ Home/Profile tab icon ၂ ခု ပေါ်လာပြီး tap လိုက်ရင် screen ပြောင်းသွားမည်။

Tab & Drawer Navigation | Thuta Learning