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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[iOS] OrientationStateTrigger does not detect orientation state changes on iPad (works on iPhone) #20491

Closed
matt-goldman opened this issue Feb 10, 2024 · 3 comments
Labels
platform/iOS 馃崕 t/bug Something isn't working

Comments

@matt-goldman
Copy link
Contributor

matt-goldman commented Feb 10, 2024

Description

On iPad, the device orientation state is not detected by OrientationStateTrigger. It works on iPhone, but not iPad, using the same iOS version (馃し).

I have also tried attaching IsActiveChanged - in the event handler I just log something to the console output. And verified that the event is not triggered on iPad (can also verify with a breakpoint).

Steps to Reproduce

  1. Create a File | New | .NET MAUI app
  2. Add a Style. Target anything, it doesn't matter
  3. Add a Setter for VisualStateManager.VisualStateGroups
  4. Add a VisualStateGroupList, and a VisualStateGroup Landscape and `Portrait1
  5. In each group, add a VisualState, and in each state add a StateTrigger.
  6. For each state trigger, add OrientationStateTrigger and set the Orientation respectively (e.g. Portrait and Landscape
  7. Add a setter for each state to any property of the target type
  8. Optionally, add an IsActiveChanged state trigger and an appropriate event handler
  9. Apply the style to an element of the target type
  10. Run the app on iPhone or Android (phone or tablet)
  11. Rotate the device, see expected behaviour
  12. Run the app on iPad
  13. Rotate the device, observe the bug 馃悶

Link to public reproduction project repository

https://github.com/matt-goldman/OrientationTest

Version with bug

8.0.6

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

iOS 17

Did you find any workaround?

I had some moderate success using the OnOrientation extension by @F-Goncalves (see: https://www.cayas.de/en/blog/responsive-layouts-for-dotnet-maui). But I can't get it working well, and it only works when the app launches in landscape. See branch onorientation-extension on the linked repo.

Relevant log output

No response

@matt-goldman matt-goldman added the t/bug Something isn't working label Feb 10, 2024
@matt-goldman
Copy link
Contributor Author

More info - I think this might be expected behaviour (if this is right, I think it needs to be documented). On iPadOS (which is different now from iOS), the orientation state is not triggered on device rotation, because iPad supports multitasking through split view and slideover and which means the orientation of the device many not reflect the orientation of the window.

I've seen some people mention a workaround by setting UIRequiresFullscreen to true in Info.plist, but this didn't work for me.

I did get a successful workaround by adding an event handler to SizeChanged. then I can compare height and width, or even get the orientation from DeviceDisplay.MainDisplayInfo.Orientation and then I can manually set the visual state (rather than using the trigger). This works well.

The DeviceDisplay.MainDisplayInfoChanged does fire when the device is rotated, but it does not fire when the app starts. So you could use this as the event to trigger layout changes, but you would need to set the initial state too. Simply using LayoutChanged or SizeChanged is probably simpler as these fire when the view is initialised, so can be used to set both your initial state and respond to orientation changes. This explains what I was seeing with OnOrientation extension.

You can see this approach in my repo on the test-set-fullscreen branch.

I'm not sure how people view this - I don't think this counts as a bug, but I do think this is something that needs to be mentioned in the documentation. I'll open a PR for the docs and write up some notes about this in a blog post in the meantime.

@PureWeen
Copy link
Member

@jfversluis what do you think?

@jfversluis
Copy link
Member

@matt-goldman yeah I agree. Thanks for uncovering this! I think a note in the official docs might be worth it here and then obviously feel free to write up a blog or something with more context and that people will find in the search results when hitting this.

If you're willing to open a PR (maybe first an issue?) on the docs repo that would be amazing!

@davidbritch fyi

Closing this here for now.

@jfversluis jfversluis closed this as not planned Won't fix, can't repro, duplicate, stale Feb 12, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Mar 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
platform/iOS 馃崕 t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants