-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace UIScreen.main
to get display scale on iOS 13.0 and later (#2215)
#2216
Conversation
UIApplication
instead of UIScreen.main
on iOS 13.0 and laterUIApplication
instead of UIScreen.main
on iOS 13.0 and later (#2215)
UIApplication
instead of UIScreen.main
on iOS 13.0 and later (#2215)window.windowScene.screen
instead of UIScreen.main
on iOS 13.0 and later (#2215)
@@ -39,7 +39,11 @@ open class LottieAnimationViewBase: UIView { | |||
|
|||
var screenScale: CGFloat { | |||
#if os(iOS) || os(tvOS) | |||
UIScreen.main.scale | |||
if #available(iOS 13.0, *) { | |||
return window?.windowScene?.screen.scale ?? .zero |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to provide a reasonable fallback, similar to UIScreen.main.scale
, rather than just .zero
? Returning .zero
for some reason would result in a very broken experience.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UIScreen.main.scale
has several values taht each device display.
For Retina displays, the scale factor may be 3.0 or 2.0 and one point can represented by nine or four pixels, respectively. For standard-resolution displays, the scale factor is 1.0 and one point equals one pixel
https://developer.apple.com/documentation/uikit/uiscreen/1617836-scale
Not all devices had a Retina display for the iPhone. This is expected complex control flow.
If there noting special happens, a view will have window.windowScene
. However, it seems reasonable to set it to 1.0
to ensure minimal operation through the scale factor.
- Related commit history : d3cbc94
- add tvOS 13.0 Co-authored-by: Cal Stephens <[email protected]>
@@ -39,7 +39,11 @@ open class LottieAnimationViewBase: UIView { | |||
|
|||
var screenScale: CGFloat { | |||
#if os(iOS) || os(tvOS) | |||
UIScreen.main.scale | |||
if #available(iOS 13.0, tvOS 13.0, *) { | |||
return window?.windowScene?.screen.scale ?? 1.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will still be a behavior change if window == nil
, but I'm not sure if there's a case where that matters (since if window == nil
then the view isn't on-screen anyway).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm on the same page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your review so far.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently screenScale
is only accessed in commonInit()
, which is called during init()
. At this point view.window
is always nil
, so screenScale
will always be 1.0
.
If we're going to access view.window
, then we need to handle the case where the window
changes, e.g. by rerunning any logic that depends on the window
or screenScale
in didMoveToWindow
.
Head branch was pushed to by a user without write access
Implements |
- delete `-` and space.
hmm.. window property has |
I don't think the change you made fixed the problem, because |
Hmmmmm, this probably would be a breaking change for some number of consumers. Is there a way for us to #if def the check, so we use the simpler code unless in an app extension? |
What would the code look like using |
Like this! let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene
windowScene?.screen.scale |
I don't understand '#if def the check'. Perdon? |
CI/Test Package are continuously failed. |
- to use `UIApplication.shared`
I was thinking something like this: https://stackoverflow.com/questions/25048026/how-to-detect-if-code-is-running-in-main-app-or-app-extension-target but it sounds like this won't be possible for us since (1) we don't control the custom build flags, and (2) we distribute pre-compiled binaries. So I don't think we can use |
Recently i access screenScale in |
window.windowScene.screen
instead of UIScreen.main
on iOS 13.0 and later (#2215)UIScreen.main
to get display scale on iOS 13.0 and later (#2215)
Co-authored-by: Cal Stephens <[email protected]>
Thanks! |
Thank you for your sincere review! 🙌 |
This PR contains the following updates: | Package | Update | Change | |---|---|---| | [airbnb/lottie-spm](https://togithub.com/airbnb/lottie-spm) | patch | `from: "4.3.3"` -> `from: "4.3.4"` | --- ### Release Notes <details> <summary>airbnb/lottie-spm (airbnb/lottie-spm)</summary> ### [`v4.3.4`](https://togithub.com/airbnb/lottie-spm/releases/tag/4.3.4) [Compare Source](https://togithub.com/airbnb/lottie-spm/compare/4.3.3...4.3.4) #### What's Changed - Fix parsing regression in 4.3.0 from addition of parsing layer effects by [@​calda](https://togithub.com/calda) in [https://github.com/airbnb/lottie-ios/pull/2208](https://togithub.com/airbnb/lottie-ios/pull/2208) - Remove old animation layer when creating a new animation layer by [@​junjielu](https://togithub.com/junjielu) in [https://github.com/airbnb/lottie-ios/pull/2214](https://togithub.com/airbnb/lottie-ios/pull/2214) - Add configuration setting to remove animated bounds changes by [@​thedrick](https://togithub.com/thedrick) in [https://github.com/airbnb/lottie-ios/pull/2218](https://togithub.com/airbnb/lottie-ios/pull/2218) - Change pod dependencies `SwiftUI` and `Combine` to `weak` to ensure compatibility with iOS 12 by [@​florianrhein](https://togithub.com/florianrhein) in [https://github.com/airbnb/lottie-ios/pull/2219](https://togithub.com/airbnb/lottie-ios/pull/2219) - Fix issue where Repeater would be ignored if not at top level by [@​calda](https://togithub.com/calda) in [https://github.com/airbnb/lottie-ios/pull/2221](https://togithub.com/airbnb/lottie-ios/pull/2221) - Replace `UIScreen.main` to get display scale on iOS 13.0 and later ([#​2215](https://togithub.com/airbnb/lottie-spm/issues/2215)) by [@​hyun99999](https://togithub.com/hyun99999) in [https://github.com/airbnb/lottie-ios/pull/2216](https://togithub.com/airbnb/lottie-ios/pull/2216) - Dispatch dot lottie file loading onto a single serial queue by [@​erichoracek](https://togithub.com/erichoracek) in [https://github.com/airbnb/lottie-ios/pull/2229](https://togithub.com/airbnb/lottie-ios/pull/2229) - Clean up unused property in InvertedMatteLayer by [@​hanton](https://togithub.com/hanton) in [https://github.com/airbnb/lottie-ios/pull/2241](https://togithub.com/airbnb/lottie-ios/pull/2241) - Fix issue where LottieView animation would restart from beginning after backgrounding app by [@​calda](https://togithub.com/calda) in [https://github.com/airbnb/lottie-ios/pull/2237](https://togithub.com/airbnb/lottie-ios/pull/2237) **Full Changelog**: airbnb/lottie-ios@4.3.3...4.3.4 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox. 👻 **Immortal**: This PR will be recreated if closed unmerged. Get [config help](https://togithub.com/renovatebot/renovate/discussions) if that's undesired. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://togithub.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNi4xMDAuMCIsInVwZGF0ZWRJblZlciI6IjM2LjEwMC4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9--> Co-authored-by: Self-hosted Renovate Bot <361546+cgrindel-self-hosted-renovate[bot]@users.noreply.github.enterprise.com>
…IScreen.main.scale` (airbnb#2216) Co-authored-by: Cal Stephens <[email protected]>
…IScreen.main.scale` (airbnb#2216) Co-authored-by: Cal Stephens <[email protected]>
UIScree.main
will be deprecated in a future version of iOS.I used
window.windowScene.screen
to get display's scale.developer doc > mian already deprecated. It causes serious errors in the near future.
So have to change another way. And
window.windowScene.screen
is the one way of getting display's scale. That is available fromiOS 13.0
. This is why control flow hasiOS 13.0
condition.Resolved: #2215