ရိုးရိုးလေး ရှင်းပြမယ်
Handling User Input ကို ရိုးရိုးလေးနားလည်မယ်
TextInput က text ရိုက်ထည့်ဖို့ component ပါ (HTML ရဲ့ <input> နဲ့ တူ) — value prop နဲ့ onChangeText callback ကို useState နဲ့ ပေါင်းသုံးရင် controlled input ဖြစ်ပါတယ် (user ရိုက်တိုင်း state update)။ Button က basic built-in component ပေမယ့် styling limited ပါတယ် — custom design လိုအပ်ရင် TouchableOpacity/Pressable ကို View+Text နဲ့ ပေါင်းသုံးလေ့ ရှိပါတယ်။
Problem → Why → Solution
ပြဿနာ — ဘာကြောင့် ဒီ concept လိုတာလဲ
onChangeText ကို onChange (web-style) ထင်ပြီး wrong prop name သုံးခြင်း — React Native က onChangeText ဖြစ်ရမည်
ဖြစ်လေ့ရှိတဲ့အမှား
TextInput ကို value/onChangeText မတွဲဘဲ uncontrolled အဖြစ်ထားခြင်း — state နဲ့ sync မဖြစ်
Core Concept — အလုပ်လုပ်ပုံကိုနားလည်မယ်
Handling User Input မှာ navigation state, form state, server state နဲ့ device state တို့၏ owner ကိုခွဲပါ။ Rapid taps, back gesture, deep link, process restart နဲ့ keyboard-only/screen-reader flow များကိုပါစမ်းပါ။
- JavaScript state
- Native component + layout
- Android / iOS UI
Handling User Input ရဲ့ React နဲ့ native platform behavior ကိုရှင်းပြနိုင်ရန်
အဓိက Syntax / Pattern
import { useState } from 'react';
import { View, TextInput, TouchableOpacity, Text, StyleSheet } from 'react-native';
export default function LoginForm() {
const [username, setUsername] = useState('');
const [password, setPassword] = useState('');
return (
<View style={styles.form}>
<TextInput
style={styles.input}
placeholder="Username"
value={username}
onChangeText={setUsername}
/>
<TextInput
style={styles.input}
placeholder="Password"
secureTextEntry
value={password}
onChangeText={setPassword}
/>
<TouchableOpacity style={styles.button} onPress={() => console.log(username)}>
<Text style={styles.buttonText}>Login</Text>
</TouchableOpacity>
</View>
);
}
const styles = StyleSheet.create({
form: { padding: 16 },
input: { borderWidth: 1, borderColor: '#ccc', borderRadius: 8, padding: 12, marginBottom: 12 },
button: { backgroundColor: '#3b82f6', padding: 14, borderRadius: 8, alignItems: 'center' },
buttonText: { color: 'white', fontWeight: '600' },
});Handling User Input မှာ navigation state, form state, server state နဲ့ device state တို့၏ owner ကိုခွဲပါ။ Rapid taps, back gesture, deep link, process restart နဲ့ keyboard-only/screen-reader flow များကိုပါစမ်းပါ။
Code ကို အဆင့်လိုက်ဖတ်မယ်
- JavaScript state
import { useState } from 'react';TextInput က text ရိုက်ထည့်ဖို့ component ပါ (HTML ရဲ့ <input> နဲ့ တူ) — value prop နဲ့ onChangeText callback ကို useState နဲ့ ပေါင်းသုံးရင် controlled input ဖြစ်ပါတယ် (user ရိုက်တိုင်း state update)။ Button က basic built-in component ပေမယ့် styling limited ပါတယ် — custom design လိုအပ်ရင် TouchableOpacity/Pressable ကို View+Text နဲ့ ပေါင်းသုံးလေ့ ရှိပါတယ်။
- Native component + layout
secureTextEntryHandling User Input မှာ navigation state, form state, server state နဲ့ device state တို့၏ owner ကိုခွဲပါ။ Rapid taps, back gesture, deep link, process restart နဲ့ keyboard-only/screen-reader flow များကိုပါစမ်းပါ။
- Android / iOS UI
});Handling User Input 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
Handling User Input ရဲ့ React နဲ့ native platform behavior ကိုရှင်းပြနိုင်ရန်
Failure
onChangeText ကို onChange (web-style) ထင်ပြီး wrong prop name သုံးခြင်း — React Native က onChangeText ဖြစ်ရမည်
ခဏလေး ဒီလိုပဲ စဉ်းစားကြည့်
TextInput က text ရိုက်ထည့်ဖို့ component ပါ (HTML ရဲ့ <input> နဲ့ တူ) — value prop နဲ့ onChangeText callback ကို useState နဲ့ ပေါင်းသုံးရင် controlled input ဖြစ်ပါတယ် (user ရိုက်တိုင်း state update)။ Button က basic built-in component ပေမယ့် styling limited ပါတယ် — custom design လိုအပ်ရင် TouchableOpacity/Pressable ကို View+Text နဲ့ ပေါင်းသုံးလေ့ ရှိပါတယ်။
လက်တွေ့ scenario နဲ့ ချိတ်ကြည့်မယ်
Login form တစ်ခု ဆောက်မယ်ဆိုရင် username/password အတွက် TextInput နှစ်ခု, submit button တစ်ခု လိုအပ်ပါတယ် — password field ကို secureTextEntry={true} ထည့်ရင် dot (••••) အဖြစ် ဖျောက်ပြပါတယ်။ TouchableOpacity ကို Button အစား သုံးရင် custom color/border/padding ပေးလို့ရပါတယ် — Button component ကတော့ platform default style ကိုပဲ သုံးရမှာမို့ customize ခက်ပါတယ်။
Code နမူနာ
import { useState } from 'react';
import { View, TextInput, TouchableOpacity, Text, StyleSheet } from 'react-native';
export default function LoginForm() {
const [username, setUsername] = useState('');
const [password, setPassword] = useState('');
return (
<View style={styles.form}>
<TextInput
style={styles.input}
placeholder="Username"
value={username}
onChangeText={setUsername}
/>
<TextInput
style={styles.input}
placeholder="Password"
secureTextEntry
value={password}
onChangeText={setPassword}
/>
<TouchableOpacity style={styles.button} onPress={() => console.log(username)}>
<Text style={styles.buttonText}>Login</Text>
</TouchableOpacity>
</View>
);
}
const styles = StyleSheet.create({
form: { padding: 16 },
input: { borderWidth: 1, borderColor: '#ccc', borderRadius: 8, padding: 12, marginBottom: 12 },
button: { backgroundColor: '#3b82f6', padding: 14, borderRadius: 8, alignItems: 'center' },
buttonText: { color: 'white', fontWeight: '600' },
});Login form ပေါ်မှာ username/password ရိုက်ထည့်နိုင်ပြီး Login button press လိုက်ရင် username ကို console မှာ print ထုတ်လာမည်။၅ မိနစ် စမ်းကြည့်
Login form ကို ကိုယ်တိုင် ဆောက်ကြည့်ပါ — TextInput ၂ ခု (username, password) နဲ့ TouchableOpacity button တစ်ခု ပါစေပါ။
သတိလေးတစ်ချက်
Password TextInput မှာ secureTextEntry ပေးရုံနဲ့ password ကို 'လုံခြုံ' ပြီလို့ မယူဆပါနှင့် — visual masking ပဲ ဖြစ်ပြီး, actual transmission/storage security ကို backend side မှာ သီးခြား handle ရပါမယ်။
Real-world usage
လက်တွေ့ Project မှာ ဘယ်လိုသုံးမလဲ
Handling User Input 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
ကိုယ်တိုင်တည်ဆောက်ကြည့်ပါ
Handling User Input 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 { useState } from 'react';
import { View, TextInput, TouchableOpacity, Text, StyleSheet } from 'react-native';
export default function LoginForm() {
const [username, setUsername] = useState('');
const [password, setPassword] = useState('');
return (
<View style={styles.form}>
<TextInput
style={styles.input}
placeholder="Username"
value={username}
onChangeText={setUsername}
/>
<TextInput
style={styles.input}
placeholder="Password"
secureTextEntry
value={password}
onChangeText={setPassword}
/>
<TouchableOpacity style={styles.button} onPress={() => console.log(username)}>
<Text style={styles.buttonText}>Login</Text>
</TouchableOpacity>
</View>
);
}
const styles = StyleSheet.create({
form: { padding: 16 },
input: { borderWidth: 1, borderColor: '#ccc', borderRadius: 8, padding: 12, marginBottom: 12 },
button: { backgroundColor: '#3b82f6', padding: 14, borderRadius: 8, alignItems: 'center' },
buttonText: { color: 'white', fontWeight: '600' },
});ရလဒ်: Handling User Input ရဲ့ React နဲ့ native platform behavior ကိုရှင်းပြနိုင်ရန်
အရိပ်အမြွက် ကြည့်ရန်
Handling User Input 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
- Handling User Input မှာ navigation state, form state, server state နဲ့ device state တို့၏ owner ကိုခွဲပါ။ Rapid taps, back gesture, deep link, process restart နဲ့ keyboard-only/screen-reader flow များကိုပါစမ်းပါ။
- onChangeText ကို onChange (web-style) ထင်ပြီး wrong prop name သုံးခြင်း — React Native က onChangeText ဖြစ်ရမည်
- Handling User Input 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