keep the thumbnail list scrolled to the right position
- ID
954fda1- date
2023-06-10 08:23:21+00:00- author
Alex Chan <alex@alexwlchan.net>- parent
9a54a45- message
keep the thumbnail list scrolled to the right position- changed files
1 file, 17 additions, 7 deletions
Changed files
BlinkReviewer/BlinkReviewer/Views/Thumbnails/NewThumbnailList.swift (607) → BlinkReviewer/BlinkReviewer/Views/Thumbnails/NewThumbnailList.swift (1000)
diff --git a/BlinkReviewer/BlinkReviewer/Views/Thumbnails/NewThumbnailList.swift b/BlinkReviewer/BlinkReviewer/Views/Thumbnails/NewThumbnailList.swift
index bd777d0..d22a2e4 100644
--- a/BlinkReviewer/BlinkReviewer/Views/Thumbnails/NewThumbnailList.swift
+++ b/BlinkReviewer/BlinkReviewer/Views/Thumbnails/NewThumbnailList.swift
@@ -12,13 +12,23 @@ struct NewThumbnailList: View {
@Binding var focusedAssetIndex: Int
var body: some View {
- PHAssetHStack(photosLibrary.assets2) { asset, index in
- NewThumbnailImage(
- photosLibrary.getThumbnail(for: asset),
- state: photosLibrary.state(of: asset),
- isFavorite: asset.isFavorite,
- isFocused: index == focusedAssetIndex
- )
+ ScrollViewReader { proxy in
+ PHAssetHStack(photosLibrary.assets2) { asset, index in
+ NewThumbnailImage(
+ photosLibrary.getThumbnail(for: asset),
+ state: photosLibrary.state(of: asset),
+ isFavorite: asset.isFavorite,
+ isFocused: index == focusedAssetIndex
+ )
+ }
+ .onChange(of: focusedAssetIndex, perform: { newIndex in
+ withAnimation {
+ proxy.scrollTo(
+ photosLibrary.assets2.object(at: newIndex).localIdentifier,
+ anchor: .center
+ )
+ }
+ })
}
}
}