OpenTalon / app / native / Sources / OpenTalon / TaskPageBoundary.swift
| 1 | import 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. |
| 5 | struct 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 | |
| 26 | private struct TaskPagePosition: PreferenceKey { |
| 27 | static let defaultValue: CGFloat = .infinity |
| 28 | static func reduce(value: inout CGFloat, nextValue: () -> CGFloat) { value = nextValue() } |
| 29 | } |