Skip to content

[iOS] Fix OrientationStateTrigger updates on iOS 27 - #39709

Merged
kubaflo merged 4 commits into
dotnet:inflight/candidatefrom
sheiksyedm:sheiksyedm-sandbox-issue-39693
Oct 27, 2026
Merged

kubaflo merged 4 commits into
dotnet:inflight/candidatefrom
sheiksyedm:sheiksyedm-sandbox-issue-39693

Conversation

@sheiksyedm

Copy link
Copy Markdown
Contributor

Note

Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!

Issue details

On iOS 27, OrientationStateTrigger does not update when the device rotates. In the reported example, a Grid uses visual states to change its background color and row/column definitions:

  • Portrait: green background, three rows, and one column.
  • Landscape: black background, two rows, and two columns.

After rotating to landscape, the Grid remains in its portrait state. The issue was reported against MAUI 10.0.120 and reproduced using this checkout's framework sources in Sandbox on an iPhone 18 Pro simulator running iOS 27.0 with Xcode 27.1.

Root cause

The iOS DeviceDisplay implementation reads UIApplication.StatusBarOrientation and subscribes to DidChangeStatusBarOrientationNotification. On the reproduced iOS 27 configuration, these deprecated APIs no longer provide the expected orientation value or change notifications.

Consequently, DeviceDisplay continues reporting Portrait with an unknown rotation, and OrientationStateTrigger does not activate the landscape visual state even though the native window scene has rotated.

Fix description

For iOS 27 and later:

  • Read interface orientation from the current window scene's EffectiveGeometry.
  • Observe UIDevice.OrientationDidChangeNotification and enable device-orientation notification generation while display listeners are active.
  • Queue the display-information refresh on the main thread so the scene can apply its updated orientation.
  • Stop generating notifications and dispose the observer when listeners are removed.

The existing paths for earlier iOS versions and Mac Catalyst remain unchanged. No public API changes are introduced.

Issues Fixed

Fixes #39693

kubaflo and others added 3 commits October 27, 2026 10:43
…he gallery (dotnet#39621)

<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->

### Description of Change

<!-- Enter description of the fix in this section -->

Extend the existing MacCatalyst startup-page resolver to Android, iOS,
and Windows, and wire it into `_IssuesUITest` / `_GalleryUITest` so
fixtures and resets can launch directly to their issue or gallery page
instead of searching and tapping through the gallery.

- **Android, iOS, MacCatalyst:** direct fixture launch is enabled by
default. Driver sessions remain reusable; each fixture receives its own
startup target. Reset/retry paths retain the current target, and
teardown closes the app instead of launching an unused gallery. Gallery
subpage selection still runs after launch; the current Android CoreCLR
ShellSearch setup failure remains under investigation.
- **Windows:** startup arguments and fixture integration are
implemented, but direct fixture launch is **opt-in** with
`MAUI_UITEST_DIRECT_LAUNCH=true`. WinAppDriver cannot change
`appArguments` on an existing session, so changing targets requires a
new session. Keep the existing navigation default until native timing
proves this is a benefit.
- Set `MAUI_UITEST_DIRECT_LAUNCH=false` to compare legacy navigation.
Normal launches and missing/empty/unknown startup targets still open the
gallery; unknown targets emit a debug diagnostic.
- Preserve the internet-required issue check through the shared page
factory. Forward the configured Android UDID to Appium and escape launch
arguments.
- Starting a new Apple test target and resetting the app stop explicitly
when closing fails. **Correction in `10e3dc7d710`:** OS-command
fallbacks no longer return success for a missing process, timeout, or
nonzero exit code; redirected output is drained and failures are logged.
Reset checks the close result before relaunching. This closes the
reproduced gap where a failed `simctl terminate` command was incorrectly
reported as success.
- Add startup/lifecycle utility tests to the solution and Helix
unit-project list, plus cross-platform fixture/reset coverage. The
regression page records how many application windows existed during
construction: `0` demonstrates initial-page creation, while the legacy
gallery-navigation control observes `1`.

Manual startup examples (exact issue description or gallery title,
case-insensitive):

```bash
adb shell am start -S -n com.microsoft.maui.uitests/com.microsoft.maui.uitests.MainActivity --es test '"Direct test launch"'
SIMCTL_CHILD_test="Direct test launch" xcrun simctl launch --terminate-running-process <simulator-udid> com.microsoft.maui.uitests
```

```powershell
.\Controls.TestCases.HostApp.exe '--test=Direct test launch'
```

MacCatalyst continues using the app process's `test` environment
variable. Startup arguments are consumed during initial-window creation;
do not merely foreground an already-running process when changing
targets. This extends dotnet#31673's resolver rather than adding a competing
one.

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes dotnet#32463

<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->

### Validation

#### Termination-fallback correction

- `dotnet test
src/TestUtils/tests/UITest.Appium.Tests/UITest.Appium.Tests.csproj
--filter
'FullyQualifiedName~FailedSimulatorFallbackCannotLaunchWithStaleStartupArguments'
-v:minimal` — **both new cases failed before the fix** with the intended
missing-exception assertion. They use a recording driver that rejects
termination and a real `simctl` command with an invalid simulator ID; no
simulator app or host UI is controlled.
- `dotnet test
src/TestUtils/tests/UITest.Appium.Tests/UITest.Appium.Tests.csproj
--no-restore -v:minimal` — **22 passed after the fix**. Includes the
original 19 utility tests, the two launch/reset regressions, and a
direct force-close response regression.
- `dotnet test
src/TestUtils/tests/UITest.Appium.Tests/UITest.Appium.Tests.csproj
--no-build -v:q` — **22 passed in each of two additional fresh test
processes**.

These utility tests establish the corrected fallback behavior, not
native Appium reliability or resolution of the outstanding UI failures.

#### Earlier implementation validation

The following checks were performed during the initial implementation,
before the later rebase onto `4781afbd`. They were **not rerun as native
certification of `10e3dc7d710`**.

Initial iOS validation used an isolated iPhone 11 Pro on iOS 26.5 with
`simctl` launches, screenshots, and local Vision OCR: all six startup
scenarios passed 3/3 (18 checks). Subsequently, with explicit permission
for simulator-only XCTest/WebDriverAgent,
`DEVICE_UDID=5668A696-15E3-41E8-884C-7D06EB167B07 dotnet test
src/Controls/tests/TestCases.iOS.Tests/Controls.TestCases.iOS.Tests.csproj
--no-build --filter 'FullyQualifiedName~Issue32463Runner'` ran the
actual fixture: **2 passed**, covering direct startup and
tap/increment/reset. No host macOS UI automation was used. This does not
clear the current Stepper failures.

- `dotnet build ./Microsoft.Maui.BuildTasks.slnf -v:q` — passed.
- `dotnet build
src/Controls/tests/TestCases.HostApp/Controls.TestCases.HostApp.csproj
-f net10.0-ios -p:RuntimeIdentifier=iossimulator-arm64 -v:q` — passed;
installed and locally validated as above using normal simulator signing.
- `dotnet build
src/Controls/tests/TestCases.HostApp/Controls.TestCases.HostApp.csproj
-f net10.0-android -p:EmbedAssembliesIntoApk=true -v:q` — passed;
installed on an isolated headless API 34 emulator.
- `dotnet build
src/Controls/tests/TestCases.HostApp/Controls.TestCases.HostApp.csproj
-f net10.0-maccatalyst -p:RuntimeIdentifier=maccatalyst-arm64 -v:q` —
passed; host UI automation was not run.
- `DEVICE_UDID=emulator-5556 dotnet test
src/Controls/tests/TestCases.Android.Tests/Controls.TestCases.Android.Tests.csproj
--no-restore --filter
'FullyQualifiedName~Issue32463|FullyQualifiedName~Issue10222Test|FullyQualifiedName~VerifyButton_CommandAndCommandParameter'`
— **15 passed**, including existing issue/gallery fixtures, per-test
resets, and the legacy-navigation control.
- `dotnet build
src/Controls/tests/TestCases.iOS.Tests/Controls.TestCases.iOS.Tests.csproj
-v:q` — passed.
- `dotnet build
src/Controls/tests/TestCases.Mac.Tests/Controls.TestCases.Mac.Tests.csproj
-v:q` — passed.
- `dotnet build
src/Controls/tests/TestCases.WinUI.Tests/Controls.TestCases.WinUI.Tests.csproj
-v:q` — passed. Windows native execution was not performed locally on
this macOS machine.
- `dotnet msbuild eng/helix.proj -getItem:XUnitProject -nologo` —
passed; includes the utility test project.

Earlier controlled runner verification:

```powershell
$env:AdbTarget = '-s emulator-5556'
$env:DEVICE_UDID = 'emulator-5556'
$DeviceUdid = 'emulator-5556'
& .github/skills/verify-tests-fail-without-fix/scripts/verify-tests-fail.ps1 -Platform android -TestType UITest -TestFilter 'FullyQualifiedName~Issue32463Runner' -FixFiles 'src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/_IssuesUITest.cs' -BaseBranch 0796941 -PRNumber 39621 -RequireFullVerification
```

**`VERIFICATION PASSED`**: legacy fixture setup failed the intended
window-count assertion (`expected 0, actual 1`); restored direct-launch
setup passed both selected tests. The original Android host verification
also failed its three direct-launch cases without the host fix and
passed all six with it. These earlier checks are not substitutes for the
current native CI matrix.

### Measured performance (limited local sample)

Three interleaved legacy/direct runs of the same two existing Android
fixtures (`Issue10222Test` and
`VerifyButton_CommandAndCommandParameter`), each with 2/2 tests passing.
Compared full `dotnet test --no-build` wall time, including fixture
setup, with `MAUI_UITEST_DIRECT_LAUNCH=false` versus `true`:

| Mode | Run 1 | Run 2 | Run 3 | Median |
|---|---:|---:|---:|---:|
| Legacy navigation | 20.938s | 20.514s | 20.819s | 20.819s |
| Direct startup | 16.237s | 23.551s | 15.575s | 16.237s |

The median was **22.0% lower** in this sample; one direct run was
slower. This is not a suite-wide estimate or a claim of an iOS/Windows
speedup.

### CI observation and remaining gaps

**This PR is not runtime-green.** The following terminal builds tested
the preceding head `f09f1302a01` through merge `e00a7f22` on base
`4781afbd`; they do not validate the new termination correction.

- [Main validation
1649162](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1649162)
failed in Windows Debug: `MSB4024` while reading generated
`.buildtasks/Microsoft.Maui.Core.props`, which another process held
open. The exact-base main build passed, but that is not causal proof.
This failure is **not** the old `WMC0612` XAML error from the initial
implementation.
- [UI validation
1649164](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1649164)
failed. Its 85 failed result occurrences represent 73 distinct automated
test/platform names, not 85 independent defects. Thirty CoreCLR Android
ShellSearch outcomes share one fixture-setup timeout at
`_GalleryUITest.FixtureSetup:58`. Five iOS Stepper assertions persist.
Other assertion, timeout, app-not-running, and visual failures remain
unresolved; neither passing utility tests nor isolated passing native
cases clear them.
- Windows ShellSearch has same-base peer-failure observations, while
other Windows visuals have passing same-base cross-PR controls. Those
are observations, not proof of PR causality or clearance. Some Catalyst
Entry visual signatures also occur on main; remaining failures must not
be dismissed as unrelated.
- [Device validation
1649165](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1649165)
succeeded, using a different harness. It does not certify Appium fixture
lifecycle correctness.

A same-lane direct-launch-disabled control for the CoreCLR ShellSearch
failure has **not yet been performed**. Its source-bound artifact
confirms the requested startup target was sent, but diagnostics do not
establish why setup timed out. No assertions, screenshot goldens,
tolerances, or skips were changed to mask these failures.

---------

Copilot-Session: cdc98af7-0509-443d-8a84-cc75ecbc1a1e
Updated
[Microsoft.AspNetCore.Authentication.Facebook](https://github.com/dotnet/dotnet)
from 10.0.13 to 10.0.14.

<details>
<summary>Release notes</summary>

_Sourced from [Microsoft.AspNetCore.Authentication.Facebook's
releases](https://github.com/dotnet/dotnet/releases)._

No release notes found for this version range.

Commits viewable in [compare
view](https://github.com/dotnet/dotnet/commits).
</details>

Updated
[Microsoft.AspNetCore.Authentication.Google](https://github.com/dotnet/dotnet)
from 10.0.13 to 10.0.14.

<details>
<summary>Release notes</summary>

_Sourced from [Microsoft.AspNetCore.Authentication.Google's
releases](https://github.com/dotnet/dotnet/releases)._

No release notes found for this version range.

Commits viewable in [compare
view](https://github.com/dotnet/dotnet/commits).
</details>

Updated
[Microsoft.AspNetCore.Authentication.MicrosoftAccount](https://github.com/dotnet/dotnet)
from 10.0.13 to 10.0.14.

<details>
<summary>Release notes</summary>

_Sourced from [Microsoft.AspNetCore.Authentication.MicrosoftAccount's
releases](https://github.com/dotnet/dotnet/releases)._

No release notes found for this version range.

Commits viewable in [compare
view](https://github.com/dotnet/dotnet/commits).
</details>

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore <dependency name> major version` will close this
group update PR and stop Dependabot creating any more for the specific
dependency's major version (unless you unignore this specific
dependency's major version or upgrade to it yourself)
- `@dependabot ignore <dependency name> minor version` will close this
group update PR and stop Dependabot creating any more for the specific
dependency's minor version (unless you unignore this specific
dependency's minor version or upgrade to it yourself)
- `@dependabot ignore <dependency name>` will close this group update PR
and stop Dependabot creating any more for the specific dependency
(unless you unignore this specific dependency or upgrade to it yourself)
- `@dependabot unignore <dependency name>` will remove all of the ignore
conditions of the specified dependency
- `@dependabot unignore <dependency name> <ignore condition>` will
remove the ignore condition of the specified dependency and ignore
conditions


</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
Read orientation from window-scene geometry and refresh display information on device orientation changes on iOS 27, where the deprecated status-bar APIs no longer update. Preserve the existing behavior on earlier iOS versions and Mac Catalyst.

Add regression coverage for portrait and landscape visual states, background colors, and grid definitions.

Fixes dotnet#39693
Copilot AI balanced review requested due to automatic review settings October 27, 2026 16:25
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 39709

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 39709"

@dotnet-policy-service dotnet-policy-service Bot added the partner/syncfusion Issues / PR's with Syncfusion collaboration label Oct 27, 2026
@azure-pipelines

This comment has been minimized.

@sheiksyedm sheiksyedm added community ✨ Community Contribution platform/ios version/ios-27 area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info labels Oct 27, 2026
@github-actions github-actions Bot added the platform/macos macOS / Mac Catalyst label Oct 27, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Orientation reporting remains incorrect for non-scene hosts and misses interface rotations without physical device movement.

2 open issues
What changed in this PR

This PR addresses #39693 by updating iOS 27 orientation reporting in Essentials, which supplies the display information used by OrientationStateTrigger.

Changes:

  • Reads orientation from window-scene geometry on iOS 27, preserving earlier iOS and Mac Catalyst paths.
  • Adds device-orientation notifications with deferred refresh and listener cleanup.
  • Adds an iOS regression test checking grid colors and definitions across portrait and landscape transitions.
File Description
src/​Essentials/​src/​DeviceDisplay/​DeviceDisplay.ios.cs Adds iOS 27 orientation reads and notification handling.
src/​Controls/​tests/​TestCases.Shared.Tests/​Tests/​Issues/​Issue39693.cs Tests visual-state updates across orientation changes.
src/​Controls/​tests/​TestCases.HostApp/​Issues/​Issue39693.xaml.cs Exposes grid state through an automation-readable status label.
src/​Controls/​tests/​TestCases.HostApp/​Issues/​Issue39693.xaml Defines portrait and landscape grid states reproducing the issue.

Review effort: Balanced

Comment on lines +171 to +172
observer = notificationCenter.AddObserver(UIDevice.OrientationDidChangeNotification,
_ => UIApplication.SharedApplication.BeginInvokeOnMainThread(OnMainDisplayInfoChanged));
Comment on lines +202 to +203
return WindowStateManager.Default.GetCurrentUIWindow()?.WindowScene?.EffectiveGeometry.InterfaceOrientation
?? UIInterfaceOrientation.Unknown;
@kubaflo
kubaflo changed the base branch from main to inflight/candidate October 27, 2026 16:54
@kubaflo

This comment has been minimized.

@kubaflo

This comment has been minimized.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines will not run the associated pipelines, because the pull request was updated after the run command was issued. Review the pull request again and issue a new run command.

@github-actions github-actions Bot added the s/agent-review-in-progress AI review is currently running for this PR label Oct 27, 2026
Preserve scene-based interface orientation and deferred notifications on iOS 27 while retaining upstream device-orientation behavior on earlier versions and MacCatalyst.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@kubaflo

kubaflo commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Resolved and pushed the conflict with inflight/candidate in ordinary merge commit fdce995c906, on the original sheiksyedm-sandbox-issue-39693 branch.

The sole conflict was DeviceDisplay.ios.cs, overlapping the PR's iOS 27 fix with upstream's switch to device-orientation notifications/calculation. Kept the PR's queued notification read and scene EffectiveGeometry.InterfaceOrientation on iOS 27, including its notification generation cleanup. Earlier iOS versions and MacCatalyst retain the target branch's device-orientation calculations and rotation mapping; unknown orientation remains unknown. The PR's orientation regression-test/page files are unchanged.

Validation: 19 selected managed DeviceDisplay/DisplayInfo tests passed with explicit DOTNET_ROLL_FORWARD=Major because the repo-local SDK has only the .NET 11 runtime. Scoped source formatting and git diff --check passed. Native iOS compilation was attempted but blocked by NETSDK1147 (missing iOS workload); the managed tests do not compile or exercise the UIKit-specific implementation. Actual iOS 27 rotation/OrientationStateTrigger behavior and native Apple builds remain for CI. No native device/UI automation or XCTest was run.

@MauiBot

MauiBot commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator

PR Test Gate

@sheiksyedm — existing-test verification; Setup did not capture a tested commit.

Result INCONCLUSIVE Platform iOS


🧪 Gate analysis — click to expand

⚠ Inconclusive. The PR could not be merged with its target branch; no tests ran.

No interpretable test-group summary was produced. No additional test execution is inferred.

Setup did not capture a verified PR head; no commit is claimed as tested.

No immutable without-fix baseline was prepared.

@MauiBot MauiBot removed the s/agent-review-in-progress AI review is currently running for this PR label Oct 27, 2026
@kubaflo
kubaflo merged commit 24ee12d into dotnet:inflight/candidate Oct 27, 2026
2 of 12 checks passed
@github-actions github-actions Bot added this to the .NET 10 SR13 milestone Oct 27, 2026
github-actions Bot pushed a commit that referenced this pull request Oct 28, 2026
<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

<!--
!!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING
MAIN. !!!!!!!
-->



### Issue details

On iOS 27, OrientationStateTrigger does not update when the device
rotates. In the reported example, a Grid uses visual states to change
its background color and row/column definitions:

- Portrait: green background, three rows, and one column.
- Landscape: black background, two rows, and two columns.

After rotating to landscape, the Grid remains in its portrait state. The
issue was reported against MAUI 10.0.120 and reproduced using this
checkout's framework sources in Sandbox on an iPhone 18 Pro simulator
running iOS 27.0 with Xcode 27.1.

### Root cause

The iOS DeviceDisplay implementation reads
UIApplication.StatusBarOrientation and subscribes to
DidChangeStatusBarOrientationNotification. On the reproduced iOS 27
configuration, these deprecated APIs no longer provide the expected
orientation value or change notifications.

Consequently, DeviceDisplay continues reporting Portrait with an unknown
rotation, and OrientationStateTrigger does not activate the landscape
visual state even though the native window scene has rotated.

### Fix description

For iOS 27 and later:

- Read interface orientation from the current window scene's
EffectiveGeometry.
- Observe UIDevice.OrientationDidChangeNotification and enable
device-orientation notification generation while display listeners are
active.
- Queue the display-information refresh on the main thread so the scene
can apply its updated orientation.
- Stop generating notifications and dispose the observer when listeners
are removed.

The existing paths for earlier iOS versions and Mac Catalyst remain
unchanged. No public API changes are introduced.



### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Fixes #39693

<!--
Are you targeting main? All PRs should target the main branch unless
otherwise noted.
-->

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 27, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration platform/ios platform/macos macOS / Mac Catalyst version/ios-27

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OrientationStateTriggers are broken with iOS 27

4 participants