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

Custom Splitter contents lag behind animation #40

Open
eduo opened this issue Jul 23, 2024 · 4 comments
Open

Custom Splitter contents lag behind animation #40

eduo opened this issue Jul 23, 2024 · 4 comments

Comments

@eduo
Copy link

eduo commented Jul 23, 2024

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
@stevengharris
Copy link
Owner

Just to double-check, it's the noticeable lag between the button and the splitter it's contained-by that shows up on toggling hide/show? I think I need to do a matchedGeometryEffect, but let me take a look.

@eduo
Copy link
Author

eduo commented Jul 24, 2024

Just to double-check, it's the noticeable lag between the button and the splitter it's contained-by that shows up on toggling hide/show? I think I need to do a matchedGeometryEffect, but let me take a look.

Yes. The button contained is switched (to reflect the direction of the click in the next position) but it's drawn directly at the destination. Doesn't seem to "travel" with the animation and the splitter. The splitter then catches up to it.

@stevengharris
Copy link
Owner

stevengharris commented Jul 24, 2024

If you're on iOS 17, adding in geometryGroup() to the ZStack fixes the issue, I believe. To be clear, in your example:

    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)
        .geometryGroup()
    }

Not sure what the easy pre-iOS17 fix would be, frankly.

@eduo
Copy link
Author

eduo commented Aug 5, 2024

Thanks! This worked well. iOS17 as a requirement is OK.

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

No branches or pull requests

2 participants