diff options
| author | Fuwn <[email protected]> | 2025-07-08 09:47:39 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2025-07-08 09:47:39 -0700 |
| commit | a43bdd31d3e053de100773dfaa34e7225dcf49a8 (patch) | |
| tree | b52a3a3636f76f2eb7c6e57c288f617d15e2b543 /Sora/Data/Scroll/ScrollPositionPreferenceKey.swift | |
| parent | feat: Development commit (diff) | |
| download | sora-testing-a43bdd31d3e053de100773dfaa34e7225dcf49a8.tar.xz sora-testing-a43bdd31d3e053de100773dfaa34e7225dcf49a8.zip | |
feat: Development commit
Diffstat (limited to 'Sora/Data/Scroll/ScrollPositionPreferenceKey.swift')
| -rw-r--r-- | Sora/Data/Scroll/ScrollPositionPreferenceKey.swift | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/Sora/Data/Scroll/ScrollPositionPreferenceKey.swift b/Sora/Data/Scroll/ScrollPositionPreferenceKey.swift new file mode 100644 index 0000000..6b78bdc --- /dev/null +++ b/Sora/Data/Scroll/ScrollPositionPreferenceKey.swift @@ -0,0 +1,19 @@ +import SwiftUI + +struct ScrollPositionPreferenceKey: PreferenceKey { + typealias Value = ScrollPositionPreference? + + static var defaultValue: Value = nil + + static func reduce(value: inout Value, nextValue: () -> Value) { + guard let next = nextValue() else { return } + + if let current = value { + if abs(next.yPosition) < abs(current.yPosition) { + value = next + } + } else { + value = next + } + } +} |