From 21c44db04bce270efbd27cb4e2492a513818cc1e Mon Sep 17 00:00:00 2001 From: hyun99999 Date: Wed, 18 Oct 2023 13:31:43 +0900 Subject: [PATCH 1/4] Use UIApplication instead of UIScreen.main on iOS 13.0 and later --- Sources/Impl/Coordinates.swift | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Sources/Impl/Coordinates.swift b/Sources/Impl/Coordinates.swift index 0aa7f71..8b63b9d 100644 --- a/Sources/Impl/Coordinates.swift +++ b/Sources/Impl/Coordinates.swift @@ -108,7 +108,12 @@ final class Coordinates { private func getDisplayScale() -> CGFloat { #if os(iOS) || os(tvOS) + if #available(iOS 13.0, *) { + let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene + return windowScene?.screen.scale ?? .zero + } else { return UIScreen.main.scale + } #elseif os(OSX) #if swift(>=4.1) return NSScreen.main?.backingScaleFactor ?? 2.0 From 1703b4d9a0593cc58dca32bc3369020065894980 Mon Sep 17 00:00:00 2001 From: hyun99999 Date: Wed, 18 Oct 2023 22:54:59 +0900 Subject: [PATCH 2/4] Add control flow's condition --- Sources/Impl/Coordinates.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Impl/Coordinates.swift b/Sources/Impl/Coordinates.swift index 8b63b9d..3999b7d 100644 --- a/Sources/Impl/Coordinates.swift +++ b/Sources/Impl/Coordinates.swift @@ -108,7 +108,7 @@ final class Coordinates { private func getDisplayScale() -> CGFloat { #if os(iOS) || os(tvOS) - if #available(iOS 13.0, *) { + if #available(iOS 13.0, tvOS 13.0, *) { let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene return windowScene?.screen.scale ?? .zero } else { From b2ff6d5a3d4c66e605db6eb1ac72f6c2404b4ff8 Mon Sep 17 00:00:00 2001 From: hyun99999 Date: Thu, 19 Oct 2023 00:49:02 +0900 Subject: [PATCH 3/4] Fix .zero to 1.0 ensure minimal operation through the scale factor. --- Sources/Impl/Coordinates.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Impl/Coordinates.swift b/Sources/Impl/Coordinates.swift index 3999b7d..afd74d9 100644 --- a/Sources/Impl/Coordinates.swift +++ b/Sources/Impl/Coordinates.swift @@ -110,7 +110,7 @@ private func getDisplayScale() -> CGFloat { #if os(iOS) || os(tvOS) if #available(iOS 13.0, tvOS 13.0, *) { let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene - return windowScene?.screen.scale ?? .zero + return windowScene?.screen.scale ?? 1.0 } else { return UIScreen.main.scale } From d103ba264820a1a2a5acc80cbca487c7856508a2 Mon Sep 17 00:00:00 2001 From: hyun99999 Date: Wed, 1 Nov 2023 18:17:33 +0900 Subject: [PATCH 4/4] Use UITraitCollection to access display scale --- Sources/Impl/Coordinates.swift | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Sources/Impl/Coordinates.swift b/Sources/Impl/Coordinates.swift index afd74d9..2d22563 100644 --- a/Sources/Impl/Coordinates.swift +++ b/Sources/Impl/Coordinates.swift @@ -109,8 +109,7 @@ final class Coordinates { private func getDisplayScale() -> CGFloat { #if os(iOS) || os(tvOS) if #available(iOS 13.0, tvOS 13.0, *) { - let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene - return windowScene?.screen.scale ?? 1.0 + return UITraitCollection.current.displayScale } else { return UIScreen.main.scale }