Skip to main content

Add more comments on PHAssetHStack

ID
1b5ed36
date
2023-06-16 06:54:10+00:00
author
Alex Chan <alex@alexwlchan.net>
parent
fc9e76c
message
Add more comments on PHAssetHStack
changed files
2 files, 13 additions, 30 deletions

Changed files

BlinkReviewer/Blink.xcodeproj/project.pbxproj (34735) → BlinkReviewer/Blink.xcodeproj/project.pbxproj (34735)

diff --git a/BlinkReviewer/Blink.xcodeproj/project.pbxproj b/BlinkReviewer/Blink.xcodeproj/project.pbxproj
index 3c053f4..d08f2a9 100644
--- a/BlinkReviewer/Blink.xcodeproj/project.pbxproj
+++ b/BlinkReviewer/Blink.xcodeproj/project.pbxproj
@@ -600,7 +600,7 @@
 				CODE_SIGN_ENTITLEMENTS = Blink/Blink.entitlements;
 				CODE_SIGN_STYLE = Automatic;
 				COMBINE_HIDPI_IMAGES = YES;
-				CURRENT_PROJECT_VERSION = 51;
+				CURRENT_PROJECT_VERSION = 67;
 				DEVELOPMENT_ASSET_PATHS = "\"Blink/Preview Content\"";
 				ENABLE_PREVIEWS = YES;
 				GENERATE_INFOPLIST_FILE = YES;
@@ -627,7 +627,7 @@
 				CODE_SIGN_ENTITLEMENTS = Blink/Blink.entitlements;
 				CODE_SIGN_STYLE = Automatic;
 				COMBINE_HIDPI_IMAGES = YES;
-				CURRENT_PROJECT_VERSION = 51;
+				CURRENT_PROJECT_VERSION = 67;
 				DEVELOPMENT_ASSET_PATHS = "\"Blink/Preview Content\"";
 				ENABLE_PREVIEWS = YES;
 				GENERATE_INFOPLIST_FILE = YES;
@@ -652,7 +652,7 @@
 				ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
 				BUNDLE_LOADER = "$(TEST_HOST)";
 				CODE_SIGN_STYLE = Automatic;
-				CURRENT_PROJECT_VERSION = 51;
+				CURRENT_PROJECT_VERSION = 67;
 				GENERATE_INFOPLIST_FILE = YES;
 				MACOSX_DEPLOYMENT_TARGET = 13.3;
 				MARKETING_VERSION = 1.0;
@@ -670,7 +670,7 @@
 				ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
 				BUNDLE_LOADER = "$(TEST_HOST)";
 				CODE_SIGN_STYLE = Automatic;
-				CURRENT_PROJECT_VERSION = 51;
+				CURRENT_PROJECT_VERSION = 67;
 				GENERATE_INFOPLIST_FILE = YES;
 				MACOSX_DEPLOYMENT_TARGET = 13.3;
 				MARKETING_VERSION = 1.0;
@@ -687,7 +687,7 @@
 			buildSettings = {
 				ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
 				CODE_SIGN_STYLE = Automatic;
-				CURRENT_PROJECT_VERSION = 51;
+				CURRENT_PROJECT_VERSION = 67;
 				GENERATE_INFOPLIST_FILE = YES;
 				MARKETING_VERSION = 1.0;
 				PRODUCT_BUNDLE_IDENTIFIER = net.alexwlchan.BlinkReviewerUITests;
@@ -703,7 +703,7 @@
 			buildSettings = {
 				ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
 				CODE_SIGN_STYLE = Automatic;
-				CURRENT_PROJECT_VERSION = 51;
+				CURRENT_PROJECT_VERSION = 67;
 				GENERATE_INFOPLIST_FILE = YES;
 				MARKETING_VERSION = 1.0;
 				PRODUCT_BUNDLE_IDENTIFIER = net.alexwlchan.BlinkReviewerUITests;

BlinkReviewer/Blink/Views/Helpers/PHAssetHStack.swift (4824) → BlinkReviewer/Blink/Views/Helpers/PHAssetHStack.swift (4355)

diff --git a/BlinkReviewer/Blink/Views/Helpers/PHAssetHStack.swift b/BlinkReviewer/Blink/Views/Helpers/PHAssetHStack.swift
index 031a147..ccd601a 100644
--- a/BlinkReviewer/Blink/Views/Helpers/PHAssetHStack.swift
+++ b/BlinkReviewer/Blink/Views/Helpers/PHAssetHStack.swift
@@ -15,7 +15,6 @@ struct AssetIdentifiersCollection: RandomAccessCollection, Equatable {
     }
 }
 
-
 /// Creates an HStack of PHAssets that fills in right-to-left.
 ///
 /// This provides lazy loading to the left-hand side, and assumes you're
@@ -32,9 +31,13 @@ struct AssetIdentifiersCollection: RandomAccessCollection, Equatable {
 /// LazyHStack to the far right, it loads every element immediately.
 ///
 /// This takes a subview which is used to render the individual entries;
-/// these subviews receive the original PHAsset and the index from the
-/// original PHFetchResult -- you can use this index to retrieve adjacent
-/// items in the FetchResult, if necessary.
+/// these subviews receive the position and identifier of the original asset.
+///
+/// Note: this operates on a list of asset identifiers, but not the assets
+/// themselves -- this is a performance optimisation.  If the user scrolls
+/// deep into the list, SwiftUI will try to render lots of entries, and if
+/// those are PHAsset elements, it'll go back to the Photos database, even
+/// though we don't really need any Photos data in our views.
 ///
 struct PHAssetHStack<Content: View>: View {
     var subview: (String, Int) -> Content
@@ -95,23 +98,3 @@ struct PHAssetHStack<Content: View>: View {
             .environment(\.layoutDirection, .rightToLeft)
     }
 }
-//
-//struct PHAssetHStack_Previews: PreviewProvider {
-//    static var fetchResult: PHFetchResult<PHAsset> {
-//        let options = PHFetchOptions()
-//        options.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: false)]
-//        options.fetchLimit = 25
-//
-//        return PHAsset.fetchAssets(with: options)
-//    }
-//
-//    static var previews: some View {
-//        PHAssetHStack(fetchResult) { asset, index in
-//            VStack {
-//                Text("view index = \(index)")
-//                Text("asset ID =\n\(asset.localIdentifier)")
-//                Text("fetchResult.object(at: \(index)) =\n\(fetchResult.object(at: index).localIdentifier)")
-//            }
-//        }
-//    }
-//}