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

Fixed wrong banner dimensions due to the wrong orientation detection #431

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

HappyIosDeveloper
Copy link

In a portrait application (in which the landscape is closed), if the device is not placed in a portrait state, the app will still be shown as portrait but the banner thinks the device is in landscape mode and shows the banner with the wrong dimensions.

return frame.width
if #available(iOS 13.0, *) {
if let scene = UIApplication.shared.connectedScenes.first as? UIWindowScene {
let orientation = UIApplication.shared.supportedInterfaceOrientations(for: scene.windows.first)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why supportedInterfaceOrientations is being checked here. Most of the time, if landscape is supported, then both .landscapeLeft and .landscapeRight would be in the mask returned. In that case, the switch would just fall through to the default of using frame.width. The same goes if both portrait and landscape orientations are supported. Shouldn't frame.width just be used all the time instead?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It prioritizes supported orientation over the current device orientation state, for example when the app is locked in portrait, and the device is in the landscape, it returns the portrait which will result in a correct orientation. I'm not sure if it's the best way to do it but just double-checked it and it works like a charm! Please feel free to upgrade it though!

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that supportedInterfaceOrientations should take priority over UIDevice.current.orientation. My point was that I think that simply checking window.frame.width or window.frame.height will take the app's current orientation (which is restricted by supported orientations) into account without needing to check for the app's supported orientations separately.

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.

3 participants