From 50c77325f69bc60b1f47a7633a359c6ef0b742f9 Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Thu, 1 Sep 2022 18:51:59 +0200 Subject: [PATCH] Add CachedAsyncImage --- Shared/Player/ChapterView.swift | 3 +- Shared/Player/Controls/PlayerControls.swift | 3 +- Shared/Videos/VideoBanner.swift | 3 +- Shared/Videos/VideoCell.swift | 3 +- Shared/Views/ChannelCell.swift | 3 +- Shared/Views/ChannelPlaylistCell.swift | 3 +- Shared/Views/ControlsBar.swift | 3 +- Yattee.xcodeproj/project.pbxproj | 33 +++++++++++++++++++ .../xcshareddata/swiftpm/Package.resolved | 9 +++++ 9 files changed, 56 insertions(+), 7 deletions(-) diff --git a/Shared/Player/ChapterView.swift b/Shared/Player/ChapterView.swift index b6baca04..f8225bf2 100644 --- a/Shared/Player/ChapterView.swift +++ b/Shared/Player/ChapterView.swift @@ -1,3 +1,4 @@ +import CachedAsyncImage import Foundation import SDWebImageSwiftUI import SwiftUI @@ -32,7 +33,7 @@ struct ChapterView: View { @ViewBuilder func smallImage(_ chapter: Chapter) -> some View { if #available(iOS 15, macOS 12, *) { - AsyncImage(url: chapter.image) { image in + CachedAsyncImage(url: chapter.image) { image in image .resizable() } placeholder: { diff --git a/Shared/Player/Controls/PlayerControls.swift b/Shared/Player/Controls/PlayerControls.swift index f48f6e10..6eb70d8f 100644 --- a/Shared/Player/Controls/PlayerControls.swift +++ b/Shared/Player/Controls/PlayerControls.swift @@ -1,3 +1,4 @@ +import CachedAsyncImage import Defaults import Foundation import SDWebImageSwiftUI @@ -219,7 +220,7 @@ struct PlayerControls: View { let url = thumbnails.best(video) { if #available(iOS 15, macOS 12, *) { - AsyncImage(url: url) { image in + CachedAsyncImage(url: url) { image in image .resizable() } placeholder: { diff --git a/Shared/Videos/VideoBanner.swift b/Shared/Videos/VideoBanner.swift index 5d938f92..8c175fec 100644 --- a/Shared/Videos/VideoBanner.swift +++ b/Shared/Videos/VideoBanner.swift @@ -1,3 +1,4 @@ +import CachedAsyncImage import CoreMedia import Foundation import SDWebImageSwiftUI @@ -73,7 +74,7 @@ struct VideoBanner: View { @ViewBuilder private var smallThumbnail: some View { let url = video?.thumbnailURL(quality: .medium) if #available(iOS 15, macOS 12, *) { - AsyncImage(url: url) { image in + CachedAsyncImage(url: url) { image in image .resizable() } placeholder: { diff --git a/Shared/Videos/VideoCell.swift b/Shared/Videos/VideoCell.swift index 8236f4ea..501b5b17 100644 --- a/Shared/Videos/VideoCell.swift +++ b/Shared/Videos/VideoCell.swift @@ -1,3 +1,4 @@ +import CachedAsyncImage import CoreMedia import Defaults import SDWebImageSwiftUI @@ -422,7 +423,7 @@ struct VideoCell: View { Group { let url = thumbnails.best(video) if #available(iOS 15, macOS 12, *) { - AsyncImage(url: url) { image in + CachedAsyncImage(url: url) { image in image .resizable() } placeholder: { diff --git a/Shared/Views/ChannelCell.swift b/Shared/Views/ChannelCell.swift index 7243ccfb..cf526632 100644 --- a/Shared/Views/ChannelCell.swift +++ b/Shared/Views/ChannelCell.swift @@ -1,3 +1,4 @@ +import CachedAsyncImage import Foundation import SDWebImageSwiftUI import SwiftUI @@ -38,7 +39,7 @@ struct ChannelCell: View { } .foregroundColor(.secondary) if #available(iOS 15, macOS 12, *) { - AsyncImage(url: channel.thumbnailURL) { image in + CachedAsyncImage(url: channel.thumbnailURL) { image in image .resizable() } placeholder: { diff --git a/Shared/Views/ChannelPlaylistCell.swift b/Shared/Views/ChannelPlaylistCell.swift index a442f6a7..9e7bc0a5 100644 --- a/Shared/Views/ChannelPlaylistCell.swift +++ b/Shared/Views/ChannelPlaylistCell.swift @@ -1,3 +1,4 @@ +import CachedAsyncImage import SDWebImageSwiftUI import SwiftUI @@ -38,7 +39,7 @@ struct ChannelPlaylistCell: View { .foregroundColor(.secondary) if #available(iOS 15, macOS 12, *) { - AsyncImage(url: playlist.thumbnailURL) { image in + CachedAsyncImage(url: playlist.thumbnailURL) { image in image .resizable() } placeholder: { diff --git a/Shared/Views/ControlsBar.swift b/Shared/Views/ControlsBar.swift index d4c94e38..04d2ec8d 100644 --- a/Shared/Views/ControlsBar.swift +++ b/Shared/Views/ControlsBar.swift @@ -1,3 +1,4 @@ +import CachedAsyncImage import Defaults import SDWebImageSwiftUI import SwiftUI @@ -268,7 +269,7 @@ struct ControlsBar: View { Group { if let video = model.currentItem?.video, let url = video.channel.thumbnailURL { if #available(iOS 15, macOS 12, *) { - AsyncImage(url: url) { image in + CachedAsyncImage(url: url) { image in image .resizable() } placeholder: { diff --git a/Yattee.xcodeproj/project.pbxproj b/Yattee.xcodeproj/project.pbxproj index d4116054..1ace9233 100644 --- a/Yattee.xcodeproj/project.pbxproj +++ b/Yattee.xcodeproj/project.pbxproj @@ -246,6 +246,9 @@ 3736A219286BB72300C9E5EE /* libharfbuzz.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3736A1FC286BB72300C9E5EE /* libharfbuzz.xcframework */; }; 3736A21A286BB72300C9E5EE /* libmpv.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3736A1FD286BB72300C9E5EE /* libmpv.xcframework */; }; 3736A21B286BB72300C9E5EE /* libmpv.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3736A1FD286BB72300C9E5EE /* libmpv.xcframework */; }; + 373AD20128BF504B00DB3ADA /* CachedAsyncImage in Frameworks */ = {isa = PBXBuildFile; productRef = 373AD20028BF504B00DB3ADA /* CachedAsyncImage */; }; + 373AD20328BF512400DB3ADA /* CachedAsyncImage in Frameworks */ = {isa = PBXBuildFile; productRef = 373AD20228BF512400DB3ADA /* CachedAsyncImage */; }; + 373AD20528BF579F00DB3ADA /* CachedAsyncImage in Frameworks */ = {isa = PBXBuildFile; productRef = 373AD20428BF579F00DB3ADA /* CachedAsyncImage */; }; 373C8FE4275B955100CB5936 /* CommentsPage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 373C8FE3275B955100CB5936 /* CommentsPage.swift */; }; 373C8FE5275B955100CB5936 /* CommentsPage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 373C8FE3275B955100CB5936 /* CommentsPage.swift */; }; 373C8FE6275B955100CB5936 /* CommentsPage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 373C8FE3275B955100CB5936 /* CommentsPage.swift */; }; @@ -1355,6 +1358,7 @@ 375B8AB128B57F4200397B31 /* KeychainAccess in Frameworks */, 3736A21A286BB72300C9E5EE /* libmpv.xcframework in Frameworks */, 3765917C27237D21009F956E /* PINCache in Frameworks */, + 373AD20328BF512400DB3ADA /* CachedAsyncImage in Frameworks */, 37BD07B72698AB2E003EBB87 /* Defaults in Frameworks */, 3736A20C286BB72300C9E5EE /* libavutil.xcframework in Frameworks */, 37FB285627220D9000A57617 /* SDWebImagePINPlugin in Frameworks */, @@ -1418,6 +1422,7 @@ 3703205C27D2BAF3007A0CB8 /* SwiftyJSON in Frameworks */, 370F4FD627CC16CB001B35DC /* libbrotlidec.1.0.9.dylib in Frameworks */, 370F4FCD27CC16CB001B35DC /* libfribidi.0.dylib in Frameworks */, + 373AD20528BF579F00DB3ADA /* CachedAsyncImage in Frameworks */, 370F4FE027CC16CB001B35DC /* libX11.6.dylib in Frameworks */, 370F4FD727CC16CB001B35DC /* libharfbuzz-subset.0.dylib in Frameworks */, ); @@ -1467,6 +1472,7 @@ 3736A209286BB72300C9E5EE /* libcrypto.xcframework in Frameworks */, 37FB28462722054C00A57617 /* SDWebImageSwiftUI in Frameworks */, 3736A217286BB72300C9E5EE /* libavfilter.xcframework in Frameworks */, + 373AD20128BF504B00DB3ADA /* CachedAsyncImage in Frameworks */, 3736A21B286BB72300C9E5EE /* libmpv.xcframework in Frameworks */, 3765917E27237D2A009F956E /* PINCache in Frameworks */, 3772003E27E8EEEB00CB2475 /* VideoToolbox.framework in Frameworks */, @@ -2337,6 +2343,7 @@ 37EE6DC428A305AD00BFD632 /* Reachability */, 3799AC0828B03CED001376F9 /* ActiveLabel */, 375B8AB028B57F4200397B31 /* KeychainAccess */, + 373AD20228BF512400DB3ADA /* CachedAsyncImage */, ); productName = "Yattee (iOS)"; productReference = 37D4B0C92671614900C925CA /* Yattee.app */; @@ -2374,6 +2381,7 @@ 37A5DBC5285E06B100CA4DD1 /* SwiftUIPager */, 372AA413286D06A10000B1DC /* Repeat */, 375B8AB628B583BD00397B31 /* KeychainAccess */, + 373AD20428BF579F00DB3ADA /* CachedAsyncImage */, ); productName = "Yattee (macOS)"; productReference = 37D4B0CF2671614900C925CA /* Yattee.app */; @@ -2451,6 +2459,7 @@ 372AA411286D06950000B1DC /* Repeat */, 37E80F42287B7AAF00561799 /* SwiftUIPager */, 3732BFCF28B83763009F3F4D /* KeychainAccess */, + 373AD20028BF504B00DB3ADA /* CachedAsyncImage */, ); productName = Yattee; productReference = 37D4B158267164AE00C925CA /* Yattee.app */; @@ -2551,6 +2560,7 @@ 37EE6DC328A305AD00BFD632 /* XCRemoteSwiftPackageReference "Reachability" */, 3799AC0728B03CEC001376F9 /* XCRemoteSwiftPackageReference "ActiveLabel.swift" */, 375B8AAF28B57F4200397B31 /* XCRemoteSwiftPackageReference "KeychainAccess" */, + 373AD1FF28BF504B00DB3ADA /* XCRemoteSwiftPackageReference "swiftui-cached-async-image" */, ); productRefGroup = 37D4B0CA2671614900C925CA /* Products */; projectDirPath = ""; @@ -4394,6 +4404,14 @@ minimumVersion = 0.6.0; }; }; + 373AD1FF28BF504B00DB3ADA /* XCRemoteSwiftPackageReference "swiftui-cached-async-image" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/lorenzofiamingo/swiftui-cached-async-image"; + requirement = { + kind = upToNextMajorVersion; + minimumVersion = 2.0.0; + }; + }; 375B8AAF28B57F4200397B31 /* XCRemoteSwiftPackageReference "KeychainAccess" */ = { isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/kishikawakatsumi/KeychainAccess.git"; @@ -4579,6 +4597,21 @@ package = 375B8AAF28B57F4200397B31 /* XCRemoteSwiftPackageReference "KeychainAccess" */; productName = KeychainAccess; }; + 373AD20028BF504B00DB3ADA /* CachedAsyncImage */ = { + isa = XCSwiftPackageProductDependency; + package = 373AD1FF28BF504B00DB3ADA /* XCRemoteSwiftPackageReference "swiftui-cached-async-image" */; + productName = CachedAsyncImage; + }; + 373AD20228BF512400DB3ADA /* CachedAsyncImage */ = { + isa = XCSwiftPackageProductDependency; + package = 373AD1FF28BF504B00DB3ADA /* XCRemoteSwiftPackageReference "swiftui-cached-async-image" */; + productName = CachedAsyncImage; + }; + 373AD20428BF579F00DB3ADA /* CachedAsyncImage */ = { + isa = XCSwiftPackageProductDependency; + package = 373AD1FF28BF504B00DB3ADA /* XCRemoteSwiftPackageReference "swiftui-cached-async-image" */; + productName = CachedAsyncImage; + }; 375B8AB028B57F4200397B31 /* KeychainAccess */ = { isa = XCSwiftPackageProductDependency; package = 375B8AAF28B57F4200397B31 /* XCRemoteSwiftPackageReference "KeychainAccess" */; diff --git a/Yattee.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Yattee.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 2e728edf..2fa86942 100644 --- a/Yattee.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Yattee.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -135,6 +135,15 @@ "version" : "1.4.4" } }, + { + "identity" : "swiftui-cached-async-image", + "kind" : "remoteSourceControl", + "location" : "https://github.com/lorenzofiamingo/swiftui-cached-async-image", + "state" : { + "revision" : "467a3d17479887943ab917a379e62bbaff60ac8a", + "version" : "2.1.1" + } + }, { "identity" : "swiftui-introspect", "kind" : "remoteSourceControl",