Skip to content

Instantly share code, notes, and snippets.

@rijieli
Created March 16, 2025 09:09
Show Gist options
  • Save rijieli/0f312e16f834f088982a32cb71755284 to your computer and use it in GitHub Desktop.
Save rijieli/0f312e16f834f088982a32cb71755284 to your computer and use it in GitHub Desktop.
Fake large title navigation bar
import SwiftUI
@available(iOS 18.0, *)
struct FakeNavigationBarView: View {
@State var point: CGPoint = .zero
let titleFullHeight: CGFloat = 100
let titleMinHeight: CGFloat = 44
var progress: CGFloat {
if point.y < 0 {
return 0
} else {
return min(1, point.y / (titleFullHeight - titleMinHeight))
}
}
var titleHeight: CGFloat {
titleMinHeight + (titleFullHeight - titleMinHeight) * (1 - progress)
}
let colors: [Color] = [.red, .green, .blue, .orange, .yellow, .purple]
var body: some View {
NavigationStack {
VStack(spacing: 0) {
ZStack {
if progress > 0.8 {
Text("Collection")
.font(.system(size: 17, weight: .bold))
} else {
Text("Collection")
.font(.system(size: 34, weight: .bold))
.frame(maxWidth: .infinity, alignment: .leading)
}
}
.padding(.horizontal, 16)
.frame(maxWidth: .infinity)
.frame(height: titleHeight)
.background(.regularMaterial)
.zIndex(1)
ScrollView {
LazyVStack {
ForEach(0..<100) { i in
Rectangle()
.fill(colors[i % colors.count])
.frame(height: 56)
}
}
}
.scrollClipDisabled()
.onScrollGeometryChange(for: CGPoint.self) { proxy in
proxy.contentOffset
} action: { _, newValue in
point = newValue
}
}
}
}
}
@available(iOS 18.0, *)
#Preview {
FakeNavigationBarView()
}
@rijieli
Copy link
Author

rijieli commented Mar 16, 2025

2025-03-16.17.10.17.mov

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment