stevengharris / SplitView

A flexible way to split SwiftUI views with a draggable splitter
MIT License
146 stars 17 forks source link

Fraction animation #36

Open artemkrachulov opened 5 months ago

artemkrachulov commented 5 months ago

Hi, very good solution for splitting views. Can you help to understand one thing about animation. How can I animate fraction value? For example on button tap, animate splitting. Code withAnimation { fraction.value = 0.75 } doesn't work.

stevengharris commented 5 months ago

The animation needs to be done in the Split view itself, since it observes the fraction changes:

.onChange(of: fraction.value) { new in withAnimation { constrainedFraction = new } } //<-Line 102

I made this change in https://github.com/stevengharris/SplitView/issues/29, but I did not make it animate by default. I suppose that would be consistent with the hide/show defaults. I don't think this has any other weird side-effects, but it's been a while since I looked at it. Let me know if this works for you and if you see any other weirdnesses that might be associated with it. Thanks.