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

Fix preview orientation on iOS #20

Merged
merged 3 commits into from
Mar 24, 2024
Merged

Fix preview orientation on iOS #20

merged 3 commits into from
Mar 24, 2024

Conversation

janusw
Copy link
Owner

@janusw janusw commented Mar 22, 2024

This fixes #19 by using UIInterfaceOrientation instead of UIDeviceOrientation. Tested on iOS 16.7.6 and 17.4 (with an iPhone and iPad).

It also extends the test app to allow all four interface orientations on iPhones (PortraitUpsideDown was missing).

janusw added 2 commits March 21, 2024 21:44
…evice orientation

* the device orientation includes cases like faceUp and faceDown,
  which are not handled
@janusw
Copy link
Owner Author

janusw commented Mar 22, 2024

Note: The GHA build shows the warning

This call site is reachable on: 'iOS' 11.0 and later, 'maccatalyst' 13.0 and later.
'UIApplication.Windows' is obsoleted on:
'ios' 15.0 and later (Use 'UIWindowScene.Windows' in the desired window scene object instead.),
'maccatalyst' 15.0 and later (Use 'UIWindowScene.Windows' in the desired window scene object instead.).
(https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1422)

However, the call still seems to work on iOS 16 & 17.

@janusw
Copy link
Owner Author

janusw commented Mar 22, 2024

Moreover, on the same line, there also is this warning:

This call site is reachable on: 'iOS' 11.0 and later, 'maccatalyst' 13.0 and later.
'UIWindow.WindowScene' is only supported on: 'ios' 13.0 and later.
(https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416)

I think the warning is incorrect, because the line is guarded by OperatingSystem.IsIOSVersionAtLeast(13). AFAICS this is due to the following diagnostic bug: dotnet/roslyn-analyzers#7239
See also: dotnet/maui#21106

…d above

* 'UIApplication.Windows' is obsoleted on: 'ios' 15.0 and later
  (Use 'UIWindowScene.Windows' in the desired window scene object instead.)
@janusw
Copy link
Owner Author

janusw commented Mar 24, 2024

Note: The GHA build shows the warning

This call site is reachable on: 'iOS' 11.0 and later, 'maccatalyst' 13.0 and later.
'UIApplication.Windows' is obsoleted on:
'ios' 15.0 and later (Use 'UIWindowScene.Windows' in the desired window scene object instead.),
'maccatalyst' 15.0 and later (Use 'UIWindowScene.Windows' in the desired window scene object instead.).
(https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1422)

However, the call still seems to work on iOS 16 & 17.

This deprecation warning is fixed in commit 062e8dc via the method used in https://www.delasign.com/blog/swift-device-orientation/. This should make the code more future-proof.

As before, I tested this on iOS 16 & 17 (with the front and back camera).

@janusw janusw merged commit 028dd9a into master Mar 24, 2024
4 checks passed
@janusw janusw deleted the ios_preview_orientation branch March 24, 2024 14:11
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.

Camera preview on iOS sometimes rotated in landscape orientation
1 participant