mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-04 10:33:45 +00:00
Fixes #2259 - Fix flipped notification placeholder avatars on iOS 17.2+
This commit is contained in:
committed by
Stefan Ceriu
parent
72a84badcb
commit
278e202f9a
@@ -189,10 +189,11 @@ extension UNMutableNotificationContent {
|
|||||||
return updatedContent.mutableCopy() as! UNMutableNotificationContent
|
return updatedContent.mutableCopy() as! UNMutableNotificationContent
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@MainActor
|
||||||
private func getPlaceholderAvatarImageData(name: String, id: String) async -> Data? {
|
private func getPlaceholderAvatarImageData(name: String, id: String) async -> Data? {
|
||||||
// The version value is used in case the design of the placeholder is updated to force a replacement
|
// The version value is used in case the design of the placeholder is updated to force a replacement
|
||||||
let isIOS17Available = isIOS17Available()
|
let shouldFlipAvatar = shouldFlipAvatar()
|
||||||
let prefix = "notification_placeholder\(isIOS17Available ? "V3" : "V2")"
|
let prefix = "notification_placeholder\(shouldFlipAvatar ? "V5" : "V4")"
|
||||||
let fileName = "\(prefix)_\(name)_\(id).png"
|
let fileName = "\(prefix)_\(name)_\(id).png"
|
||||||
if let data = try? Data(contentsOf: URL.temporaryDirectory.appendingPathComponent(fileName)) {
|
if let data = try? Data(contentsOf: URL.temporaryDirectory.appendingPathComponent(fileName)) {
|
||||||
MXLog.info("Found existing notification icon placeholder")
|
MXLog.info("Found existing notification icon placeholder")
|
||||||
@@ -204,24 +205,24 @@ extension UNMutableNotificationContent {
|
|||||||
contentID: id)
|
contentID: id)
|
||||||
.clipShape(Circle())
|
.clipShape(Circle())
|
||||||
.frame(width: 50, height: 50)
|
.frame(width: 50, height: 50)
|
||||||
let renderer = await ImageRenderer(content: image)
|
let renderer = ImageRenderer(content: image)
|
||||||
guard let image = await renderer.uiImage else {
|
|
||||||
|
// Specify the scale so the image is rendered correctly. We don't have access to the screen
|
||||||
|
// here so a hardcoded 3.0 will have to do
|
||||||
|
renderer.scale = 3.0
|
||||||
|
|
||||||
|
guard let image = renderer.uiImage else {
|
||||||
MXLog.info("Generating notification icon placeholder failed")
|
MXLog.info("Generating notification icon placeholder failed")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
let data: Data?
|
let data: Data?
|
||||||
// On simulator and macOS the image is rendered correctly
|
|
||||||
// But on other devices before iOS 17 is rendered upside down so we need to flip it
|
if shouldFlipAvatar {
|
||||||
#if targetEnvironment(simulator)
|
|
||||||
data = image.pngData()
|
|
||||||
#else
|
|
||||||
if ProcessInfo.processInfo.isiOSAppOnMac || isIOS17Available {
|
|
||||||
data = image.pngData()
|
|
||||||
} else {
|
|
||||||
data = image.flippedVertically().pngData()
|
data = image.flippedVertically().pngData()
|
||||||
|
} else {
|
||||||
|
data = image.pngData()
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
if let data {
|
if let data {
|
||||||
do {
|
do {
|
||||||
@@ -235,12 +236,26 @@ extension UNMutableNotificationContent {
|
|||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
private func isIOS17Available() -> Bool {
|
/// On simulators and macOS the image is rendered correctly
|
||||||
|
/// On devices before iOS 17 and after iOS 17.2 it's rendered upside down and needs to be flipped
|
||||||
|
private func shouldFlipAvatar() -> Bool {
|
||||||
|
#if targetEnvironment(simulator)
|
||||||
|
return false
|
||||||
|
#else
|
||||||
|
if ProcessInfo.processInfo.isiOSAppOnMac {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
guard let version = Version(UIDevice.current.systemVersion) else {
|
guard let version = Version(UIDevice.current.systemVersion) else {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
return version.major >= 17
|
if version >= Version(17, 0, 0), version < Version(17, 2, 0) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
Fix flipped notification placeholder avatars on iOS 17.2+
|
||||||
Reference in New Issue
Block a user