Open JonasDeichelmann opened 4 years ago
For anyone interested - I encountered this as well, and the only fix I found was explicitly setting isEditing as state variable on my View, so that it would remember value, but not reset every time:
// This state property is actually never used by this view, and serves as a storage of editing state for text view.
@State private var isEditing: Bool = true
var body: some View {
VStack {
TextView(text: $model.text, isEditing: $isEditing)
TextField("Placeholder", text: $model.textForTextfield)
}
}
This seems like a small design flaw, since TextView should remember it's state, but what happens view hierarchy changes for any reason(editing textfield is one of them), TextView may be recreated by SwiftUI, and if you passed .constant(true)
as isEditing property, view will be recreated with focus. With my @State
workaround, isEditing is stored outside of TextView, and therefore the issue does not happen.
@DenTelezhkin Thank you for your solution! As we still recognize SwiftUI is in the beginning.
Hey, sorry for not making this clear. I should have mentioned in the README that it is not possible to set a constant Binding variable for isEditing, and it must be set on the view so that it isn't recreated. So I wouldn't call it a workaround, but instead a necessary thing to do.
Hi,
I want to use the TextView in a Form, but it always jumps to the textview when the user is typing something into other Form-TextFields. That mades the TextView unusable.
Cheers, Jonas