Make array index available inside this ForEach
- ID
8cd41ac- date
2023-06-08 09:51:04+00:00- author
Alex Chan <alex@alexwlchan.net>- parent
8d90f16- message
Make array index available inside this ForEach- changed files
1 file, 10 additions, 2 deletions
Changed files
BlinkReviewer/BlinkReviewer/Views/PhotoReviewer.swift (2024) → BlinkReviewer/BlinkReviewer/Views/PhotoReviewer.swift (2521)
diff --git a/BlinkReviewer/BlinkReviewer/Views/PhotoReviewer.swift b/BlinkReviewer/BlinkReviewer/Views/PhotoReviewer.swift
index 6b97356..99e3300 100644
--- a/BlinkReviewer/BlinkReviewer/Views/PhotoReviewer.swift
+++ b/BlinkReviewer/BlinkReviewer/Views/PhotoReviewer.swift
@@ -20,8 +20,16 @@ struct PhotoReviewer: View {
LazyHStack(spacing: 5) {
// TODO: placeholder images for start/end
// TODO: Allow tapping thumbnails to jump to that
- ForEach(assets, id: \.localIdentifier) { asset in
- ThumbnailImage(thumbnail: asset.getThumbnail(), isSelected: assets[selectedAssetIndex].localIdentifier == asset.localIdentifier)
+
+ // Implementation note: we use the localIdentifier rather than the
+ // array index as the id here, because the app gets way slower if
+ // you use the array index -- it tries to regenerate a bunch of
+ // the thumbnails every time you change position.
+ ForEach(Array(assets.enumerated()), id: \.element.localIdentifier) { index, asset in
+ ThumbnailImage(
+ thumbnail: asset.getThumbnail(),
+ isSelected: assets[selectedAssetIndex].localIdentifier == asset.localIdentifier
+ )
}
}.padding()
}.frame(height: 70)