ခဏလေး ဒီလိုပဲ စဉ်းစားကြည့်
`VStack` ထဲမှာ `ForEach` သုံးရင် child view အားလုံးကို တစ်ပြိုင်နက် render လုပ်ပါတယ် — item ၁၀၀၀ ရှိရင် performance ကျဆင်းနိုင်ပါတယ် (scroll လုပ်ဖို့ `ScrollView` ကို manual ထပ်ထားရပါ)။ `List` ကတော့ built-in scrollable container ပါ — visible item ကိုသာ efficiently render (lazy loading, Android ရဲ့ `LazyColumn`/RecyclerView နဲ့ ဆင်တူပါတယ်), swipe-to-delete/pull-to-refresh စတဲ့ native iOS behavior ကိုပါ built-in ပေးပါတယ်.
လက်တွေ့ scenario နဲ့ ချိတ်ကြည့်မယ်
Todo list app မှာ `List(todos) { todo in TodoRow(todo: todo) }` လို့ ရေးရင် — todo item ၁၀၀ ရှိပေမယ့် screen ပေါ်မှာ visible ဖြစ်နေတဲ့ item များကိုပဲ render လုပ်ပြီး, native iOS scroll/swipe behavior (swipe-to-delete) ကိုပါ အလိုအလျောက် ရရှိပါတယ် — `todos` ရဲ့ item တစ်ခုချင်းစီက `Identifiable` protocol ကို conform လုပ်ထားဖို့ လိုပါတယ် (TodoItem ရဲ့ `id` property ကနေ).
အတူတူ ကြည့်မယ်
struct TodoListScreen: View {
let todos: [TodoItem]
var body: some View {
List(todos) { todo in
HStack {
Image(systemName: todo.isDone ? "checkmark.circle.fill" : "circle")
Text(todo.title)
}
}
}
}Todo item ၅-၁၀ ခုကို scroll လုပ်ရင် native iOS style (swipe-to-delete ပါ) ဖြင့် ကြည့်ရှုနိုင်တဲ့ list ကို Simulator ပေါ်မှာ တွေ့ရမည်။၅ မိနစ် စမ်းကြည့်
`TodoItem` (Basic chapter struct) ရဲ့ array (item ၁၀ ခု sample data) ကို create ပြီး `TodoListScreen` ကို run ကြည့်ပါ — scroll လုပ်ကြည့်ပြီး smooth ဖြစ်တာ confirm လုပ်ကြည့်ပါ။
သတိလေးတစ်ချက်
`List` ရဲ့ default styling (row separator, background) ကို remove/customize ချင်ရင် `.listStyle()` modifier ကို သုံးရပါမယ် — default appearance က design mockup နဲ့ မကိုက်ညီနိုင်ပါ။