Replies: 1 comment 3 replies
-
|
Hi @Lieksu, this is a general problem of "data sources", where you have a collection of data that you want to use to power a collection of views. The same problem exists in collection views, but UIKit provides a nice solution via diffable data sources. Also SwiftUI provides a nice solution via I think the best solution is to basically recreate what And there is probably a general tool we could make to help with this, but we haven't yet figured out its correct shape. We will think about it more. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi there!
UIKitNavigation looks promising and I can't wait to see the details of how it was built.
I've been experimenting with a slightly simplified version of Observable UIKit for the past month and one use-case I just can't get right: initialization of a view that should observe something inside another
observecall.Problem
Here's an example:
My goal is to redraw the collection when the number of elements changes and redraw a single element when its properties change. The problem is that I call AuthorView.init in the observe method, and the name property is accessed inside the observe method in the collection view. If the name property changes, the observe method on the collection is called, and every single view is recreated.
Options I've tried:
observemethod to finish and create views on the next tick of the RunLoop, we do not register access to thenameproperty from it. I do not really like this approach asDispatchQueue.main.asyncis typically used to ensure something is executed on the main thread, not to schedule an operation for the next tick. Mixing@MainActorandDispatchQueue.main.asyncalso does not seem like the way forward.namechanges the first time, but it will not be called subsequent times. As far as I understand, thenameproperty was not called on the second pass, and observation is not registered again, but it stays active in the child view. This looks better, but it is not ideal because it is not obvious to the reader of the code what is happening here and why we have only one unnecessary execution of closure inobserveafter every necessary one.I am curious if this use case is valid and, if so, how you would approach this problem. Any insights or suggestions would be greatly appreciated.
Beta Was this translation helpful? Give feedback.
All reactions