Sunday, November 8, 2026
HomeiOS Developmentios - SwiftUI the right way to take care of onEditingChanged for...

ios – SwiftUI the right way to take care of onEditingChanged for textual content area

[ad_1]

I used to make use of this TextField API for modifying change callback (instance utilization: to test if enter is legitimate after carried out modifying):

init(_ titleKey: LocalizedStringKey, textual content: Binding<String>, onEditingChanged: @escaping (Bool) -> Void, onCommit: @escaping () -> Void)

It is marked as deprecated within the doc, with a rationalization:

Use init(_:textual content:immediate:) as a substitute. Add the onSubmit(of:_:) view modifier for the onCommit habits. Use FocusState and centered(_:equals:) for the onEditingChanged habits.

I’m not positive the right way to use centered(_:equals:) for onEditingChanged. It doesn’t have a callback when this area is finished modifying.


struct MyTextField {
  let binding: Binding<Textual content>

  var physique: some View {
    TextField("Enter Quantity", textual content: binding) // there was a `onEditingChanged` callback right here, but it surely's deprecated. 
      .keyboardType(.decimalPad)
  }
}

enum Area {
  case heightField
  case weightField
}


struct HomeView {

  @FocusState
  non-public var focusedField: Area?

  var physique: some View {

    MyTextField(binding: $top) 
      .centered($focusedField, equals:.heightField)

    MyTextField(binding: $weight)
      .centered($focusedField, equals:.weightField)

  }
}

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments