-
-
Notifications
You must be signed in to change notification settings - Fork 60
Description
ScrollView
Scroll view layout is surprisingly tricky. The main complicating factor is choosing whether or not to include the scroll bars. In certain situations, it can look like you've made the wrong choice regardless of whether you choose to include the scroll bars or not. For example, if you have a view of constant aspect ratio inside a scroll view, and the scroll view is slightly too short to fit the view, then you must show the scroll bars, but the act of showing the scroll bar decreases the width of the scroll view's content, and therefore its height due to its constant aspect ratio, causing the scroll bar to appear useless. The only consistent choice to make is to include the scroll bar, cause otherwise the content will overflow. Last time I checked, SwiftUI handled this edge case worse than SwiftCrossUI. It ends up flickering between having the scroll bar and not having it constantly. I believe that SwiftCrossUI handles the situation correctly, just not efficiently, but I'll have to double check.
I've included this edge case because it's something that we have to make sure we still handle correctly after optimising the ScrollView layout implementation.
Ideal width VStacks (and ideal height HStacks)
Ideal width VStacks with a proposed height (and equivalent HStacks) are tricky to lay out consistently. The expected behaviour, in English terms, is that the stack should allocate its height to its children as usual (greedily) while letting each child take on its ideal width. Then the stack should take on the width of the widest child and all other children should expand their widths to match the widest element. The issue is that giving the children more width could cause the the heights of the children to change, causing a knock-on effect of each child getting proposals that differ more and more from the original proposals. I don't believe that there's a way to solve the problem perfectly without at least having a closed form for the sizing behaviour of each child of the stack. You either have to risk under-utilising the proposed height, or not have the widths laid out how you might expect, or both.
I noticed this issue while trying to spec out SwiftCrossUI's layout algorithm a bit better. The first time that I tried to test out this edge case, I instantly managed to break SwiftUI's layout algorithm.
It's kinda interesting that these issues that I noticed on paper are real issues faced by SwiftUI. I think we can handle them better than SwiftUI.
I'll update this issue as I find more edge cases.