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

Make text field actions cumulative #660

Open
PavelHolec opened this issue Aug 18, 2023 · 0 comments
Open

Make text field actions cumulative #660

PavelHolec opened this issue Aug 18, 2023 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@PavelHolec
Copy link
Collaborator

PavelHolec commented Aug 18, 2023

Actions that do not return value (such as shouldReturnKey) should be all able to be run in sequence to avoid passing the handler.

The technique works by reassigning the closure by also calling previous closure first:

extension EnvironmentValues {
  public var onSubmitAction: () -> Void {
    get {
      self[TriggerSubmitKey.self]
    } set {
      let oldValue = self[TriggerSubmitKey.self]
      self[TriggerSubmitKey.self] = {
        oldValue()
        newValue()
      }
    }
  }
}

Similar to native onSubmit that is cumulative and runs all provided handlers, not just the innermost one.

https://www.fivestars.blog/articles/onsubmit/

@PavelHolec PavelHolec added the enhancement New feature or request label Aug 18, 2023
@PavelHolec PavelHolec self-assigned this Aug 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant