N
N
Nikita2020-06-08 14:13:02
iOS
Nikita, 2020-06-08 14:13:02

Why does the keyboard fall off after each character entered in the SwiftUI TextField and how best to fix it?

I have an ObservableObject in parent View and child View:

import Parchment

class MainViewModel: ObservableObject {
    @Published var inputText = String()

    init() {}
}

struct ChildView: View {
    @EnvironmentObject var viewModel: MainViewModel

    var body: some View {
          PageView(/**/) {
          TextField("", $viewModel.inputText)
}
}
    }
}


Tried placing inputText in ObservedObject of child View, nothing changed.
As soon as I enter one character, the keyboard disappears. Apparently, SwiftUI starts redrawing the entire page, as a result of which the TextField ceases to be active.
How can this be fixed? Maybe somehow force the activation of the TextField, or call the keyboard?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question