stevengharris / SplitView

A flexible way to split SwiftUI views with a draggable splitter

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bug when hiding splitview while using minimum fractions

bastiaanterhorst opened this issue · comments

Hi,
I'm using a simple horizontal split set up like this:

@State private var minPFraction = 0.1 // 100 at default width of 1000

--snip--

           VStack {
                Split(primary: {
                    Color.teal
                }, secondary: {
                    Color.green
                })
                .constraints(minPFraction: minPFraction, priority: .left, dragToHideP: true)
                .fraction(fraction)
                .hide(hide)
                
                Button("Toggle Hide") {
                    withAnimation {
                            if(hide.side == .left) {
                                hide.toggle()
                            } else {
                                hide.hide(.left)
                            }
                    }
                }
            }

When I click hide to toggle hiding the left split it hides but the whole split narrows in width revealing the content below the split view on the right side:

Screen.Recording.2023-12-10.at.15.51.51.mov

On hiding the left split seems to resize to minPFraction. And when hiding by dragging to the left, that hidden state seems not to be in sync with whatever .hide() is using as clicking the hide button doesn't unhide the left split, but does what looks like another hide operation.

Is there something obvious I am missing? :)

Thanks!

PS
As an aside: it was a bit confusing to get the left split to hide! hide.toggle() always hides the right view, regardless of which one has priority (I expect in most scenario's the split having priority is the one to be hidden -- but I could be wrong). I did get it to work with the code above, but IMHO an API like .toggle(.left) would be cleaner.

To be clear: when I remove the minPFraction property, it works. So it looks like setting a minimum fraction is incompatible with hiding a split.

Yes, see #30 for some details. Thanks for this and the other report. I am hoping to work on the open issues this week.

This should be fixed with #33. Also, thanks to your suggestion, I added toggle(_ side: SplitSide? = nil) as a method on SideHolder. The default behavior of toggle() will remain the same, which is to operate on the .secondary side. I can see your point that this might couple logically to priority if you are specifying it, but I generally think of these things as orthogonal, and dreaded having to explain about how they were coupled only if you specified priority 🤪.

As a result, though, your example showing the problem now looks like this for me:

VStack {
    Split(primary: {
        Color.teal
    }, secondary: {
        Color.green
    })
    .constraints(minPFraction: minPFraction, priority: .left, dragToHideP: true)
    .fraction(fraction)
    .hide(hide)
    Button("Toggle Hide") {
        withAnimation {
            hide.toggle(.left)
        }
    }
}

and works properly. Note that per #30, the splitter is completely hidden (currently by design) when the minPFraction is specified. I'll be working on making that optional next.