Skip to content
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

Merged
merged 1 commit into from
Apr 17, 2024

Conversation

NickEntin
Copy link
Collaborator

No description provided.

@NickEntin NickEntin changed the base branch from entin/tvos to master April 16, 2024 21:51
Comment on lines +45 to +47
#if os(iOS)
return (window?.screen ?? UIScreen.main).pixelsPerPoint
#endif
Copy link
Collaborator Author

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

Copy link
Collaborator

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

Copy link
Collaborator Author

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).

@NickEntin NickEntin marked this pull request as ready for review April 16, 2024 23:07
Comment on lines +45 to +47
#if os(iOS)
return (window?.screen ?? UIScreen.main).pixelsPerPoint
#endif
Copy link
Collaborator

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

@NickEntin NickEntin merged commit a1f0be7 into master Apr 17, 2024
6 checks passed
@NickEntin NickEntin deleted the entin/scale-from-traits branch April 17, 2024 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants