Skip to main content

Snap to scroll when we’re moving >100 images at a time

ID
0528e53
date
2023-06-15 13:36:09+00:00
author
Alex Chan <alex@alexwlchan.net>
parent
fd49963
message
Snap to scroll when we're moving >100 images at a time
changed files
1 file, 8 additions, 2 deletions

Changed files

BlinkReviewer/Blink/Views/Thumbnails/ThumbnailList.swift (1357) → BlinkReviewer/Blink/Views/Thumbnails/ThumbnailList.swift (1836)

diff --git a/BlinkReviewer/Blink/Views/Thumbnails/ThumbnailList.swift b/BlinkReviewer/Blink/Views/Thumbnails/ThumbnailList.swift
index 0dce571..f1562ce 100644
--- a/BlinkReviewer/Blink/Views/Thumbnails/ThumbnailList.swift
+++ b/BlinkReviewer/Blink/Views/Thumbnails/ThumbnailList.swift
@@ -28,8 +28,14 @@ struct ThumbnailList: View {
                     focusedAssetIndex = index
                 }
             }
-            .onChange(of: focusedAssetIndex, perform: { newIndex in
-                withAnimation {
+            // When the focusedAssetIndex changes, scroll to the new position.
+            //
+            // By default this is an animated scroll, but if the user is scrolling
+            // a long way, we skip the animation and jump straight to it -- if somebody
+            // jumps over several thousand images in one go, it looks better to snap
+            // rather than do a jaggy animation.
+            .onChange(of: focusedAssetIndex, perform: { [oldIndex = focusedAssetIndex] newIndex in
+                withAnimation(abs(newIndex - oldIndex) < 100 ? .default : nil) {
                     proxy.scrollTo(
                         photosLibrary.asset(at: newIndex).localIdentifier,
                         anchor: .center