Skip to content

Instantly share code, notes, and snippets.

@gabrielribeiro
Created April 10, 2025 00:31
Show Gist options
  • Save gabrielribeiro/fa332aae06f0e09853c4b07f5fd36ff1 to your computer and use it in GitHub Desktop.
Save gabrielribeiro/fa332aae06f0e09853c4b07f5fd36ff1 to your computer and use it in GitHub Desktop.
Issue with ScrollKit v0.7.0
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