Skip to content

Custom Splitter contents lag behind animation #40

Description

@eduo

Hi.

I have a custom splitter where in the middle there's a drag icon (three lines) and on the right a button to collapse down or return back.

I must be doing something wrong, since while everything works, the splitter itself lags. behind the icon for the button that triggers the resize animation.

Can be tested by pasting this in a new swift view file (preview with iPhone). The preview has vertical coloured spacers for top and bottom):

`
import Foundation
import SwiftUI
import SplitView

struct listListsSplitter: SplitDivider {
@ObservedObject var layout: LayoutHolder
@ObservedObject var hide: SideHolder
@ObservedObject var styling: SplitStyling
@State private var hideButton: Bool = false

var body: some View {
        ZStack{
        Image(systemName: "line.3.horizontal")
            .foregroundColor(.white)
            if !hideButton {
                Button(
                    action: { withAnimation { hide.toggle() } },
                    label: {
                        hide.side == nil ?
                        Image(systemName: "platter.filled.bottom.and.arrow.down.iphone")
                        :
                        Image(systemName: "platter.filled.top.and.arrow.up.iphone")

                    }
                )
                .buttonStyle(.borderless)
                .accentColor(.white)
                .font(.title)
                .frame(maxWidth: .infinity, alignment: .trailing)
            }
    }
    .frame(maxWidth: .infinity)
    .background(.gray)
    }

}

#Preview {
let layout = LayoutHolder()
let hide = SideHolder()

    var thisSplit =
        VSplit(
            top: {
                VStack {
                    Spacer().background {Color.teal.frame(minWidth: 10, minHeight: 10)}
                }
            },
            bottom: {
            VStack {
                Spacer().background {Color.yellow.frame(minWidth: 10, minHeight: 10)}
            }
        }
        )
        .hide(hide)
        .constraints(minPFraction: 0.15, minSFraction: 0.1)
        .splitter { listListsSplitter(layout: layout, hide: hide, styling: SplitStyling(visibleThickness: 20)) }
return thisSplit

}
`

This screenshot shows the splitter catching up with the label:

image

And this one shows the final state:

image

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions