Skip to content

Commit

Permalink
Add NavigationLink to PhotoGrid demo
Browse files Browse the repository at this point in the history
  • Loading branch information
Apptek Studios committed Jan 1, 2020
1 parent 7165b21 commit 92584a1
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Demo/ASCollectionViewDemo/Screens/AppStore/App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))")!
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ 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
{
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
Expand All @@ -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):
Expand All @@ -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)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Demo/ASCollectionViewDemo/Screens/AppStore/AppViews.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct AppViewLarge: View
{
HStack(alignment: .top)
{
ASRemoteImageView(app.squareThumbURL)
ASRemoteImageView(app.url)
.aspectRatio(1, contentMode: .fit)
.cornerRadius(16)
.clipped()
Expand All @@ -72,7 +72,7 @@ struct AppViewCompact: View
{
HStack(alignment: .center)
{
ASRemoteImageView(app.squareThumbURL)
ASRemoteImageView(app.url)
.aspectRatio(1, contentMode: .fit)
.cornerRadius(16)
.clipped()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ struct StoryView: View
{
VStack
{
ASRemoteImageView(post.squareThumbURL)
ASRemoteImageView(post.url)
.aspectRatio(contentMode: .fill)
.clipShape(Circle())
.frame(width: 50, height: 50)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct MagazineLayoutScreen: View
{ (offset, sectionData) -> ASCollectionViewSection<Int> in
ASCollectionViewSection(id: offset, data: sectionData, onCellEvent: onCellEvent)
{ item, _ in
ASRemoteImageView(item.squareThumbURL)
ASRemoteImageView(item.url)
.aspectRatio(1, contentMode: .fit)
.contextMenu
{
Expand Down Expand Up @@ -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)
}
}
}
Expand Down
31 changes: 22 additions & 9 deletions Demo/ASCollectionViewDemo/Screens/PhotoGrid/PhotoGridScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
}
}
Expand Down
5 changes: 0 additions & 5 deletions Demo/ASCollectionViewDemo/SharedModels/Post.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 92584a1

Please sign in to comment.