ရိုးရိုးလေး ရှင်းပြမယ်
Styling with StyleSheet ကို ရိုးရိုးလေးနားလည်မယ်
StyleSheet.create() က style object တွေကို validate/optimize လုပ်ပေးတဲ့ helper function ပါ — plain object ({ }) ကို တိုက်ရိုက်သုံးလည်း အလုပ်ဖြစ်ပေမယ့် StyleSheet.create ကို သုံးတာ performance ပိုကောင်းပြီး style error ကို development mode မှာ warning ပြပေးပါတယ်။ Property name တွေက CSS နဲ့ ဆင်တူပေမယ် camelCase ဖြစ်ပါတယ် (background-color → backgroundColor), unit မလိုအပ်ပါဘူး (px မထည့်ရ, number ချည်း ရေးပါတယ်)။
Problem → Why → Solution
ပြဿနာ — ဘာကြောင့် ဒီ concept လိုတာလဲ
CSS unit (px, em) ကို React Native style ထဲ ထည့်ရေးမိခြင်း — number ချည်းသာ ရေးရပါတယ်
ဖြစ်လေ့ရှိတဲ့အမှား
kebab-case (background-color) ကို camelCase အစား ရေးမိခြင်း
Core Concept — အလုပ်လုပ်ပုံကိုနားလည်မယ်
Styling with StyleSheet ကို 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
Styling with StyleSheet ရဲ့ React နဲ့ native platform behavior ကိုရှင်းပြနိုင်ရန်
အဓိက Syntax / Pattern
import { StyleSheet, View, Text } from 'react-native';
const styles = StyleSheet.create({
card: {
backgroundColor: '#f0f0f0',
borderRadius: 12,
padding: 16,
marginBottom: 8,
},
title: {
fontSize: 18,
fontWeight: '600',
color: '#1a1a2e',
},
});
// Combining styles conditionally
<View style={[styles.card, isActive && styles.activeCard]}>
<Text style={styles.title}>Card Title</Text>
</View>Styling with StyleSheet ကို 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
import { StyleSheet, View, Text } from 'react-native';StyleSheet.create() က style object တွေကို validate/optimize လုပ်ပေးတဲ့ helper function ပါ — plain object ({ }) ကို တိုက်ရိုက်သုံးလည်း အလုပ်ဖြစ်ပေမယ့် StyleSheet.create ကို သုံးတာ performance ပိုကောင်းပြီး style error ကို development mode မှာ warning ပြပေးပါတယ်။ Property name တွေက CSS နဲ့ ဆင်တူပေမယ် camelCase ဖြစ်ပါတယ် (background-color → backgroundColor), unit မလိုအပ်ပါဘူး (px မထည့်ရ, number ချည်း ရေးပါတယ်)။
- Native component + layout
fontSize: 18,Styling with StyleSheet ကို 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
</View>Styling with StyleSheet 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
Styling with StyleSheet ရဲ့ React နဲ့ native platform behavior ကိုရှင်းပြနိုင်ရန်
Failure
CSS unit (px, em) ကို React Native style ထဲ ထည့်ရေးမိခြင်း — number ချည်းသာ ရေးရပါတယ်
ခဏလေး ဒီလိုပဲ စဉ်းစားကြည့်
StyleSheet.create() က style object တွေကို validate/optimize လုပ်ပေးတဲ့ helper function ပါ — plain object ({ }) ကို တိုက်ရိုက်သုံးလည်း အလုပ်ဖြစ်ပေမယ့် StyleSheet.create ကို သုံးတာ performance ပိုကောင်းပြီး style error ကို development mode မှာ warning ပြပေးပါတယ်။ Property name တွေက CSS နဲ့ ဆင်တူပေမယ် camelCase ဖြစ်ပါတယ် (background-color → backgroundColor), unit မလိုအပ်ပါဘူး (px မထည့်ရ, number ချည်း ရေးပါတယ်)။
လက်တွေ့ scenario နဲ့ ချိတ်ကြည့်မယ်
Style object များစွာကို component တစ်ခုမှာ ပေါင်းသုံးချင်ရင် array syntax သုံးလို့ရပါတယ် — style={[styles.base, styles.active]} ဆိုရင် base style အရင်သုံးပြီး active style ကို override လုပ်ပါတယ် (array ရဲ့ နောက်ဆုံး item က priority အမြင့်ဆုံး)။ Conditional styling (ဥပမာ button pressed state) ကို ဒီ array pattern နဲ့ လွယ်လွယ်ကူကူ implement လုပ်နိုင်ပါတယ်။
Code နမူနာ
import { StyleSheet, View, Text } from 'react-native';
const styles = StyleSheet.create({
card: {
backgroundColor: '#f0f0f0',
borderRadius: 12,
padding: 16,
marginBottom: 8,
},
title: {
fontSize: 18,
fontWeight: '600',
color: '#1a1a2e',
},
});
// Combining styles conditionally
<View style={[styles.card, isActive && styles.activeCard]}>
<Text style={styles.title}>Card Title</Text>
</View>Card component တစ်ခုကို StyleSheet.create နဲ့ style ချနိုင်ပြီး conditional style ကို array syntax နဲ့ ပေါင်းသုံးနိုင်မည်။၅ မိနစ် စမ်းကြည့်
Card style (backgroundColor, borderRadius, padding) ကို ကိုယ်တိုင် ရေးပြီး, isActive true ဖြစ်ရင် border color ပြောင်းတဲ့ conditional style ထပ်ထည့်ကြည့်ပါ။
သတိလေးတစ်ချက်
Style property အားလုံးက CSS နဲ့ တူတယ်လို့ မယူဆပါနှင့် — 'display: flex' ကို default အနေနဲ့ View တိုင်းမှာ ရှိပြီးသားပါ, ဒါပေမယ့် flexDirection default က 'column' ပါ (CSS web ရဲ့ 'row' default နဲ့ ကွဲပါတယ်)။
Real-world usage
လက်တွေ့ Project မှာ ဘယ်လိုသုံးမလဲ
Styling with StyleSheet 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
ကိုယ်တိုင်တည်ဆောက်ကြည့်ပါ
Styling with StyleSheet 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 ကိုခန့်မှန်းပါ
import { StyleSheet, View, Text } from 'react-native';
const styles = StyleSheet.create({
card: {
backgroundColor: '#f0f0f0',
borderRadius: 12,
padding: 16,
marginBottom: 8,
},
title: {
fontSize: 18,
fontWeight: '600',
color: '#1a1a2e',
},
});
// Combining styles conditionally
<View style={[styles.card, isActive && styles.activeCard]}>
<Text style={styles.title}>Card Title</Text>
</View>ရလဒ်: Styling with StyleSheet ရဲ့ React နဲ့ native platform behavior ကိုရှင်းပြနိုင်ရန်
အရိပ်အမြွက် ကြည့်ရန်
Styling with StyleSheet 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
- Styling with StyleSheet ကို screen တစ်ခုအတွက် style syntax အဖြစ်သာမမြင်ဘဲ Yoga constraints, pixel density, font scaling, safe areas, keyboard, touch target, accessibility tree နဲ့ iOS/Android behavior ကွာခြားမှုတို့ပါသော native UI contract အဖြစ်နားလည်ပါ။
- CSS unit (px, em) ကို React Native style ထဲ ထည့်ရေးမိခြင်း — number ချည်းသာ ရေးရပါတယ်
- Styling with StyleSheet 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