ခဏလေး ဒီလိုပဲ စဉ်းစားကြည့်
Empty state (todo list ဗလာဖြစ်နေရင် 'No todos yet!' ပြသခြင်း) က UX polish ရဲ့ အရေးကြီးတဲ့ အစိတ်အပိုင်းပါ — FlatList ရဲ့ ListEmptyComponent prop ကို သုံးပြီး implement လုပ်လို့ရပါတယ်။ Todo item ကို press လိုက်ရင် Detail screen ဆီ navigate (React Navigation, ယခင်အခန်းများကနေ) လုပ်ပြီး, todo ရဲ့ full detail/edit screen ကို ပြသနိုင်ပါတယ်။
လက်တွေ့ scenario နဲ့ ချိတ်ကြည့်မယ်
FlatList ThemeListEmptyComponent={<Text>No todos yet! Add one above.</Text>} ကို ထည့်ရင် todos array ဗလာဖြစ်ချိန်မှာသာ ပေါ်ပါတယ်။ Todo item ရဲ့ onPress ကို navigation.navigate('TodoDetail', { todoId: item.id }) ဖြင့် ချိတ်ဆက်ပြီး, TodoDetail screen ထဲမှာ route.params.todoId ကနေ todo ကို ရှာပြသနိုင်ပါတယ် (React Navigation ရဲ့ route params pattern)။
Code နမူနာ
<FlatList
data={todos}
keyExtractor={(item) => item.id}
ListEmptyComponent={
<Text style={styles.emptyText}>No todos yet! Add one above 👆</Text>
}
renderItem={({ item }) => (
<TouchableOpacity
style={styles.todoItem}
onPress={() => navigation.navigate('TodoDetail', { todoId: item.id })}
>
<Text>{item.done ? '☑️' : '☐'} {item.text}</Text>
<TouchableOpacity onPress={() => deleteTodo(item.id)}>
<Text>🗑️</Text>
</TouchableOpacity>
</TouchableOpacity>
)}
/>Todo list ဗလာနေချိန် empty state message ပေါ်ပြီး, todo item ကို press လိုက်ရင် Detail screen ဆီ navigate ဖြစ်သွားမည်။၅ မိနစ် စမ်းကြည့်
Todo App ကို ListEmptyComponent + navigation (Detail screen) ဖြင့် ပြီးပြည့်စုံအောင် ဆက်လက် တည်ဆောက်ကြည့်ပါ — ဒါက tutorial တစ်ခုလုံးရဲ့ capstone project ဖြစ်ပါတယ်။
သတိလေးတစ်ချက်
Nested TouchableOpacity (item press + delete button press) ကို React Native မှာ event bubbling behavior က platform (iOS/Android) အလိုက် အနည်းငယ် ကွာနိုင်ပါတယ် — device နှစ်မျိုးလုံးမှာ test လုပ်ကြည့်ပါ။