Branchwell

OpenTalon / app · opentalon.ai / native / Sources / OpenTalon / TaskPageBoundary.swift

Raw 1014 B on d752fc53b5caa0d12214a7b5a145b0c32ef811f0
1import SwiftUI
2
3/// Only grows a list when its loaded end reaches the actual scroll viewport.
4/// An onAppear sentinel can run during offscreen layout and exhaust every page.
5struct TaskPageBoundary: View {
6 let space: String
7 let viewportHeight: CGFloat
8 let load: () -> Void
9
10 var body: some View {
11 Color.clear
12 .frame(height: 1)
13 .background {
14 GeometryReader { geometry in
15 Color.clear.preference(key: TaskPagePosition.self,
16 value: geometry.frame(in: .named(space)).minY)
17 }
18 }
19 .onPreferenceChange(TaskPagePosition.self) { position in
20 if position < viewportHeight + 60 { load() }
21 }
22 .accessibilityHidden(true)
23 }
24}
25
26private struct TaskPagePosition: PreferenceKey {
27 static let defaultValue: CGFloat = .infinity
28 static func reduce(value: inout CGFloat, nextValue: () -> CGFloat) { value = nextValue() }
29}