On iOS 15, if you display a List
of VStack
s with a Text
and DatePicker
as below
@main
struct WeirdListDatePickerProblem: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
struct ContentView: View {
let listRows: [Int] = (0...100).map { $0 }
var body: some View {
List(listRows, id: \.self) { v in
RowView()
}
}
}
struct RowView: View {
@State var date: Date = Date()
var body: some View {
VStack {
Text("If you remove this then the problem disappears")
DatePicker("", selection: $date, displayedComponents: [.date])
.labelsHidden()
}
}
}
then the screen is mangled as below.
It becomes worse the more you scroll. This has been seen on the simulator and on a real device using iOS 15.5 with Xcode 13.4.1.
If you remove the Text
then the problem disappears.
How, on iOS 15, can you display list items with a Text
and DatePicker
without the above happening?