ScottRobbins / DeclarativeLayout

A declarative, expressive and efficient way to lay out your views.
MIT License
5 stars 0 forks source link

Allow specifying identifier for view #29

Closed ScottRobbins closed 5 years ago

ScottRobbins commented 5 years ago

One of the annoying things right now is that if you need a container view, or a layout guide, you have to pass in an instance of a view. This forces you to create a property to hold it, give it a name, etc. For things like stackviews and layout guides you rarely want to use this property outside of the layout method, and you may be creating a lot of them (especially for arranged subviews of stackviews).

To make that a little easier, I added the ability for users to call addView (and the others) without passing in an instance of a view and it would create one. The issue with this is if you need to update the view later, the new layout that is updated will have different views instantiated for this, so diffing will cause unnecessary restructuring of the view hierarchy and layout passes.

Instead, I'd like to add the ability to call addView(identifier:) (or something like that), so you wouldn't need to create a property, you'd just need to pass a unique identifier for that view. That way when you update the layout later, the framework can find the view it already has based on that identifier and reuse it.

ScottRobbins commented 5 years ago

done here: https://github.com/HotCocoaTouch/DeclarativeLayout/pull/35