Update Kingfisher

This commit is contained in:
Justin Mazzocchi 2021-01-07 18:29:08 -08:00
parent f34fc7097d
commit b5e128a1b0
No known key found for this signature in database
GPG key ID: E223E6937AAFB01C
7 changed files with 64 additions and 43 deletions

View file

@ -1,11 +1,6 @@
// Copyright © 2020 Metabolist. All rights reserved. // Copyright © 2020 Metabolist. All rights reserved.
import struct Kingfisher.DownsamplingImageProcessor import Kingfisher
import struct Kingfisher.FormatIndicatedCacheSerializer
import protocol Kingfisher.ImageProcessor
import struct Kingfisher.KingfisherOptionsInfo
import struct Kingfisher.RoundCornerImageProcessor
import KingfisherSwiftUI
import SwiftUI import SwiftUI
extension KingfisherOptionsInfo { extension KingfisherOptionsInfo {
@ -28,3 +23,23 @@ extension KingfisherOptionsInfo {
downsampled(size: CGSize(width: dimension, height: dimension), scaleFactor: scaleFactor, rounded: rounded) 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)
}
}

View file

@ -38,7 +38,6 @@
D065966125899E890096AC5D /* CompositionAttachmentCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D065966025899E890096AC5D /* CompositionAttachmentCollectionViewCell.swift */; }; D065966125899E890096AC5D /* CompositionAttachmentCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D065966025899E890096AC5D /* CompositionAttachmentCollectionViewCell.swift */; };
D065966225899E890096AC5D /* 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 */; }; 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 */; }; D06BC5E625202AD90079541D /* ProfileViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D06BC5E525202AD90079541D /* ProfileViewController.swift */; };
D0804133258D902900AD6139 /* CompositionAttachmentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0804132258D902900AD6139 /* CompositionAttachmentView.swift */; }; D0804133258D902900AD6139 /* CompositionAttachmentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0804132258D902900AD6139 /* CompositionAttachmentView.swift */; };
D0804134258D902900AD6139 /* 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 */; }; D0F0B126251A90F400942152 /* AccountListCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0F0B125251A90F400942152 /* AccountListCell.swift */; };
D0F0B12E251A97E400942152 /* TableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0F0B12D251A97E400942152 /* TableViewController.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 */; }; 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 */; }; 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 */; }; D0FCC105259C4E61000B67DF /* NewStatusViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0FCC104259C4E61000B67DF /* NewStatusViewController.swift */; };
D0FCC106259C4E62000B67DF /* 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 */; }; D0FCC110259C4F20000B67DF /* NewStatusView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0FCC10F259C4F20000B67DF /* NewStatusView.swift */; };
@ -286,7 +286,7 @@
isa = PBXFrameworksBuildPhase; isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
D06B492324D4611300642749 /* KingfisherSwiftUI in Frameworks */, D0F5880525A7E4C500E3A49C /* Kingfisher in Frameworks */,
D0E2C1D124FD97F000854680 /* ViewModels in Frameworks */, D0E2C1D124FD97F000854680 /* ViewModels in Frameworks */,
D0BECB9F2501D9AD002C1B13 /* PreviewViewModels in Frameworks */, D0BECB9F2501D9AD002C1B13 /* PreviewViewModels in Frameworks */,
); );
@ -303,7 +303,7 @@
isa = PBXFrameworksBuildPhase; isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
D0F2D54025818C4B00986197 /* Kingfisher in Frameworks */, D0F5880F25A7E6CC00E3A49C /* Kingfisher in Frameworks */,
D04F9E8E259E9C950081B0C9 /* ViewModels in Frameworks */, D04F9E8E259E9C950081B0C9 /* ViewModels in Frameworks */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
@ -580,9 +580,9 @@
); );
name = Metatext; name = Metatext;
packageProductDependencies = ( packageProductDependencies = (
D06B492224D4611300642749 /* KingfisherSwiftUI */,
D0E2C1D024FD97F000854680 /* ViewModels */, D0E2C1D024FD97F000854680 /* ViewModels */,
D0BECB9E2501D9AD002C1B13 /* PreviewViewModels */, D0BECB9E2501D9AD002C1B13 /* PreviewViewModels */,
D0F5880425A7E4C500E3A49C /* Kingfisher */,
); );
productName = "Metatext (iOS)"; productName = "Metatext (iOS)";
productReference = D047FA8C24C3E21200AF17C5 /* Metatext.app */; productReference = D047FA8C24C3E21200AF17C5 /* Metatext.app */;
@ -622,8 +622,8 @@
); );
name = "Share Extension"; name = "Share Extension";
packageProductDependencies = ( packageProductDependencies = (
D0F2D53F25818C4B00986197 /* Kingfisher */,
D04F9E8D259E9C950081B0C9 /* ViewModels */, D04F9E8D259E9C950081B0C9 /* ViewModels */,
D0F5880E25A7E6CC00E3A49C /* Kingfisher */,
); );
productName = "Share Extension"; productName = "Share Extension";
productReference = D08E526C257C36CA00FA2C5F /* Share Extension.appex */; productReference = D08E526C257C36CA00FA2C5F /* Share Extension.appex */;
@ -686,7 +686,7 @@
); );
mainGroup = D047FA7F24C3E21000AF17C5; mainGroup = D047FA7F24C3E21000AF17C5;
packageReferences = ( packageReferences = (
D06B492124D4611300642749 /* XCRemoteSwiftPackageReference "Kingfisher" */, D0F5880325A7E4C500E3A49C /* XCRemoteSwiftPackageReference "Kingfisher" */,
); );
productRefGroup = D047FA8D24C3E21200AF17C5 /* Products */; productRefGroup = D047FA8D24C3E21200AF17C5 /* Products */;
projectDirPath = ""; projectDirPath = "";
@ -1276,12 +1276,12 @@
/* End XCConfigurationList section */ /* End XCConfigurationList section */
/* Begin XCRemoteSwiftPackageReference section */ /* Begin XCRemoteSwiftPackageReference section */
D06B492124D4611300642749 /* XCRemoteSwiftPackageReference "Kingfisher" */ = { D0F5880325A7E4C500E3A49C /* XCRemoteSwiftPackageReference "Kingfisher" */ = {
isa = XCRemoteSwiftPackageReference; isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/onevcat/Kingfisher"; repositoryURL = "https://github.com/onevcat/Kingfisher";
requirement = { requirement = {
kind = upToNextMajorVersion; kind = upToNextMajorVersion;
minimumVersion = 5.15.8; minimumVersion = 6.0.1;
}; };
}; };
/* End XCRemoteSwiftPackageReference section */ /* End XCRemoteSwiftPackageReference section */
@ -1291,11 +1291,6 @@
isa = XCSwiftPackageProductDependency; isa = XCSwiftPackageProductDependency;
productName = ViewModels; productName = ViewModels;
}; };
D06B492224D4611300642749 /* KingfisherSwiftUI */ = {
isa = XCSwiftPackageProductDependency;
package = D06B492124D4611300642749 /* XCRemoteSwiftPackageReference "Kingfisher" */;
productName = KingfisherSwiftUI;
};
D0BECB972501C0FC002C1B13 /* Secrets */ = { D0BECB972501C0FC002C1B13 /* Secrets */ = {
isa = XCSwiftPackageProductDependency; isa = XCSwiftPackageProductDependency;
productName = Secrets; productName = Secrets;
@ -1312,9 +1307,14 @@
isa = XCSwiftPackageProductDependency; isa = XCSwiftPackageProductDependency;
productName = ViewModels; productName = ViewModels;
}; };
D0F2D53F25818C4B00986197 /* Kingfisher */ = { D0F5880425A7E4C500E3A49C /* Kingfisher */ = {
isa = XCSwiftPackageProductDependency; isa = XCSwiftPackageProductDependency;
package = D06B492124D4611300642749 /* XCRemoteSwiftPackageReference "Kingfisher" */; package = D0F5880325A7E4C500E3A49C /* XCRemoteSwiftPackageReference "Kingfisher" */;
productName = Kingfisher;
};
D0F5880E25A7E6CC00E3A49C /* Kingfisher */ = {
isa = XCSwiftPackageProductDependency;
package = D0F5880325A7E4C500E3A49C /* XCRemoteSwiftPackageReference "Kingfisher" */;
productName = Kingfisher; productName = Kingfisher;
}; };
/* End XCSwiftPackageProductDependency section */ /* End XCSwiftPackageProductDependency section */

View file

@ -24,8 +24,8 @@
"repositoryURL": "https://github.com/onevcat/Kingfisher", "repositoryURL": "https://github.com/onevcat/Kingfisher",
"state": { "state": {
"branch": null, "branch": null,
"revision": "2a10bf41da75599a9f8e872dbd44fe0155a2e00c", "revision": "0be276f6a7fd54af4c3eb03f2d12e12d8c8a1a1d",
"version": "5.15.8" "version": "6.0.1"
} }
} }
] ]

View file

@ -1,6 +1,6 @@
// Copyright © 2020 Metabolist. All rights reserved. // Copyright © 2020 Metabolist. All rights reserved.
import KingfisherSwiftUI import Kingfisher
import SwiftUI import SwiftUI
import ViewModels import ViewModels

View file

@ -1,6 +1,6 @@
// Copyright © 2020 Metabolist. All rights reserved. // Copyright © 2020 Metabolist. All rights reserved.
import KingfisherSwiftUI import Kingfisher
import struct ServiceLayer.Identity import struct ServiceLayer.Identity
import SwiftUI import SwiftUI
import ViewModels import ViewModels
@ -63,8 +63,8 @@ private extension IdentitiesView {
@ViewBuilder @ViewBuilder
func row(identity: Identity) -> some View { func row(identity: Identity) -> some View {
HStack { HStack {
KFImage(identity.image, KFImage(identity.image)
options: .downsampled(dimension: 40, scaleFactor: displayScale)) .downsampled(dimension: 40, scaleFactor: displayScale)
VStack(alignment: .leading, spacing: 0) { VStack(alignment: .leading, spacing: 0) {
Spacer() Spacer()
if identity.authenticated { if identity.authenticated {

View file

@ -1,6 +1,6 @@
// Copyright © 2020 Metabolist. All rights reserved. // Copyright © 2020 Metabolist. All rights reserved.
import KingfisherSwiftUI import Kingfisher
import SwiftUI import SwiftUI
import ViewModels import ViewModels
@ -17,8 +17,8 @@ struct SecondaryNavigationView: View {
destination: IdentitiesView(viewModel: .init(identification: viewModel.identification)), destination: IdentitiesView(viewModel: .init(identification: viewModel.identification)),
label: { label: {
HStack { HStack {
KFImage(viewModel.identification.identity.image, KFImage(viewModel.identification.identity.image)
options: .downsampled(dimension: .avatarDimension, scaleFactor: displayScale)) .downsampled(dimension: .avatarDimension, scaleFactor: displayScale)
VStack(alignment: .leading) { VStack(alignment: .leading) {
if viewModel.identification.identity.authenticated { if viewModel.identification.identity.authenticated {
if let account = viewModel.identification.identity.account { if let account = viewModel.identification.identity.account {

View file

@ -1,6 +1,6 @@
// Copyright © 2020 Metabolist. All rights reserved. // Copyright © 2020 Metabolist. All rights reserved.
import KingfisherSwiftUI import Kingfisher
import SwiftUI import SwiftUI
import ViewModels import ViewModels
@ -10,6 +10,8 @@ struct TabNavigationView: View {
@Environment(\.displayScale) var displayScale: CGFloat @Environment(\.displayScale) var displayScale: CGFloat
@State var selectedTab = NavigationViewModel.Tab.timelines @State var selectedTab = NavigationViewModel.Tab.timelines
@State private var contextMenuImages = [UUID: KFImage]()
var body: some View { var body: some View {
Group { Group {
if viewModel.identification.identity.pending { if viewModel.identification.identity.pending {
@ -50,6 +52,16 @@ struct TabNavigationView: View {
}) })
.alertItem($viewModel.alertItem) .alertItem($viewModel.alertItem)
.onAppear(perform: viewModel.refreshIdentity) .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 .onReceive(NotificationCenter.default
.publisher(for: UIScene.willEnterForegroundNotification) .publisher(for: UIScene.willEnterForegroundNotification)
.map { _ in () }, .map { _ in () },
@ -132,10 +144,10 @@ private extension TabNavigationView {
Button { Button {
viewModel.presentingSecondaryNavigation.toggle() viewModel.presentingSecondaryNavigation.toggle()
} label: { } label: {
KFImage(viewModel.identification.identity.image, KFImage(viewModel.identification.identity.image)
options: .downsampled( .downsampled(
dimension: .barButtonItemDimension, dimension: .barButtonItemDimension,
scaleFactor: displayScale)) scaleFactor: displayScale)
.placeholder { Image(systemName: "gear") } .placeholder { Image(systemName: "gear") }
.renderingMode(.original) .renderingMode(.original)
.contextMenu(ContextMenu { .contextMenu(ContextMenu {
@ -145,13 +157,7 @@ private extension TabNavigationView {
} label: { } label: {
Label( Label(
title: { Text(recentIdentity.handle) }, title: { Text(recentIdentity.handle) },
icon: { icon: { contextMenuImages[recentIdentity.id] })
KFImage(recentIdentity.image,
options: .downsampled(
dimension: .barButtonItemDimension,
scaleFactor: displayScale))
.renderingMode(.original)
})
} }
} }
}) })