Fix for flipped image notification placeholder on iPhone (#1200)

* fix

* better handling

* reverted wrong commit

* typo in changlog
This commit is contained in:
Mauro
2023-06-28 16:52:23 +02:00
committed by GitHub
parent afbb0a8260
commit e4959ff156
2 changed files with 28 additions and 2 deletions
@@ -122,7 +122,7 @@ extension UNMutableNotificationContent {
if let fetchedImage {
image = fetchedImage
} else if let data = await getPlaceholderAvatarImageData(name: icon.groupInfo?.name ?? senderName,
id: icon.groupInfo?.name ?? senderName) {
id: icon.groupInfo?.id ?? senderID) {
image = INImage(imageData: data)
} else {
image = INImage(named: "")
@@ -181,6 +181,31 @@ extension UNMutableNotificationContent {
.clipShape(Circle())
.frame(width: 100, height: 100)
let renderer = await ImageRenderer(content: image)
return await renderer.uiImage?.jpegData(compressionQuality: 0.8)
guard let image = await renderer.uiImage else {
return nil
}
// On simulator and macOS the image is rendered correctly
// But on other devices is rendered upside down so we need to flip it
#if targetEnvironment(simulator)
return image.pngData()
#else
if ProcessInfo.processInfo.isiOSAppOnMac {
return image.pngData()
} else {
return image.flippedVertically().pngData()
}
#endif
}
}
private extension UIImage {
func flippedVertically() -> UIImage {
let format = UIGraphicsImageRendererFormat()
format.scale = scale
return UIGraphicsImageRenderer(size: size, format: format).image { context in
context.cgContext.concatenate(CGAffineTransform(scaleX: 1, y: -1))
self.draw(at: CGPoint(x: 0, y: -size.height))
}
}
}
+1
View File
@@ -0,0 +1 @@
Fix for the flipped notification image placeholder on iOS.