diff options
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 + } + } +} |