Parchment icon indicating copy to clipboard operation
Parchment copied to clipboard

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

Open Amzd opened this issue 3 years ago • 0 comments

https://github.com/rechsteiner/Parchment/blob/c9268f4a987229f43e2ac9153d4596cf17ac36e7/Parchment/Structs/PageView.swift#L87

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.

Amzd avatar May 25 '21 09:05 Amzd