diff --git a/MastodonSDK/Sources/MastodonUI/Extension/UIImage.swift b/MastodonSDK/Sources/MastodonUI/Extension/UIImage.swift index 5a83e1d619..ad027fc92d 100644 --- a/MastodonSDK/Sources/MastodonUI/Extension/UIImage.swift +++ b/MastodonSDK/Sources/MastodonUI/Extension/UIImage.swift @@ -18,12 +18,10 @@ extension UIImage { } extension UIImage { - public func normalized() -> UIImage? { + public func normalized() -> UIImage { if imageOrientation == .up { return self } - UIGraphicsBeginImageContext(size) - draw(in: CGRect(origin: CGPoint.zero, size: size)) - let image = UIGraphicsGetImageFromCurrentImageContext() - UIGraphicsEndImageContext() - return image + return UIGraphicsImageRenderer(size: size).image { _ in + draw(in: CGRect(origin: .zero, size: size)) + } } - } +} diff --git a/MastodonSDK/Sources/MastodonUI/Scene/ComposeContent/Attachment/AttachmentViewModel+Load.swift b/MastodonSDK/Sources/MastodonUI/Scene/ComposeContent/Attachment/AttachmentViewModel+Load.swift index 7cfd51eb5c..8757f9c726 100644 --- a/MastodonSDK/Sources/MastodonUI/Scene/ComposeContent/Attachment/AttachmentViewModel+Load.swift +++ b/MastodonSDK/Sources/MastodonUI/Scene/ComposeContent/Attachment/AttachmentViewModel+Load.swift @@ -16,7 +16,7 @@ extension AttachmentViewModel { func load(input: Input) async throws -> Output { switch input { case .image(let image): - guard let data = image.normalized()?.pngData() else { + guard let data = image.normalized().pngData() else { throw AttachmentError.invalidAttachmentType } return .image(data, imageKind: .png) diff --git a/MastodonSDK/Sources/MastodonUI/View/Control/StripProgressView.swift b/MastodonSDK/Sources/MastodonUI/View/Control/StripProgressView.swift index 8d429594fb..72ab99557b 100644 --- a/MastodonSDK/Sources/MastodonUI/View/Control/StripProgressView.swift +++ b/MastodonSDK/Sources/MastodonUI/View/Control/StripProgressView.swift @@ -34,15 +34,7 @@ public final class StripProgressLayer: CALayer { return presentation()?.progress ?? self.progress }() - // os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s: progress: %.2f", ((#file as NSString).lastPathComponent), #line, #function, progress) - UIGraphicsBeginImageContextWithOptions(bounds.size, false, 0) - guard let context = UIGraphicsGetCurrentContext() else { - assertionFailure() - return - } - context.clear(bounds) - var rect = bounds let newWidth = CGFloat(progress) * rect.width let widthChanged = rect.width - newWidth @@ -53,13 +45,11 @@ public final class StripProgressLayer: CALayer { default: break } - let path = UIBezierPath(rect: rect) - context.setFillColor(tintColor.cgColor) - context.addPath(path.cgPath) - context.fillPath() - - contents = UIGraphicsGetImageFromCurrentImageContext()?.cgImage - UIGraphicsEndImageContext() + + contents = UIGraphicsImageRenderer(size: bounds.size).image { context in + tintColor.setFill() + context.fill(rect) + }.cgImage } }