OAStackView
OAStackView copied to clipboard
[WIP] Fixes issues with the arrangedSubviews property
This is quite a big PR, so please bear with me and let me know if you are open for changes like this.
I found that the arrangedSubviews
property was not properly implemented. For starters, it was always nil
. Looking for a solution, I found that the heavy reliance on self.subviews
made it impossible to implement arranged subviews. I started shuffling things around and here we are...
Main improvements:
- arrangedSubviews is now non-nil and should be kvo'able
- removing an arranged view now does not remove the view as a subview
- it should now be possible to have subviews in the OAStackView that are not managed by the stack view
All the tests pass and the example project runs fine, but I'd like to do some more testing in my own project. Let me know what you think!
I've discovered some bugs after I filed the PR, so it definitely deserves the [WIP]
annotation. I will push additional changes, but in the meantime it would be great if you think this direction is favorable.
This looks like a change to the correct direction, working with visible views was not really the optimal solution and I wanted to move away from it. I agree with your decision with going with arranged view storage. I am really interested in seeing where this path leads :+1: Great work!
I just pushed some more commits to this PR. Not all of them strictly relate to the arrangedSubviews change, but I've been trying to make improvements to OAStackView
while integrating it into a project at work and some changes now depend on each other. ffcde3b
for example has more to do with #14 (and #14 should not be merged without it). I'll explain the additional changes:
-
3058581
the subviews of the stack need to shrink if the stack's size is constrained. The intrinsicContentSize based approach did not cover this. Instead, the alignment strategies now add additional constraints to make sure that the stack and subviews grow/shrink together. -
ffcde3b
this is needed for #14 or else the baseline constraints will not be removed properly. I am not sure about the compiler checks for the newerNSLayoutAttributes
. Let me know what you think. -
fc97522
implements theUIStackView
approach for baseline aligning a stack view itself. I'm not sure if this is as powerful asUIStackView
, since we're probably missing some private API that will update the baseline alignment when the contents of the stack changes.
@Thomvis — Ping on this one? I just ran into some of the arrangedSubviews
you described here and am wondering what the state of this is. Thanks!