diff --git a/Extensions/KingfisherOptionsInfo+Extensions.swift b/Extensions/KingfisherOptionsInfo+Extensions.swift index 03482c6..f734e4e 100644 --- a/Extensions/KingfisherOptionsInfo+Extensions.swift +++ b/Extensions/KingfisherOptionsInfo+Extensions.swift @@ -1,11 +1,6 @@ // Copyright © 2020 Metabolist. All rights reserved. -import struct Kingfisher.DownsamplingImageProcessor -import struct Kingfisher.FormatIndicatedCacheSerializer -import protocol Kingfisher.ImageProcessor -import struct Kingfisher.KingfisherOptionsInfo -import struct Kingfisher.RoundCornerImageProcessor -import KingfisherSwiftUI +import Kingfisher import SwiftUI extension KingfisherOptionsInfo { @@ -28,3 +23,23 @@ extension KingfisherOptionsInfo { downsampled(size: CGSize(width: dimension, height: dimension), scaleFactor: scaleFactor, rounded: rounded) } } + +extension KFOptionSetter { + func downsampled(size: CGSize, scaleFactor: CGFloat, rounded: Bool = true) -> Self { + var processor: ImageProcessor = DownsamplingImageProcessor(size: size) + + if rounded { + processor = processor.append(another: RoundCornerImageProcessor(radius: .widthFraction(0.5))) + } + options.processor = processor + options.scaleFactor = scaleFactor + options.cacheOriginalImage = true + options.cacheSerializer = FormatIndicatedCacheSerializer.png + + return self + } + + func downsampled(dimension: CGFloat, scaleFactor: CGFloat, rounded: Bool = true) -> Self { + downsampled(size: CGSize(width: dimension, height: dimension), scaleFactor: scaleFactor, rounded: rounded) + } +} diff --git a/Metatext.xcodeproj/project.pbxproj b/Metatext.xcodeproj/project.pbxproj index 731b034..b2b0713 100644 --- a/Metatext.xcodeproj/project.pbxproj +++ b/Metatext.xcodeproj/project.pbxproj @@ -38,7 +38,6 @@ D065966125899E890096AC5D /* CompositionAttachmentCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D065966025899E890096AC5D /* CompositionAttachmentCollectionViewCell.swift */; }; D065966225899E890096AC5D /* CompositionAttachmentCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D065966025899E890096AC5D /* CompositionAttachmentCollectionViewCell.swift */; }; D065966725899E910096AC5D /* CompositionAttachmentsDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = D065965A25899DAE0096AC5D /* CompositionAttachmentsDataSource.swift */; }; - D06B492324D4611300642749 /* KingfisherSwiftUI in Frameworks */ = {isa = PBXBuildFile; productRef = D06B492224D4611300642749 /* KingfisherSwiftUI */; }; D06BC5E625202AD90079541D /* ProfileViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D06BC5E525202AD90079541D /* ProfileViewController.swift */; }; D0804133258D902900AD6139 /* CompositionAttachmentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0804132258D902900AD6139 /* CompositionAttachmentView.swift */; }; D0804134258D902900AD6139 /* CompositionAttachmentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0804132258D902900AD6139 /* CompositionAttachmentView.swift */; }; @@ -117,8 +116,9 @@ D0F0B126251A90F400942152 /* AccountListCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0F0B125251A90F400942152 /* AccountListCell.swift */; }; D0F0B12E251A97E400942152 /* TableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0F0B12D251A97E400942152 /* TableViewController.swift */; }; D0F0B136251AA12700942152 /* CollectionItem+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0F0B135251AA12700942152 /* CollectionItem+Extensions.swift */; }; - D0F2D54025818C4B00986197 /* Kingfisher in Frameworks */ = {isa = PBXBuildFile; productRef = D0F2D53F25818C4B00986197 /* Kingfisher */; }; D0F2D54B2581CF7D00986197 /* VisualEffectBlur.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0F2D54A2581CF7D00986197 /* VisualEffectBlur.swift */; }; + D0F5880525A7E4C500E3A49C /* Kingfisher in Frameworks */ = {isa = PBXBuildFile; productRef = D0F5880425A7E4C500E3A49C /* Kingfisher */; }; + D0F5880F25A7E6CC00E3A49C /* Kingfisher in Frameworks */ = {isa = PBXBuildFile; productRef = D0F5880E25A7E6CC00E3A49C /* Kingfisher */; }; D0FCC105259C4E61000B67DF /* NewStatusViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0FCC104259C4E61000B67DF /* NewStatusViewController.swift */; }; D0FCC106259C4E62000B67DF /* NewStatusViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0FCC104259C4E61000B67DF /* NewStatusViewController.swift */; }; D0FCC110259C4F20000B67DF /* NewStatusView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0FCC10F259C4F20000B67DF /* NewStatusView.swift */; }; @@ -286,7 +286,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - D06B492324D4611300642749 /* KingfisherSwiftUI in Frameworks */, + D0F5880525A7E4C500E3A49C /* Kingfisher in Frameworks */, D0E2C1D124FD97F000854680 /* ViewModels in Frameworks */, D0BECB9F2501D9AD002C1B13 /* PreviewViewModels in Frameworks */, ); @@ -303,7 +303,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - D0F2D54025818C4B00986197 /* Kingfisher in Frameworks */, + D0F5880F25A7E6CC00E3A49C /* Kingfisher in Frameworks */, D04F9E8E259E9C950081B0C9 /* ViewModels in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -580,9 +580,9 @@ ); name = Metatext; packageProductDependencies = ( - D06B492224D4611300642749 /* KingfisherSwiftUI */, D0E2C1D024FD97F000854680 /* ViewModels */, D0BECB9E2501D9AD002C1B13 /* PreviewViewModels */, + D0F5880425A7E4C500E3A49C /* Kingfisher */, ); productName = "Metatext (iOS)"; productReference = D047FA8C24C3E21200AF17C5 /* Metatext.app */; @@ -622,8 +622,8 @@ ); name = "Share Extension"; packageProductDependencies = ( - D0F2D53F25818C4B00986197 /* Kingfisher */, D04F9E8D259E9C950081B0C9 /* ViewModels */, + D0F5880E25A7E6CC00E3A49C /* Kingfisher */, ); productName = "Share Extension"; productReference = D08E526C257C36CA00FA2C5F /* Share Extension.appex */; @@ -686,7 +686,7 @@ ); mainGroup = D047FA7F24C3E21000AF17C5; packageReferences = ( - D06B492124D4611300642749 /* XCRemoteSwiftPackageReference "Kingfisher" */, + D0F5880325A7E4C500E3A49C /* XCRemoteSwiftPackageReference "Kingfisher" */, ); productRefGroup = D047FA8D24C3E21200AF17C5 /* Products */; projectDirPath = ""; @@ -1276,12 +1276,12 @@ /* End XCConfigurationList section */ /* Begin XCRemoteSwiftPackageReference section */ - D06B492124D4611300642749 /* XCRemoteSwiftPackageReference "Kingfisher" */ = { + D0F5880325A7E4C500E3A49C /* XCRemoteSwiftPackageReference "Kingfisher" */ = { isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/onevcat/Kingfisher"; requirement = { kind = upToNextMajorVersion; - minimumVersion = 5.15.8; + minimumVersion = 6.0.1; }; }; /* End XCRemoteSwiftPackageReference section */ @@ -1291,11 +1291,6 @@ isa = XCSwiftPackageProductDependency; productName = ViewModels; }; - D06B492224D4611300642749 /* KingfisherSwiftUI */ = { - isa = XCSwiftPackageProductDependency; - package = D06B492124D4611300642749 /* XCRemoteSwiftPackageReference "Kingfisher" */; - productName = KingfisherSwiftUI; - }; D0BECB972501C0FC002C1B13 /* Secrets */ = { isa = XCSwiftPackageProductDependency; productName = Secrets; @@ -1312,9 +1307,14 @@ isa = XCSwiftPackageProductDependency; productName = ViewModels; }; - D0F2D53F25818C4B00986197 /* Kingfisher */ = { + D0F5880425A7E4C500E3A49C /* Kingfisher */ = { isa = XCSwiftPackageProductDependency; - package = D06B492124D4611300642749 /* XCRemoteSwiftPackageReference "Kingfisher" */; + package = D0F5880325A7E4C500E3A49C /* XCRemoteSwiftPackageReference "Kingfisher" */; + productName = Kingfisher; + }; + D0F5880E25A7E6CC00E3A49C /* Kingfisher */ = { + isa = XCSwiftPackageProductDependency; + package = D0F5880325A7E4C500E3A49C /* XCRemoteSwiftPackageReference "Kingfisher" */; productName = Kingfisher; }; /* End XCSwiftPackageProductDependency section */ diff --git a/Metatext.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Metatext.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 96210f2..61e971a 100644 --- a/Metatext.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Metatext.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -24,8 +24,8 @@ "repositoryURL": "https://github.com/onevcat/Kingfisher", "state": { "branch": null, - "revision": "2a10bf41da75599a9f8e872dbd44fe0155a2e00c", - "version": "5.15.8" + "revision": "0be276f6a7fd54af4c3eb03f2d12e12d8c8a1a1d", + "version": "6.0.1" } } ] diff --git a/Views/AddIdentityView.swift b/Views/AddIdentityView.swift index d1194b7..727be67 100644 --- a/Views/AddIdentityView.swift +++ b/Views/AddIdentityView.swift @@ -1,6 +1,6 @@ // Copyright © 2020 Metabolist. All rights reserved. -import KingfisherSwiftUI +import Kingfisher import SwiftUI import ViewModels diff --git a/Views/IdentitiesView.swift b/Views/IdentitiesView.swift index 520e68a..051a5b5 100644 --- a/Views/IdentitiesView.swift +++ b/Views/IdentitiesView.swift @@ -1,6 +1,6 @@ // Copyright © 2020 Metabolist. All rights reserved. -import KingfisherSwiftUI +import Kingfisher import struct ServiceLayer.Identity import SwiftUI import ViewModels @@ -63,8 +63,8 @@ private extension IdentitiesView { @ViewBuilder func row(identity: Identity) -> some View { HStack { - KFImage(identity.image, - options: .downsampled(dimension: 40, scaleFactor: displayScale)) + KFImage(identity.image) + .downsampled(dimension: 40, scaleFactor: displayScale) VStack(alignment: .leading, spacing: 0) { Spacer() if identity.authenticated { diff --git a/Views/SecondaryNavigationView.swift b/Views/SecondaryNavigationView.swift index 75289a6..090777e 100644 --- a/Views/SecondaryNavigationView.swift +++ b/Views/SecondaryNavigationView.swift @@ -1,6 +1,6 @@ // Copyright © 2020 Metabolist. All rights reserved. -import KingfisherSwiftUI +import Kingfisher import SwiftUI import ViewModels @@ -17,8 +17,8 @@ struct SecondaryNavigationView: View { destination: IdentitiesView(viewModel: .init(identification: viewModel.identification)), label: { HStack { - KFImage(viewModel.identification.identity.image, - options: .downsampled(dimension: .avatarDimension, scaleFactor: displayScale)) + KFImage(viewModel.identification.identity.image) + .downsampled(dimension: .avatarDimension, scaleFactor: displayScale) VStack(alignment: .leading) { if viewModel.identification.identity.authenticated { if let account = viewModel.identification.identity.account { diff --git a/Views/TabNavigationView.swift b/Views/TabNavigationView.swift index 9b0a4f2..09a8bc4 100644 --- a/Views/TabNavigationView.swift +++ b/Views/TabNavigationView.swift @@ -1,6 +1,6 @@ // Copyright © 2020 Metabolist. All rights reserved. -import KingfisherSwiftUI +import Kingfisher import SwiftUI import ViewModels @@ -10,6 +10,8 @@ struct TabNavigationView: View { @Environment(\.displayScale) var displayScale: CGFloat @State var selectedTab = NavigationViewModel.Tab.timelines + @State private var contextMenuImages = [UUID: KFImage]() + var body: some View { Group { if viewModel.identification.identity.pending { @@ -50,6 +52,16 @@ struct TabNavigationView: View { }) .alertItem($viewModel.alertItem) .onAppear(perform: viewModel.refreshIdentity) + // Have to preload these, otherwise the context menu won't display them when first expanded + .onReceive(viewModel.$recentIdentities) { + contextMenuImages = Dictionary(uniqueKeysWithValues: $0.map { + ($0.id, KFImage($0.image) + .downsampled( + dimension: .barButtonItemDimension, + scaleFactor: displayScale) + .renderingMode(.original)) + }) + } .onReceive(NotificationCenter.default .publisher(for: UIScene.willEnterForegroundNotification) .map { _ in () }, @@ -132,10 +144,10 @@ private extension TabNavigationView { Button { viewModel.presentingSecondaryNavigation.toggle() } label: { - KFImage(viewModel.identification.identity.image, - options: .downsampled( - dimension: .barButtonItemDimension, - scaleFactor: displayScale)) + KFImage(viewModel.identification.identity.image) + .downsampled( + dimension: .barButtonItemDimension, + scaleFactor: displayScale) .placeholder { Image(systemName: "gear") } .renderingMode(.original) .contextMenu(ContextMenu { @@ -145,13 +157,7 @@ private extension TabNavigationView { } label: { Label( title: { Text(recentIdentity.handle) }, - icon: { - KFImage(recentIdentity.image, - options: .downsampled( - dimension: .barButtonItemDimension, - scaleFactor: displayScale)) - .renderingMode(.original) - }) + icon: { contextMenuImages[recentIdentity.id] }) } } })