fix: widget iOS 17 deployment target + register FloatingTabState
- Widget extension: 16.0 → 17.0 (containerBackground/widget API require 17) - xcodegen re-run picks up FloatingTabState.swift (was on disk but not registered in project.pbxproj after previous xcodegen run)
This commit is contained in:
52
KisaniCal/Components/FloatingTabState.swift
Normal file
52
KisaniCal/Components/FloatingTabState.swift
Normal file
@@ -0,0 +1,52 @@
|
||||
import SwiftUI
|
||||
|
||||
@MainActor
|
||||
final class FloatingTabState: ObservableObject {
|
||||
@Published private(set) var isCollapsed = false
|
||||
private var lastY: CGFloat = 0
|
||||
|
||||
func report(scrollY: CGFloat) {
|
||||
let delta = scrollY - lastY
|
||||
guard abs(delta) > 1.5 else { return }
|
||||
let shouldCollapse = delta < 0 // content Y decreases → user scrolling down
|
||||
lastY = scrollY
|
||||
guard shouldCollapse != isCollapsed else { return }
|
||||
withAnimation(KisaniSpring.snappy) {
|
||||
isCollapsed = shouldCollapse
|
||||
}
|
||||
}
|
||||
|
||||
func resetOffset() {
|
||||
lastY = 0
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: — Scroll tracker
|
||||
|
||||
private struct ScrollYKey: PreferenceKey {
|
||||
static let defaultValue: CGFloat = 0
|
||||
static func reduce(value: inout CGFloat, nextValue: () -> CGFloat) { value = nextValue() }
|
||||
}
|
||||
|
||||
private struct TabBarScrollModifier: ViewModifier {
|
||||
@EnvironmentObject private var tabState: FloatingTabState
|
||||
|
||||
func body(content: Content) -> some View {
|
||||
content
|
||||
.background(
|
||||
GeometryReader { geo in
|
||||
Color.clear
|
||||
.preference(key: ScrollYKey.self, value: geo.frame(in: .global).minY)
|
||||
}
|
||||
)
|
||||
.onPreferenceChange(ScrollYKey.self) { y in
|
||||
tabState.report(scrollY: y)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension View {
|
||||
func trackScrollForTabBar() -> some View {
|
||||
modifier(TabBarScrollModifier())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user