Replies: 2 comments 6 replies
-
This is an unfortunate behavior change in SwiftUI that we've filed feedback for, and I encourage you to do the same. As you mention it affects vanilla SwiftUI, as well, but has a greater potential to be noticed by a TCA app. These potential extra emissions have always been present in SwiftUI, but they've grown to affect many more APIs with the latest release. As far as we can tell the best way to work around the problem is to add a extension Binding where Value: Equatable {
func removeDuplicates() -> Self {
.init(
get: { self.wrappedValue },
set: { newValue, transaction in
guard newValue != self.wrappedValue else { return }
self.transaction(transaction).wrappedValue = newValue
}
)
}
} (Thanks to @iampatbrown for the transaction logic that helps binding animations work as one would expect.) You could introduce a It is possible for |
Beta Was this translation helpful? Give feedback.
-
There is another workaround I know. Just append |
Beta Was this translation helpful? Give feedback.
-
After some tests on our app on iOS 15 / TCA, we discovered that all bindings values are always emitted twice.
It's not a TCA-related problem, but it looks like binding system has changed in iOS 15.
Did you heard anything about that ?
A simple code to reproduce, in TCA & Vanilla SwiftUI :
Tested on iOS 14, bindings are emitted only once.
And it's worse than that ! If you ever set the bound property in your reducer on a different action for example, it will emit a new
textUpdated
action automatically on update, because binding is also triggered after that : before iOS 15, it was not.Beta Was this translation helpful? Give feedback.
All reactions