jel/Jel/Views/Utility/StickyHeaderView.swift

39 lines
817 B
Swift
Raw Normal View History

2023-12-25 01:01:52 +00:00
//
// StickyHeaderView.swift
// Jel
//
// Created by zerocool on 12/24/23.
//
import SwiftUI
struct StickyHeaderView<Content: View>: View {
var minHeight: CGFloat
var content: Content
init(minHeight: CGFloat = 200, @ViewBuilder content: () -> Content) {
self.minHeight = minHeight
self.content = content()
}
var body: some View {
GeometryReader { geo in
if(geo.frame(in: .global).minY <= 0) {
content
.frame(width: geo.size.width, height: geo.size.height, alignment: .center)
} else {
content
.offset(y: -geo.frame(in: .global).minY)
.frame(width: geo.size.width, height: geo.size.height + geo.frame(in: .global).minY)
}
}.frame(minHeight: minHeight)
}
}
#Preview {
StickyHeaderView {
Text("Test")
}
}