Convert Binding to UIBinding
#336
Unanswered
maximkrouk
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Currently I'm using a workaround:
Note
onDidSetis injected through dynamic member lookup withswift-keypath-mapping[setter:]subscriptI just figured out this approach and I think I had a few weird moments related to values sync (still testing, I have a scrollable picker that sends fractional values pretty frequently, tho all the values are rounded to .2f). Probably it's related to willSet/didSet sync and could be resolved with replacing setter to
.onWillSetor using both (.perform(onWillSet:onDidSet:)) and an internalTaskLocalBoolthat can be checked inonChangeHowever maybe there is just a simpler way to convert
BindingtoUIBinding🤔There was a discussion related to conversion in other direction #280, however it's related to TCA rather than
swift-navigation. It's understandable that it's possible to derive both types of bindings from anObservableobject, but in my case anObservableobject (a TCAStore🙂) is declared in higher-level feature module, and the component has to be declared in lower-levelAppUImodule. And I'd like to avoid exposing UIBinding from SwiftUI component 🫠UPD:
This seem to work correctly and without any visual artifacts:
But more direct conversion tips are still appreciated
All reactions