Created
April 10, 2025 00:31
-
-
Save gabrielribeiro/fa332aae06f0e09853c4b07f5fd36ff1 to your computer and use it in GitHub Desktop.
Revisions
-
gabrielribeiro created this gist
Apr 10, 2025 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,47 @@ 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 } }