From 864ec73a9ad7c0741e81ba5ce64eb56e6f755b86 Mon Sep 17 00:00:00 2001 From: woxtu Date: Wed, 11 Jan 2023 17:10:04 +0900 Subject: [PATCH] Remove Kingfisher (#858) * Replace image type detection * Replace image processing * Remove Kingfisher --- Documentation/Acknowledgments.md | 1 - .../xcshareddata/swiftpm/Package.resolved | 9 --------- MastodonSDK/Package.swift | 2 -- .../Attachment/AttachmentViewModel+Compress.swift | 14 +++++++------- .../Attachment/AttachmentViewModel+Load.swift | 8 +++++--- .../Attachment/AttachmentViewModel+Upload.swift | 1 - .../Attachment/AttachmentViewModel.swift | 1 - .../ComposeContent/View/ComposeContentView.swift | 1 - 8 files changed, 12 insertions(+), 25 deletions(-) diff --git a/Documentation/Acknowledgments.md b/Documentation/Acknowledgments.md index 3e9a2d7b4..a9389bb9f 100644 --- a/Documentation/Acknowledgments.md +++ b/Documentation/Acknowledgments.md @@ -13,7 +13,6 @@ - [Fuzi](https://github.com/cezheng/Fuzi) - [Kanna](https://github.com/tid-kijyun/Kanna) - [KeychainAccess](https://github.com/kishikawakatsumi/KeychainAccess.git) -- [Kingfisher](https://github.com/onevcat/Kingfisher) - [MetaTextKit](https://github.com/TwidereProject/MetaTextKit) - [Nuke-FLAnimatedImage-Plugin](https://github.com/kean/Nuke-FLAnimatedImage-Plugin) - [Nuke](https://github.com/kean/Nuke) diff --git a/Mastodon.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Mastodon.xcworkspace/xcshareddata/swiftpm/Package.resolved index e029f5bed..cd7395c7e 100644 --- a/Mastodon.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Mastodon.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -73,15 +73,6 @@ "version": "4.2.2" } }, - { - "package": "Kingfisher", - "repositoryURL": "https://github.com/onevcat/Kingfisher.git", - "state": { - "branch": null, - "revision": "44e891bdb61426a95e31492a67c7c0dfad1f87c5", - "version": "7.4.1" - } - }, { "package": "MetaTextKit", "repositoryURL": "https://github.com/TwidereProject/MetaTextKit.git", diff --git a/MastodonSDK/Package.swift b/MastodonSDK/Package.swift index 6d87f3d1b..12aadd888 100644 --- a/MastodonSDK/Package.swift +++ b/MastodonSDK/Package.swift @@ -56,7 +56,6 @@ let package = Package( .package(url: "https://github.com/woxtu/UIHostingConfigurationBackport.git", from: "0.1.0"), .package(url: "https://github.com/SDWebImage/SDWebImage.git", from: "5.12.0"), .package(url: "https://github.com/eneko/Stripes.git", from: "0.2.0"), - .package(url: "https://github.com/onevcat/Kingfisher.git", from: "7.4.1"), .package(url: "https://github.com/NextLevel/NextLevelSessionExporter.git", from: "0.4.6"), ], targets: [ @@ -131,7 +130,6 @@ let package = Package( .product(name: "CropViewController", package: "TOCropViewController"), .product(name: "PanModal", package: "PanModal"), .product(name: "Stripes", package: "Stripes"), - .product(name: "Kingfisher", package: "Kingfisher"), .product(name: "NextLevelSessionExporter", package: "NextLevelSessionExporter"), ] ), diff --git a/MastodonSDK/Sources/MastodonUI/Scene/ComposeContent/Attachment/AttachmentViewModel+Compress.swift b/MastodonSDK/Sources/MastodonUI/Scene/ComposeContent/Attachment/AttachmentViewModel+Compress.swift index 417bc773a..059a5bc3e 100644 --- a/MastodonSDK/Sources/MastodonUI/Scene/ComposeContent/Attachment/AttachmentViewModel+Compress.swift +++ b/MastodonSDK/Sources/MastodonUI/Scene/ComposeContent/Attachment/AttachmentViewModel+Compress.swift @@ -10,7 +10,7 @@ import UIKit import AVKit import MastodonCore import SessionExporter -import Kingfisher +import Nuke extension AttachmentViewModel { func compressVideo(url: URL) async throws -> URL { @@ -99,18 +99,18 @@ extension AttachmentViewModel { func compressImage(data: Data, sizeLimit: SizeLimit) throws -> Output { let maxPayloadSizeInBytes = max((sizeLimit.image ?? 10 * 1024 * 1024), 1 * 1024 * 1024) - guard let image = KFCrossPlatformImage(data: data)?.kf.normalized, - var imageData = image.kf.pngRepresentation() + guard let image = UIImage(data: data)?.normalized(), + var imageData = image.pngData() else { throw AttachmentError.invalidAttachmentType } repeat { - guard let image = KFCrossPlatformImage(data: imageData) else { + guard let image = UIImage(data: imageData) else { throw AttachmentError.invalidAttachmentType } - if imageData.kf.imageFormat == .PNG { + if AssetType(imageData) == .png { // A. png image if imageData.count > maxPayloadSizeInBytes { guard let compressedJpegData = image.jpegData(compressionQuality: 0.8) else { @@ -126,7 +126,7 @@ extension AttachmentViewModel { // B. other image if imageData.count > maxPayloadSizeInBytes { let targetSize = CGSize(width: image.size.width * 0.8, height: image.size.height * 0.8) - let scaledImage = image.kf.resize(to: targetSize) + let scaledImage = image.resized(size: targetSize) guard let compressedJpegData = scaledImage.jpegData(compressionQuality: 0.8) else { throw AttachmentError.invalidAttachmentType } @@ -140,7 +140,7 @@ extension AttachmentViewModel { } while (imageData.count > maxPayloadSizeInBytes) - return .image(imageData, imageKind: imageData.kf.imageFormat == .PNG ? .png : .jpg) + return .image(imageData, imageKind: AssetType(imageData) == .png ? .png : .jpg) } } diff --git a/MastodonSDK/Sources/MastodonUI/Scene/ComposeContent/Attachment/AttachmentViewModel+Load.swift b/MastodonSDK/Sources/MastodonUI/Scene/ComposeContent/Attachment/AttachmentViewModel+Load.swift index 7cfd51eb5..02cd60be9 100644 --- a/MastodonSDK/Sources/MastodonUI/Scene/ComposeContent/Attachment/AttachmentViewModel+Load.swift +++ b/MastodonSDK/Sources/MastodonUI/Scene/ComposeContent/Attachment/AttachmentViewModel+Load.swift @@ -9,6 +9,7 @@ import os.log import UIKit import AVKit import UniformTypeIdentifiers +import Nuke extension AttachmentViewModel { @@ -55,7 +56,7 @@ extension AttachmentViewModel { } defer { url.stopAccessingSecurityScopedResource() } let imageData = try Data(contentsOf: url) - return .image(imageData, imageKind: imageData.kf.imageFormat == .PNG ? .png : .jpg) + return .image(imageData, imageKind: AssetType(imageData) == .png ? .png : .jpg) } else if uti.conforms(to: .movie) { guard url.startAccessingSecurityScopedResource() else { throw AttachmentError.invalidAttachmentType @@ -89,11 +90,12 @@ extension AttachmentViewModel { } let imageData = result.data + let assetType = AssetType(imageData) - if imageData.kf.imageFormat == .PNG { + if assetType == .png { return .png } - if imageData.kf.imageFormat == .JPEG { + if assetType == .jpeg { return .jpg } diff --git a/MastodonSDK/Sources/MastodonUI/Scene/ComposeContent/Attachment/AttachmentViewModel+Upload.swift b/MastodonSDK/Sources/MastodonUI/Scene/ComposeContent/Attachment/AttachmentViewModel+Upload.swift index 4f99f0ba1..607c581ed 100644 --- a/MastodonSDK/Sources/MastodonUI/Scene/ComposeContent/Attachment/AttachmentViewModel+Upload.swift +++ b/MastodonSDK/Sources/MastodonUI/Scene/ComposeContent/Attachment/AttachmentViewModel+Upload.swift @@ -7,7 +7,6 @@ import os.log import UIKit -import Kingfisher import UniformTypeIdentifiers import MastodonCore import MastodonSDK diff --git a/MastodonSDK/Sources/MastodonUI/Scene/ComposeContent/Attachment/AttachmentViewModel.swift b/MastodonSDK/Sources/MastodonUI/Scene/ComposeContent/Attachment/AttachmentViewModel.swift index 3ff97769e..03df6426e 100644 --- a/MastodonSDK/Sources/MastodonUI/Scene/ComposeContent/Attachment/AttachmentViewModel.swift +++ b/MastodonSDK/Sources/MastodonUI/Scene/ComposeContent/Attachment/AttachmentViewModel.swift @@ -9,7 +9,6 @@ import os.log import UIKit import Combine import PhotosUI -import Kingfisher import MastodonCore import MastodonLocalization import func QuartzCore.CACurrentMediaTime diff --git a/MastodonSDK/Sources/MastodonUI/Scene/ComposeContent/View/ComposeContentView.swift b/MastodonSDK/Sources/MastodonUI/Scene/ComposeContent/View/ComposeContentView.swift index a7f867f60..8d06d4c1e 100644 --- a/MastodonSDK/Sources/MastodonUI/Scene/ComposeContent/View/ComposeContentView.swift +++ b/MastodonSDK/Sources/MastodonUI/Scene/ComposeContent/View/ComposeContentView.swift @@ -11,7 +11,6 @@ import MastodonAsset import MastodonCore import MastodonLocalization import Stripes -import Kingfisher public struct ComposeContentView: View {