-
Notifications
You must be signed in to change notification settings - Fork 34
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
Get scale factor for view from trait collection instead of screen #110
Conversation
e8f2e83
to
6324d72
Compare
6324d72
to
3b3e625
Compare
3b3e625
to
1f443b9
Compare
#if os(iOS) | ||
return (window?.screen ?? UIScreen.main).pixelsPerPoint | ||
#endif |
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 OS check is a precursor to #111, where we can't use UIScreen
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.
We might also be able to fall back to window?.traitCollection ?? UITraitCollection.current
as an alternative way to get the scale instead of UIScreen
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.
If it's in a window, it should get the traits from the window automatically, so I don't think the first part is necessary. Falling back to the current global trait collection is a really interesting idea though. I think in practice it would probably be safe to do so, but UITraitCollection.current
has some really weird behavior around when it's valid to read, so I'm a bit hesitant to use it here. I think for now using UIScreen
is safer (and should give the same value).
#if os(iOS) | ||
return (window?.screen ?? UIScreen.main).pixelsPerPoint | ||
#endif |
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.
We might also be able to fall back to window?.traitCollection ?? UITraitCollection.current
as an alternative way to get the scale instead of UIScreen
No description provided.