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:
kutesir
2026-05-28 20:35:44 +03:00
parent 5e232f2d81
commit dc99a3f1f0
9 changed files with 74 additions and 8 deletions

View 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())
}
}