Created
April 10, 2025 00:31
-
-
Save gabrielribeiro/fa332aae06f0e09853c4b07f5fd36ff1 to your computer and use it in GitHub Desktop.
Issue with ScrollKit v0.7.0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
import ScrollKit | |
struct ContentView: View { | |
@State private var headerVisibleRatio = 1.0 | |
var body: some View { | |
NavigationView { | |
ScrollViewWithStickyHeader( | |
header: header, | |
headerHeight: 300, | |
onScroll: handleScrollOffset | |
) { | |
LazyVStack(spacing: 0) { | |
ForEach(1...100, id: \.self) { item in | |
VStack(spacing: 0) { | |
Text("Item \(item)") | |
.padding() | |
.frame(maxWidth: .infinity, alignment: .leading) | |
Divider() | |
} | |
} | |
} | |
} | |
} | |
} | |
private func header() -> some View { | |
ZStack { | |
Color.blue | |
.opacity(headerVisibleRatio) | |
Color.red | |
.opacity(1 - headerVisibleRatio) | |
VStack { | |
Text("Blue is header, red is preview (shouldn't be visible when scrolled)") | |
} | |
.opacity(headerVisibleRatio) | |
} | |
} | |
private func handleScrollOffset(_ offset: CGPoint, headerVisibleRatio: CGFloat) { | |
self.headerVisibleRatio = headerVisibleRatio | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment