There's a nasty SwiftUI bug in which a
TextField disappears if placed in a
HStack within a
List.List {
ForEach(0...200, id: \.self) { index in
HStack {
Text("Text \(index)")
TextField("Test", text: .constant("TextField \(index)"))
}
}
}- Screenshot: https://i.stack.imgur.com/HARDF.png
- Video: https://recordit.co/X12uGct7gD
This happens when
TextField is placed within a
HStack / VStack / ZStack / .overlay() / .background(). It does not happen when
TextField is the only child of
ForEach.
I have filed a bug (FB7500885) but I'm looking for ideas from the community to work around it. Here is what I've tried so far:
- Setting an explicit
on.frame()TextField - Setting
on.fixedSized()TextField - Using a
wrapped in aUITextField
, with or without layout constraintsUIViewConvertible
Is there anything else I could try?