From 52ffe19324e815cd18773c1ff6a202411ab489d7 Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Tue, 27 Jul 2021 23:26:52 +0200 Subject: [PATCH] Replace URLImage with AsyncImage --- Apple TV/VideoCellView.swift | 10 ++-- Apple TV/VideoDetailsView.swift | 8 +-- Apple TV/VideoListRowView.swift | 36 ++++++++---- Pearvidious.xcodeproj/project.pbxproj | 57 ------------------- .../xcshareddata/swiftpm/Package.resolved | 13 +---- Shared/PearvidiousApp.swift | 5 -- Shared/VideoView.swift | 20 +++++++ 7 files changed, 54 insertions(+), 95 deletions(-) create mode 100644 Shared/VideoView.swift diff --git a/Apple TV/VideoCellView.swift b/Apple TV/VideoCellView.swift index 0527ac40..587c3a0f 100644 --- a/Apple TV/VideoCellView.swift +++ b/Apple TV/VideoCellView.swift @@ -1,6 +1,3 @@ -import URLImage -import URLImageStore - import SwiftUI struct VideoCellView: View { @@ -12,13 +9,14 @@ struct VideoCellView: View { Button(action: { navigationState.playVideo(video) }) { VStack(alignment: .leading) { ZStack { - if let thumbnail = video.thumbnailURL(quality: .high) { - // to replace with AsyncImage when it is fixed with lazy views - URLImage(thumbnail) { image in + if let url = video.thumbnailURL(quality: .high) { + AsyncImage(url: url) { image in image .resizable() .aspectRatio(contentMode: .fill) .frame(width: 550, height: 310) + } placeholder: { + ProgressView() } .mask(RoundedRectangle(cornerRadius: 12)) } else { diff --git a/Apple TV/VideoDetailsView.swift b/Apple TV/VideoDetailsView.swift index 027bd1ad..58c393a1 100644 --- a/Apple TV/VideoDetailsView.swift +++ b/Apple TV/VideoDetailsView.swift @@ -1,7 +1,6 @@ import Defaults import Siesta import SwiftUI -import URLImage struct VideoDetailsView: View { @Environment(\.dismiss) private var dismiss @@ -36,13 +35,14 @@ struct VideoDetailsView: View { VStack(alignment: .center) { ZStack(alignment: .bottom) { Group { - if let thumbnail = video.thumbnailURL(quality: .maxres) { - // to replace with AsyncImage when it is fixed with lazy views - URLImage(thumbnail) { image in + if let url = video.thumbnailURL(quality: .maxres) { + AsyncImage(url: url) { image in image .resizable() .aspectRatio(contentMode: .fill) .frame(width: 1600, height: 800) + } placeholder: { + ProgressView() } } } diff --git a/Apple TV/VideoListRowView.swift b/Apple TV/VideoListRowView.swift index 130d8470..0c86d0c5 100644 --- a/Apple TV/VideoListRowView.swift +++ b/Apple TV/VideoListRowView.swift @@ -1,6 +1,4 @@ import SwiftUI -import URLImage -import URLImageStore struct VideoListRowView: View { @EnvironmentObject private var navigationState @@ -166,20 +164,13 @@ struct VideoListRowView: View { ) -> some View { Group { if let url = video.thumbnailURL(quality: quality) { - URLImage(url) { - EmptyView() - } inProgress: { _ in - ProgressView() - .progressViewStyle(CircularProgressViewStyle()) - } failure: { _, retry in - VStack { - Button("Retry", action: retry) - } - } content: { image in + AsyncImage(url: url) { image in image .resizable() .aspectRatio(contentMode: .fill) .frame(minWidth: minWidth, maxWidth: maxWidth, minHeight: minHeight, maxHeight: maxHeight) + } placeholder: { + ProgressView() } .mask(RoundedRectangle(cornerRadius: 12)) } else { @@ -201,3 +192,24 @@ struct VideoListRowView: View { #endif } } + +struct VideoListRowPreview: PreviewProvider { + static var previews: some View { + List { + VideoListRowView(video: Video.fixture) + VideoListRowView(video: Video.fixtureUpcomingWithoutPublishedOrViews) + VideoListRowView(video: Video.fixtureLiveWithoutPublishedOrViews) + } + .frame(maxWidth: 400) + + #if os(iOS) + List { + VideoListRowView(video: Video.fixture) + VideoListRowView(video: Video.fixtureUpcomingWithoutPublishedOrViews) + VideoListRowView(video: Video.fixtureLiveWithoutPublishedOrViews) + } + .environment(\.verticalSizeClass, .compact) + .frame(maxWidth: 800) + #endif + } +} diff --git a/Pearvidious.xcodeproj/project.pbxproj b/Pearvidious.xcodeproj/project.pbxproj index 2bb0ca70..365ad961 100644 --- a/Pearvidious.xcodeproj/project.pbxproj +++ b/Pearvidious.xcodeproj/project.pbxproj @@ -71,8 +71,6 @@ 377A20AA2693C9A2002842B8 /* TypedContentAccessors.swift in Sources */ = {isa = PBXBuildFile; fileRef = 377A20A82693C9A2002842B8 /* TypedContentAccessors.swift */; }; 377A20AB2693C9A2002842B8 /* TypedContentAccessors.swift in Sources */ = {isa = PBXBuildFile; fileRef = 377A20A82693C9A2002842B8 /* TypedContentAccessors.swift */; }; 377FC7D5267A080300A6BBAF /* SwiftyJSON in Frameworks */ = {isa = PBXBuildFile; productRef = 377FC7D4267A080300A6BBAF /* SwiftyJSON */; }; - 377FC7D7267A080300A6BBAF /* URLImage in Frameworks */ = {isa = PBXBuildFile; productRef = 377FC7D6267A080300A6BBAF /* URLImage */; }; - 377FC7D9267A080300A6BBAF /* URLImageStore in Frameworks */ = {isa = PBXBuildFile; productRef = 377FC7D8267A080300A6BBAF /* URLImageStore */; }; 377FC7DB267A080300A6BBAF /* Logging in Frameworks */ = {isa = PBXBuildFile; productRef = 377FC7DA267A080300A6BBAF /* Logging */; }; 377FC7DC267A081800A6BBAF /* PopularVideosView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37AAF27D26737323007FC770 /* PopularVideosView.swift */; }; 377FC7DD267A081A00A6BBAF /* PopularVideosView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37AAF27D26737323007FC770 /* PopularVideosView.swift */; }; @@ -85,8 +83,6 @@ 377FC7E4267A084E00A6BBAF /* SearchView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37AAF27F26737550007FC770 /* SearchView.swift */; }; 377FC7E5267A084E00A6BBAF /* SearchView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37AAF27F26737550007FC770 /* SearchView.swift */; }; 377FC7ED267A0A0800A6BBAF /* SwiftyJSON in Frameworks */ = {isa = PBXBuildFile; productRef = 377FC7EC267A0A0800A6BBAF /* SwiftyJSON */; }; - 377FC7EF267A0A0800A6BBAF /* URLImage in Frameworks */ = {isa = PBXBuildFile; productRef = 377FC7EE267A0A0800A6BBAF /* URLImage */; }; - 377FC7F1267A0A0800A6BBAF /* URLImageStore in Frameworks */ = {isa = PBXBuildFile; productRef = 377FC7F0267A0A0800A6BBAF /* URLImageStore */; }; 377FC7F3267A0A0800A6BBAF /* Logging in Frameworks */ = {isa = PBXBuildFile; productRef = 377FC7F2267A0A0800A6BBAF /* Logging */; }; 3797757D268922D100DD52A8 /* Siesta in Frameworks */ = {isa = PBXBuildFile; productRef = 3797757C268922D100DD52A8 /* Siesta */; }; 37977583268922F600DD52A8 /* InvidiousAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37977582268922F600DD52A8 /* InvidiousAPI.swift */; }; @@ -175,8 +171,6 @@ 37D4B19826717E1500C925CA /* Video.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37D4B19626717E1500C925CA /* Video.swift */; }; 37D4B19926717E1500C925CA /* Video.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37D4B19626717E1500C925CA /* Video.swift */; }; 37D4B19D2671817900C925CA /* SwiftyJSON in Frameworks */ = {isa = PBXBuildFile; productRef = 37D4B19C2671817900C925CA /* SwiftyJSON */; }; - 37D4B1AB2672580400C925CA /* URLImage in Frameworks */ = {isa = PBXBuildFile; productRef = 37D4B1AA2672580400C925CA /* URLImage */; }; - 37D4B1AD2672580400C925CA /* URLImageStore in Frameworks */ = {isa = PBXBuildFile; productRef = 37D4B1AC2672580400C925CA /* URLImageStore */; }; 37EAD86B267B9C5600D9E01B /* SponsorBlockAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37EAD86A267B9C5600D9E01B /* SponsorBlockAPI.swift */; }; 37EAD86C267B9C5600D9E01B /* SponsorBlockAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37EAD86A267B9C5600D9E01B /* SponsorBlockAPI.swift */; }; 37EAD86D267B9C5600D9E01B /* SponsorBlockAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37EAD86A267B9C5600D9E01B /* SponsorBlockAPI.swift */; }; @@ -294,10 +288,8 @@ files = ( 37BD07B72698AB2E003EBB87 /* Defaults in Frameworks */, 37BADCA52699FB72009BE4FB /* Alamofire in Frameworks */, - 377FC7D9267A080300A6BBAF /* URLImageStore in Frameworks */, 377FC7D5267A080300A6BBAF /* SwiftyJSON in Frameworks */, 37BD07B92698AB2E003EBB87 /* Siesta in Frameworks */, - 377FC7D7267A080300A6BBAF /* URLImage in Frameworks */, 37BD07C72698B27B003EBB87 /* Introspect in Frameworks */, 377FC7DB267A080300A6BBAF /* Logging in Frameworks */, ); @@ -309,10 +301,8 @@ files = ( 37BD07BE2698AC96003EBB87 /* Defaults in Frameworks */, 37BADCA7269A552E009BE4FB /* Alamofire in Frameworks */, - 377FC7F1267A0A0800A6BBAF /* URLImageStore in Frameworks */, 377FC7ED267A0A0800A6BBAF /* SwiftyJSON in Frameworks */, 37BD07C02698AC97003EBB87 /* Siesta in Frameworks */, - 377FC7EF267A0A0800A6BBAF /* URLImage in Frameworks */, 377FC7F3267A0A0800A6BBAF /* Logging in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -337,10 +327,8 @@ files = ( 372915E42687E33E00F5A35B /* Defaults in Frameworks */, 37BADCA9269A570B009BE4FB /* Alamofire in Frameworks */, - 37D4B1AD2672580400C925CA /* URLImageStore in Frameworks */, 37D4B19D2671817900C925CA /* SwiftyJSON in Frameworks */, 3797757D268922D100DD52A8 /* Siesta in Frameworks */, - 37D4B1AB2672580400C925CA /* URLImage in Frameworks */, 37B767E02678C5BF0098BAA8 /* Logging in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -536,8 +524,6 @@ name = "Pearvidious (iOS)"; packageProductDependencies = ( 377FC7D4267A080300A6BBAF /* SwiftyJSON */, - 377FC7D6267A080300A6BBAF /* URLImage */, - 377FC7D8267A080300A6BBAF /* URLImageStore */, 377FC7DA267A080300A6BBAF /* Logging */, 37BD07B62698AB2E003EBB87 /* Defaults */, 37BD07B82698AB2E003EBB87 /* Siesta */, @@ -563,8 +549,6 @@ name = "Pearvidious (macOS)"; packageProductDependencies = ( 377FC7EC267A0A0800A6BBAF /* SwiftyJSON */, - 377FC7EE267A0A0800A6BBAF /* URLImage */, - 377FC7F0267A0A0800A6BBAF /* URLImageStore */, 377FC7F2267A0A0800A6BBAF /* Logging */, 37BD07BD2698AC96003EBB87 /* Defaults */, 37BD07BF2698AC97003EBB87 /* Siesta */, @@ -625,8 +609,6 @@ name = "Pearvidious (Apple TV)"; packageProductDependencies = ( 37D4B19C2671817900C925CA /* SwiftyJSON */, - 37D4B1AA2672580400C925CA /* URLImage */, - 37D4B1AC2672580400C925CA /* URLImageStore */, 37B767DF2678C5BF0098BAA8 /* Logging */, 372915E32687E33E00F5A35B /* Defaults */, 3797757C268922D100DD52A8 /* Siesta */, @@ -698,7 +680,6 @@ mainGroup = 37D4B0BC2671614700C925CA; packageReferences = ( 37D4B19B2671817900C925CA /* XCRemoteSwiftPackageReference "SwiftyJSON" */, - 37D4B1A92672580400C925CA /* XCRemoteSwiftPackageReference "url-image" */, 37B767DE2678C5BF0098BAA8 /* XCRemoteSwiftPackageReference "swift-log" */, 372915E22687E33E00F5A35B /* XCRemoteSwiftPackageReference "Defaults" */, 3797757B268922D100DD52A8 /* XCRemoteSwiftPackageReference "siesta" */, @@ -1558,14 +1539,6 @@ minimumVersion = 5.0.0; }; }; - 37D4B1A92672580400C925CA /* XCRemoteSwiftPackageReference "url-image" */ = { - isa = XCRemoteSwiftPackageReference; - repositoryURL = "https://github.com/dmytro-anokhin/url-image"; - requirement = { - kind = upToNextMajorVersion; - minimumVersion = 3.0.0; - }; - }; /* End XCRemoteSwiftPackageReference section */ /* Begin XCSwiftPackageProductDependency section */ @@ -1579,16 +1552,6 @@ package = 37D4B19B2671817900C925CA /* XCRemoteSwiftPackageReference "SwiftyJSON" */; productName = SwiftyJSON; }; - 377FC7D6267A080300A6BBAF /* URLImage */ = { - isa = XCSwiftPackageProductDependency; - package = 37D4B1A92672580400C925CA /* XCRemoteSwiftPackageReference "url-image" */; - productName = URLImage; - }; - 377FC7D8267A080300A6BBAF /* URLImageStore */ = { - isa = XCSwiftPackageProductDependency; - package = 37D4B1A92672580400C925CA /* XCRemoteSwiftPackageReference "url-image" */; - productName = URLImageStore; - }; 377FC7DA267A080300A6BBAF /* Logging */ = { isa = XCSwiftPackageProductDependency; package = 37B767DE2678C5BF0098BAA8 /* XCRemoteSwiftPackageReference "swift-log" */; @@ -1599,16 +1562,6 @@ package = 37D4B19B2671817900C925CA /* XCRemoteSwiftPackageReference "SwiftyJSON" */; productName = SwiftyJSON; }; - 377FC7EE267A0A0800A6BBAF /* URLImage */ = { - isa = XCSwiftPackageProductDependency; - package = 37D4B1A92672580400C925CA /* XCRemoteSwiftPackageReference "url-image" */; - productName = URLImage; - }; - 377FC7F0267A0A0800A6BBAF /* URLImageStore */ = { - isa = XCSwiftPackageProductDependency; - package = 37D4B1A92672580400C925CA /* XCRemoteSwiftPackageReference "url-image" */; - productName = URLImageStore; - }; 377FC7F2267A0A0800A6BBAF /* Logging */ = { isa = XCSwiftPackageProductDependency; package = 37B767DE2678C5BF0098BAA8 /* XCRemoteSwiftPackageReference "swift-log" */; @@ -1669,16 +1622,6 @@ package = 37D4B19B2671817900C925CA /* XCRemoteSwiftPackageReference "SwiftyJSON" */; productName = SwiftyJSON; }; - 37D4B1AA2672580400C925CA /* URLImage */ = { - isa = XCSwiftPackageProductDependency; - package = 37D4B1A92672580400C925CA /* XCRemoteSwiftPackageReference "url-image" */; - productName = URLImage; - }; - 37D4B1AC2672580400C925CA /* URLImageStore */ = { - isa = XCSwiftPackageProductDependency; - package = 37D4B1A92672580400C925CA /* XCRemoteSwiftPackageReference "url-image" */; - productName = URLImageStore; - }; /* End XCSwiftPackageProductDependency section */ }; rootObject = 37D4B0BD2671614700C925CA /* Project object */; diff --git a/Pearvidious.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Pearvidious.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 2d352f2e..e4e6775c 100644 --- a/Pearvidious.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Pearvidious.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -20,7 +20,7 @@ } }, { - "package": "siesta", + "package": "Siesta", "repositoryURL": "https://github.com/bustoutsolutions/siesta", "state": { "branch": null, @@ -38,7 +38,7 @@ } }, { - "package": "SwiftUI-Introspect", + "package": "Introspect", "repositoryURL": "https://github.com/siteline/SwiftUI-Introspect.git", "state": { "branch": null, @@ -54,15 +54,6 @@ "revision": "b3dcd7dbd0d488e1a7077cb33b00f2083e382f07", "version": "5.0.1" } - }, - { - "package": "url-image", - "repositoryURL": "https://github.com/dmytro-anokhin/url-image", - "state": { - "branch": null, - "revision": "a55b6597f6ce67dfbdc136ecfb8c8436b14ca41d", - "version": "3.1.0" - } } ] }, diff --git a/Shared/PearvidiousApp.swift b/Shared/PearvidiousApp.swift index 2e6aec7d..303e0967 100644 --- a/Shared/PearvidiousApp.swift +++ b/Shared/PearvidiousApp.swift @@ -1,15 +1,10 @@ import SwiftUI -import URLImage -import URLImageStore @main struct PearvidiousApp: App { var body: some Scene { - let urlImageService = URLImageService(fileStore: URLImageFileStore(), - inMemoryStore: URLImageInMemoryStore()) WindowGroup { ContentView() - .environment(\.urlImageService, urlImageService) } } } diff --git a/Shared/VideoView.swift b/Shared/VideoView.swift new file mode 100644 index 00000000..25a85531 --- /dev/null +++ b/Shared/VideoView.swift @@ -0,0 +1,20 @@ +// +// VideoView.swift +// VideoView +// +// Created by Arkadiusz Fal on 26/07/2021. +// + +import SwiftUI + +struct VideoView: View { + var body: some View { + Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/) + } +} + +struct VideoView_Previews: PreviewProvider { + static var previews: some View { + VideoView() + } +}