Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug when hiding splitview while using minimum fractions #31

Closed
bastiaanterhorst opened this issue Dec 10, 2023 · 3 comments · Fixed by #33
Closed

Bug when hiding splitview while using minimum fractions #31

bastiaanterhorst opened this issue Dec 10, 2023 · 3 comments · Fixed by #33

Comments

@bastiaanterhorst
Copy link
Contributor

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.

@bastiaanterhorst
Copy link
Contributor Author

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.

@stevengharris
Copy link
Owner

stevengharris commented Dec 10, 2023

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

@stevengharris
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants