ရိုးရိုးလေး ရှင်းပြမယ်
Layout with Flexbox ကို ရိုးရိုးလေးနားလည်မယ်
React Native မှာ View တိုင်းရဲ့ default flexDirection က 'column' ပါ (web CSS ရဲ့ 'row' default နဲ့ ဆန့်ကျင်ဘက်) — child component တွေက default အနေနဲ့ အပေါ်ကနေအောက် အစီစီ arrange ဖြစ်ပါတယ်။ flexDirection: 'row' ပြောင်းရင် ဘေးချင်းကပ် arrange ဖြစ်ပါတယ်။ justifyContent က main axis ပေါ်မှာ spacing ချုပ်ကိုင်ပြီး (flex-start, center, space-between), alignItems က cross axis ပေါ်မှာ alignment ချုပ်ကိုင်ပါတယ် (flex-start, center, stretch)။
Problem → Why → Solution
ပြဿနာ — ဘာကြောင့် ဒီ concept လိုတာလဲ
Web CSS ရဲ့ default flexDirection: row ကို ယူဆပြီး React Native (column default) မှာ layout မှားခြင်း
ဖြစ်လေ့ရှိတဲ့အမှား
Fixed width/height ကိုပဲ သုံးပြီး flex: 1 ကို လျစ်လျူရှုခြင်း — screen size မတူတဲ့ device မှာ layout ပျက်နိုင်
Core Concept — အလုပ်လုပ်ပုံကိုနားလည်မယ်
Layout with Flexbox ကို screen တစ်ခုအတွက် style syntax အဖြစ်သာမမြင်ဘဲ Yoga constraints, pixel density, font scaling, safe areas, keyboard, touch target, accessibility tree နဲ့ iOS/Android behavior ကွာခြားမှုတို့ပါသော native UI contract အဖြစ်နားလည်ပါ။
- JavaScript state
- Native component + layout
- Android / iOS UI
Layout with Flexbox ရဲ့ React နဲ့ native platform behavior ကိုရှင်းပြနိုင်ရန်
အဓိက Syntax / Pattern
const styles = StyleSheet.create({
header: {
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
padding: 16,
},
content: {
flex: 1, // remaining space ကို ယူ
justifyContent: 'center',
alignItems: 'center',
},
});Layout with Flexbox ကို screen တစ်ခုအတွက် style syntax အဖြစ်သာမမြင်ဘဲ Yoga constraints, pixel density, font scaling, safe areas, keyboard, touch target, accessibility tree နဲ့ iOS/Android behavior ကွာခြားမှုတို့ပါသော native UI contract အဖြစ်နားလည်ပါ။
Code ကို အဆင့်လိုက်ဖတ်မယ်
- JavaScript state
const styles = StyleSheet.create({React Native မှာ View တိုင်းရဲ့ default flexDirection က 'column' ပါ (web CSS ရဲ့ 'row' default နဲ့ ဆန့်ကျင်ဘက်) — child component တွေက default အနေနဲ့ အပေါ်ကနေအောက် အစီစီ arrange ဖြစ်ပါတယ်။ flexDirection: 'row' ပြောင်းရင် ဘေးချင်းကပ် arrange ဖြစ်ပါတယ်။ justifyContent က main axis ပေါ်မှာ spacing ချုပ်ကိုင်ပြီး (flex-start, center, space-between), alignItems က cross axis ပေါ်မှာ alignment ချုပ်ကိုင်ပါတယ် (flex-start, center, stretch)။
- Native component + layout
},Layout with Flexbox ကို screen တစ်ခုအတွက် style syntax အဖြစ်သာမမြင်ဘဲ Yoga constraints, pixel density, font scaling, safe areas, keyboard, touch target, accessibility tree နဲ့ iOS/Android behavior ကွာခြားမှုတို့ပါသော native UI contract အဖြစ်နားလည်ပါ။
- Android / iOS UI
});Layout with Flexbox example ကို Android/iOS, small/large screens, font scaling, dark mode, keyboard, screen reader, slow/offline network, denied permissions နဲ့ app background/foreground cases ဖြင့်စမ်းပါ။ DevTools, tests နဲ့ release build ကိုလိုအပ်သလိုအသုံးပြုပါ။
- JavaScript state
- Native component + layout
- Android / iOS UI
Success
Layout with Flexbox ရဲ့ React နဲ့ native platform behavior ကိုရှင်းပြနိုင်ရန်
Failure
Web CSS ရဲ့ default flexDirection: row ကို ယူဆပြီး React Native (column default) မှာ layout မှားခြင်း
ခဏလေး ဒီလိုပဲ စဉ်းစားကြည့်
React Native မှာ View တိုင်းရဲ့ default flexDirection က 'column' ပါ (web CSS ရဲ့ 'row' default နဲ့ ဆန့်ကျင်ဘက်) — child component တွေက default အနေနဲ့ အပေါ်ကနေအောက် အစီစီ arrange ဖြစ်ပါတယ်။ flexDirection: 'row' ပြောင်းရင် ဘေးချင်းကပ် arrange ဖြစ်ပါတယ်။ justifyContent က main axis ပေါ်မှာ spacing ချုပ်ကိုင်ပြီး (flex-start, center, space-between), alignItems က cross axis ပေါ်မှာ alignment ချုပ်ကိုင်ပါတယ် (flex-start, center, stretch)။
လက်တွေ့ scenario နဲ့ ချိတ်ကြည့်မယ်
Header bar (logo ဘယ်ဘက်, menu icon ညာဘက်) ကို ဆောက်ချင်ရင် flexDirection: 'row', justifyContent: 'space-between' ကို View style ထဲ ထည့်ရုံပါ — child ၂ ခုက automatic ကြားခြားထွက်သွားပါလိမ့်မယ်။ flex: 1 ကို child component ရဲ့ style ထဲ ထည့်ရင် available space ကို ယူပါတယ် — screen size အမျိုးမျိုးမှာ responsive ဖြစ်စေချင်ရင် fixed width/height အစား flex ကို သုံးတာက ပိုကောင်းပါတယ်။
Code နမူနာ
const styles = StyleSheet.create({
header: {
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
padding: 16,
},
content: {
flex: 1, // remaining space ကို ယူ
justifyContent: 'center',
alignItems: 'center',
},
});Header bar တစ်ခုကို flexDirection: row နဲ့ ဆောက်ပြီး logo/icon ကို ဘေးချင်းကပ် arrange လုပ်နိုင်မည်။၅ မိနစ် စမ်းကြည့်
flexDirection: 'row' ပါတဲ့ View တစ်ခုထဲမှာ box ၃ ခု ထည့်ပြီး justifyContent ကို 'flex-start', 'center', 'space-between' သုံးမျိုးနဲ့ စမ်းကြည့်ပါ။
သတိလေးတစ်ချက်
flex: 1 ကို parent container မှာ height သတ်မှတ်မထားရင် (root View က flex: 1 ရှိမှ) အလုပ်မဖြစ်နိုင်ပါဘူး — parent-child flex chain ကို သတိထားပါ။
Real-world usage
လက်တွေ့ Project မှာ ဘယ်လိုသုံးမလဲ
Layout with Flexbox example ကို Android/iOS, small/large screens, font scaling, dark mode, keyboard, screen reader, slow/offline network, denied permissions နဲ့ app background/foreground cases ဖြင့်စမ်းပါ။ DevTools, tests နဲ့ release build ကိုလိုအပ်သလိုအသုံးပြုပါ။
Mini challenge
ကိုယ်တိုင်တည်ဆောက်ကြည့်ပါ
Layout with Flexbox example ကို Android/iOS, small/large screens, font scaling, dark mode, keyboard, screen reader, slow/offline network, denied permissions နဲ့ app background/foreground cases ဖြင့်စမ်းပါ။ DevTools, tests နဲ့ release build ကိုလိုအပ်သလိုအသုံးပြုပါ။
- Example ကို copy မလုပ်ဘဲ ပြန်ရေးပါ
- Normal input နဲ့ edge case စမ်းပါ
- Run မလုပ်မီ compiler/output result ကိုခန့်မှန်းပါ
const styles = StyleSheet.create({
header: {
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
padding: 16,
},
content: {
flex: 1, // remaining space ကို ယူ
justifyContent: 'center',
alignItems: 'center',
},
});ရလဒ်: Layout with Flexbox ရဲ့ React နဲ့ native platform behavior ကိုရှင်းပြနိုင်ရန်
အရိပ်အမြွက် ကြည့်ရန်
Layout with Flexbox example ကို Android/iOS, small/large screens, font scaling, dark mode, keyboard, screen reader, slow/offline network, denied permissions နဲ့ app background/foreground cases ဖြင့်စမ်းပါ။ DevTools, tests နဲ့ release build ကိုလိုအပ်သလိုအသုံးပြုပါ။
Quick Quiz 1 / 3
Quick Quiz 2 / 3
Quick Quiz 3 / 3
ဒီသင်ခန်းစာမှာ မှတ်ထားရမယ့်အချက်များ
- JavaScript state → Native component + layout → Android / iOS UI
- Layout with Flexbox ကို screen တစ်ခုအတွက် style syntax အဖြစ်သာမမြင်ဘဲ Yoga constraints, pixel density, font scaling, safe areas, keyboard, touch target, accessibility tree နဲ့ iOS/Android behavior ကွာခြားမှုတို့ပါသော native UI contract အဖြစ်နားလည်ပါ။
- Web CSS ရဲ့ default flexDirection: row ကို ယူဆပြီး React Native (column default) မှာ layout မှားခြင်း
- Layout with Flexbox example ကို Android/iOS, small/large screens, font scaling, dark mode, keyboard, screen reader, slow/offline network, denied permissions နဲ့ app background/foreground cases ဖြင့်စမ်းပါ။ DevTools, tests နဲ့ release build ကိုလိုအပ်သလိုအသုံးပြုပါ။
React Native Documentation — React Native