From 92584a1b3113912cf32653579e1728b3a09e7889 Mon Sep 17 00:00:00 2001 From: Apptek Studios Date: Thu, 2 Jan 2020 07:44:54 +1000 Subject: [PATCH] Add NavigationLink to PhotoGrid demo --- .../AdjustableGridScreen.swift | 10 +++--- .../Screens/AppStore/App.swift | 2 +- .../Screens/AppStore/AppStoreScreen.swift | 8 ++--- .../Screens/AppStore/AppViews.swift | 4 +-- .../Screens/InstaFeed/InstaFeedScreen.swift | 8 ++--- .../Screens/InstaFeed/StoryView.swift | 2 +- .../MagazineLayout/MagazineLayoutScreen.swift | 10 +++--- .../Screens/PhotoGrid/PhotoGridScreen.swift | 31 +++++++++++++------ .../Screens/Waterfall/WaterfallScreen.swift | 10 +++--- .../SharedModels/Post.swift | 5 --- 10 files changed, 49 insertions(+), 41 deletions(-) diff --git a/Demo/ASCollectionViewDemo/Screens/AdjustableLayout/AdjustableGridScreen.swift b/Demo/ASCollectionViewDemo/Screens/AdjustableLayout/AdjustableGridScreen.swift index 3eb8bf7..acea906 100644 --- a/Demo/ASCollectionViewDemo/Screens/AdjustableLayout/AdjustableGridScreen.swift +++ b/Demo/ASCollectionViewDemo/Screens/AdjustableLayout/AdjustableGridScreen.swift @@ -33,7 +33,7 @@ struct AdjustableGridScreen: View { GeometryReader { geom in - ASRemoteImageView(item.squareThumbURL) + ASRemoteImageView(item.url) .aspectRatio(1, contentMode: .fill) .frame(width: geom.size.width, height: geom.size.height) .clipped() @@ -101,18 +101,18 @@ struct AdjustableGridScreen: View switch event { case let .onAppear(item): - ASRemoteImageManager.shared.load(item.squareThumbURL) + ASRemoteImageManager.shared.load(item.url) case let .onDisappear(item): - ASRemoteImageManager.shared.cancelLoad(for: item.squareThumbURL) + ASRemoteImageManager.shared.cancelLoad(for: item.url) case let .prefetchForData(data): for item in data { - ASRemoteImageManager.shared.load(item.squareThumbURL) + ASRemoteImageManager.shared.load(item.url) } case let .cancelPrefetchForData(data): for item in data { - ASRemoteImageManager.shared.cancelLoad(for: item.squareThumbURL) + ASRemoteImageManager.shared.cancelLoad(for: item.url) } } } diff --git a/Demo/ASCollectionViewDemo/Screens/AppStore/App.swift b/Demo/ASCollectionViewDemo/Screens/AppStore/App.swift index 89344ff..51bfbc0 100644 --- a/Demo/ASCollectionViewDemo/Screens/AppStore/App.swift +++ b/Demo/ASCollectionViewDemo/Screens/AppStore/App.swift @@ -14,7 +14,7 @@ struct App: Identifiable URL(string: "https://picsum.photos/800/500?random=\(abs(randomNumberForImage))")! } - var squareThumbURL: URL + var url: URL { URL(string: "https://picsum.photos/500?random=\(abs(randomNumberForImage))")! } diff --git a/Demo/ASCollectionViewDemo/Screens/AppStore/AppStoreScreen.swift b/Demo/ASCollectionViewDemo/Screens/AppStore/AppStoreScreen.swift index b23507b..a150dd7 100644 --- a/Demo/ASCollectionViewDemo/Screens/AppStore/AppStoreScreen.swift +++ b/Demo/ASCollectionViewDemo/Screens/AppStore/AppStoreScreen.swift @@ -73,7 +73,7 @@ struct AppStoreScreen: View case 0: ASRemoteImageManager.shared.load(item.featureImageURL) default: - ASRemoteImageManager.shared.load(item.squareThumbURL) + ASRemoteImageManager.shared.load(item.url) } case let .onDisappear(item): switch sectionID @@ -81,7 +81,7 @@ struct AppStoreScreen: View case 0: ASRemoteImageManager.shared.cancelLoad(for: item.featureImageURL) default: - ASRemoteImageManager.shared.cancelLoad(for: item.squareThumbURL) + ASRemoteImageManager.shared.cancelLoad(for: item.url) } case let .prefetchForData(data): for item in data @@ -91,7 +91,7 @@ struct AppStoreScreen: View case 0: ASRemoteImageManager.shared.load(item.featureImageURL) default: - ASRemoteImageManager.shared.load(item.squareThumbURL) + ASRemoteImageManager.shared.load(item.url) } } case let .cancelPrefetchForData(data): @@ -102,7 +102,7 @@ struct AppStoreScreen: View case 0: ASRemoteImageManager.shared.cancelLoad(for: item.featureImageURL) default: - ASRemoteImageManager.shared.cancelLoad(for: item.squareThumbURL) + ASRemoteImageManager.shared.cancelLoad(for: item.url) } } } diff --git a/Demo/ASCollectionViewDemo/Screens/AppStore/AppViews.swift b/Demo/ASCollectionViewDemo/Screens/AppStore/AppViews.swift index dd042d7..844d327 100644 --- a/Demo/ASCollectionViewDemo/Screens/AppStore/AppViews.swift +++ b/Demo/ASCollectionViewDemo/Screens/AppStore/AppViews.swift @@ -46,7 +46,7 @@ struct AppViewLarge: View { HStack(alignment: .top) { - ASRemoteImageView(app.squareThumbURL) + ASRemoteImageView(app.url) .aspectRatio(1, contentMode: .fit) .cornerRadius(16) .clipped() @@ -72,7 +72,7 @@ struct AppViewCompact: View { HStack(alignment: .center) { - ASRemoteImageView(app.squareThumbURL) + ASRemoteImageView(app.url) .aspectRatio(1, contentMode: .fit) .cornerRadius(16) .clipped() diff --git a/Demo/ASCollectionViewDemo/Screens/InstaFeed/InstaFeedScreen.swift b/Demo/ASCollectionViewDemo/Screens/InstaFeed/InstaFeedScreen.swift index 1a01145..7c1360a 100644 --- a/Demo/ASCollectionViewDemo/Screens/InstaFeed/InstaFeedScreen.swift +++ b/Demo/ASCollectionViewDemo/Screens/InstaFeed/InstaFeedScreen.swift @@ -93,18 +93,18 @@ struct InstaFeedScreen: View switch event { case let .onAppear(item): - ASRemoteImageManager.shared.load(item.squareThumbURL) + ASRemoteImageManager.shared.load(item.url) case let .onDisappear(item): - ASRemoteImageManager.shared.cancelLoad(for: item.squareThumbURL) + ASRemoteImageManager.shared.cancelLoad(for: item.url) case let .prefetchForData(data): for item in data { - ASRemoteImageManager.shared.load(item.squareThumbURL) + ASRemoteImageManager.shared.load(item.url) } case let .cancelPrefetchForData(data): for item in data { - ASRemoteImageManager.shared.cancelLoad(for: item.squareThumbURL) + ASRemoteImageManager.shared.cancelLoad(for: item.url) } } } diff --git a/Demo/ASCollectionViewDemo/Screens/InstaFeed/StoryView.swift b/Demo/ASCollectionViewDemo/Screens/InstaFeed/StoryView.swift index 6dc8a1d..89b8baa 100644 --- a/Demo/ASCollectionViewDemo/Screens/InstaFeed/StoryView.swift +++ b/Demo/ASCollectionViewDemo/Screens/InstaFeed/StoryView.swift @@ -10,7 +10,7 @@ struct StoryView: View { VStack { - ASRemoteImageView(post.squareThumbURL) + ASRemoteImageView(post.url) .aspectRatio(contentMode: .fill) .clipShape(Circle()) .frame(width: 50, height: 50) diff --git a/Demo/ASCollectionViewDemo/Screens/MagazineLayout/MagazineLayoutScreen.swift b/Demo/ASCollectionViewDemo/Screens/MagazineLayout/MagazineLayoutScreen.swift index 157d442..d062721 100644 --- a/Demo/ASCollectionViewDemo/Screens/MagazineLayout/MagazineLayoutScreen.swift +++ b/Demo/ASCollectionViewDemo/Screens/MagazineLayout/MagazineLayoutScreen.swift @@ -18,7 +18,7 @@ struct MagazineLayoutScreen: View { (offset, sectionData) -> ASCollectionViewSection in ASCollectionViewSection(id: offset, data: sectionData, onCellEvent: onCellEvent) { item, _ in - ASRemoteImageView(item.squareThumbURL) + ASRemoteImageView(item.url) .aspectRatio(1, contentMode: .fit) .contextMenu { @@ -57,18 +57,18 @@ struct MagazineLayoutScreen: View switch event { case let .onAppear(item): - ASRemoteImageManager.shared.load(item.squareThumbURL) + ASRemoteImageManager.shared.load(item.url) case let .onDisappear(item): - ASRemoteImageManager.shared.cancelLoad(for: item.squareThumbURL) + ASRemoteImageManager.shared.cancelLoad(for: item.url) case let .prefetchForData(data): for item in data { - ASRemoteImageManager.shared.load(item.squareThumbURL) + ASRemoteImageManager.shared.load(item.url) } case let .cancelPrefetchForData(data): for item in data { - ASRemoteImageManager.shared.cancelLoad(for: item.squareThumbURL) + ASRemoteImageManager.shared.cancelLoad(for: item.url) } } } diff --git a/Demo/ASCollectionViewDemo/Screens/PhotoGrid/PhotoGridScreen.swift b/Demo/ASCollectionViewDemo/Screens/PhotoGrid/PhotoGridScreen.swift index 86c4c80..0d1177a 100644 --- a/Demo/ASCollectionViewDemo/Screens/PhotoGrid/PhotoGridScreen.swift +++ b/Demo/ASCollectionViewDemo/Screens/PhotoGrid/PhotoGridScreen.swift @@ -35,11 +35,14 @@ struct PhotoGridScreen: View { GeometryReader { geom in - ASRemoteImageView(item.squareThumbURL) - .aspectRatio(1, contentMode: .fill) - .frame(width: geom.size.width, height: geom.size.height) - .clipped() - .opacity(state.isSelected ? 0.7 : 1.0) + NavigationLink(destination: self.destinationForItem(item)) { + ASRemoteImageView(item.url) + .aspectRatio(1, contentMode: .fill) + .frame(width: geom.size.width, height: geom.size.height) + .clipped() + } + .buttonStyle(PlainButtonStyle()) + .disabled(self.isEditing) } if state.isSelected @@ -92,18 +95,28 @@ struct PhotoGridScreen: View switch event { case let .onAppear(item): - ASRemoteImageManager.shared.load(item.squareThumbURL) + ASRemoteImageManager.shared.load(item.url) case let .onDisappear(item): - ASRemoteImageManager.shared.cancelLoad(for: item.squareThumbURL) + ASRemoteImageManager.shared.cancelLoad(for: item.url) case let .prefetchForData(data): for item in data { - ASRemoteImageManager.shared.load(item.squareThumbURL) + ASRemoteImageManager.shared.load(item.url) } case let .cancelPrefetchForData(data): for item in data { - ASRemoteImageManager.shared.cancelLoad(for: item.squareThumbURL) + ASRemoteImageManager.shared.cancelLoad(for: item.url) + } + } + } + + func destinationForItem(_ item: Post) -> some View { + ScrollView { + PostView(post: item) + .onAppear { + ASRemoteImageManager.shared.load(item.url) + ASRemoteImageManager.shared.load(item.usernamePhotoURL) } } } diff --git a/Demo/ASCollectionViewDemo/Screens/Waterfall/WaterfallScreen.swift b/Demo/ASCollectionViewDemo/Screens/Waterfall/WaterfallScreen.swift index 4bfb980..8e93403 100644 --- a/Demo/ASCollectionViewDemo/Screens/Waterfall/WaterfallScreen.swift +++ b/Demo/ASCollectionViewDemo/Screens/Waterfall/WaterfallScreen.swift @@ -30,7 +30,7 @@ struct WaterfallScreen: View { geom in ZStack(alignment: .bottomTrailing) { - ASRemoteImageView(item.squareThumbURL) + ASRemoteImageView(item.url) .scaledToFill() .frame(width: geom.size.width, height: geom.size.height) .opacity(state.isSelected ? 0.7 : 1.0) @@ -114,18 +114,18 @@ struct WaterfallScreen: View switch event { case let .onAppear(item): - ASRemoteImageManager.shared.load(item.squareThumbURL) + ASRemoteImageManager.shared.load(item.url) case let .onDisappear(item): - ASRemoteImageManager.shared.cancelLoad(for: item.squareThumbURL) + ASRemoteImageManager.shared.cancelLoad(for: item.url) case let .prefetchForData(data): for item in data { - ASRemoteImageManager.shared.load(item.squareThumbURL) + ASRemoteImageManager.shared.load(item.url) } case let .cancelPrefetchForData(data): for item in data { - ASRemoteImageManager.shared.cancelLoad(for: item.squareThumbURL) + ASRemoteImageManager.shared.cancelLoad(for: item.url) } } } diff --git a/Demo/ASCollectionViewDemo/SharedModels/Post.swift b/Demo/ASCollectionViewDemo/SharedModels/Post.swift index 97a8a4b..cc77219 100644 --- a/Demo/ASCollectionViewDemo/SharedModels/Post.swift +++ b/Demo/ASCollectionViewDemo/SharedModels/Post.swift @@ -17,11 +17,6 @@ struct Post: Identifiable URL(string: "https://picsum.photos/\(Int(aspectRatio * 500))/500?random=\(abs(randomNumberForImage))")! } - var squareThumbURL: URL - { - URL(string: "https://picsum.photos/500?random=\(abs(randomNumberForImage))")! - } - var usernamePhotoURL: URL = URL(string: "https://picsum.photos/100?random=\(Int.random(in: 0...500))")! var comments: Int = .random(in: 4...600)