2// NewThumbnailList.swift
5// Created by Alex Chan on 10/06/2023.
10struct ThumbnailList: View {
11 @EnvironmentObject var photosLibrary: PhotosLibrary
12 @Binding var focusedAssetIndex: Int
15 ScrollViewReader { proxy in
16 PHAssetHStack(assetIdentifiers: photosLibrary.assetIdentifiers) { localIdentifier, index in
19 state: photosLibrary.state(ofLocalIdentifier: localIdentifier),
20 isFavorite: photosLibrary.isFavorite(localIdentifier: localIdentifier),
21 isFocused: index == focusedAssetIndex,
23 photosLibrary.getThumbnail(for: photosLibrary.asset(at: index))
26 .environmentObject(photosLibrary)
28 focusedAssetIndex = index
31 // When the focusedAssetIndex changes, scroll to the new position.
33 // By default this is an animated scroll, but if the user is scrolling
34 // a long way, we skip the animation and jump straight to it -- if somebody
35 // jumps over several thousand images in one go, it looks better to snap
36 // rather than do a jaggy animation.
37 .onChange(of: focusedAssetIndex, perform: { [oldIndex = focusedAssetIndex] newIndex in
38 withAnimation(abs(newIndex - oldIndex) < 100 ? .default : nil) {
40 photosLibrary.asset(at: newIndex).localIdentifier,