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

SwiftUI: Calling didSelect (and other callbacks) twice overrides the previous callback without warning #576

Closed
Amzd opened this issue May 25, 2021 · 1 comment

Comments

@Amzd
Copy link

Amzd commented May 25, 2021

view.onDidSelect = action

Calling didSelect (and other callbacks) twice overrides the previous callback without warning.

Say a user wants to do some logic in their model and some logic for view state in their SwiftUI view this won't work:

PageView(...) {
    // ...
}
.didSelect(model.didSelectPage)
.didSelect(updateViewState(forSelectedPage:)) // Only the last one is called

but instead they have to put both calls in one didSelect.

This is not a big problem but calls to onAppear which are similar in API can be called multiple times so users might expect that.

I think there should either be an assert to check if didSelect (or a different callback) was previously set and let the user know that this won't work OR append the new closures to the previous one.

@rechsteiner
Copy link
Owner

Hey! Sorry about the delay. This is now fixed in the 4.0 branch and will be out soon (#677)

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

2 participants