Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG - When using TextView in Form #26

Open
JonasDeichelmann opened this issue Jun 5, 2020 · 3 comments
Open

BUG - When using TextView in Form #26

JonasDeichelmann opened this issue Jun 5, 2020 · 3 comments

Comments

@JonasDeichelmann
Copy link

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

@DenTelezhkin
Copy link

DenTelezhkin commented Jun 18, 2020

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.

@JonasDeichelmann
Copy link
Author

@DenTelezhkin Thank you for your solution!
As we still recognize SwiftUI is in the beginning.

@kenmueller
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants