danielsaidi / ScrollKit

ScrollKit is a SwiftUI SDK that adds powerful scroll features, like offset tracking and a header view that stretches & transforms as you pull down, and sticks to the top when you scroll.
MIT License
722 stars 26 forks source link

Question: TabView inside the ScrollViewWithStickyHeader #9

Closed gabrielribeiro closed 10 months ago

gabrielribeiro commented 10 months ago

Congrats on the work! Such a stunning library! It definitely improved my app UI!

Just a question: is it possible to have a TabView (page control) inside the ScrollViewWithStickyHeader header and have all the gestures working?

I want to develop something like that:

Screenshot 2023-12-03 at 23 09 14
danielsaidi commented 10 months ago

Hey @gabrielribeiro

Thank you, happy to hear that it helped!

Sure, it should work right away. I basically just replaced the preview header in the SpotifyPreviewScreen with this:

func scrollViewHeader() -> some View {
    TabView {
        Color.red
        Color.green
        Color.blue
    }
    .tabViewStyle(.page)
}

and the result becomes:

Skärmavbild 2023-12-04 kl  17 29 54 Skärmavbild 2023-12-04 kl  17 29 57

So it seems to work pretty well :) But you need to adjust the docked state so that it's based on the currently active page, otherwise you'll get this when scrolling while the second (green) page is active:

Skärmavbild 2023-12-04 kl  17 35 42
gabrielribeiro commented 10 months ago

Wow that's awesome! Thank you so much for the help!

danielsaidi commented 10 months ago

Also, if you don't need the pinned behavior, you can just use the ScrollViewHeader inside a regular ScrollView :)

ScrollView {
    VStack {
        ScrollViewHeader {
            TabView {
                Color.red
                Color.green
                Color.blue
            }
            .tabViewStyle(.page)
        }
         .frame(height: 250)

        LazyVStack {
            ForEach(0...100, id: \.self) {
                Text("\($0)")
            }
        }
    }
}

The result becomes:

screen1 screen2 screen3