Repository navigation
[Android] Fix ShellRenderer blank content when navigating from a modal - #40295
Conversation
… content (dotnet#40169) <!-- Open .NET 11 fix PRs against net11 for review; target main for next-major features. After approval, a maintainer manually retargets the fix PR to the active inflight branch and merges it directly there. Do not merge individual fixes into net11. Bots must not retarget or merge. Candidate integration into net11 and release/* changes are separate, explicitly coordinated release work. --> ### Target Branch | This PR is for | Initial base | | --- | --- | | New features, API changes, or .NET 12 work (including .NET 12 fixes) | `main` | | .NET 11 servicing fixes | `net11`, for review | | Older servicing, release integration, infrastructure, or documentation | The branch designated for that work | - [ ] I selected the applicable base branch using the [contribution guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting). For .NET 11 fixes, only a maintainer retargets the approved PR to the active inflight lane and merges it after CI validates that final base. Do not merge individual fixes directly into `net11`; agents must not retarget or merge. ### Issue Description On Android 16, switching between Entries with different keyboard types can briefly display the previous keyboard layout before showing the correct one, causing visible flickering. In the reproduction, each Entry is dynamically added to a ContentView and replaced with a Label when another cell is selected. ### Root Cause RemoveAllViews() detached the focused native EditText without explicitly clearing its focus. Removing a view is not the same as completing a focus transition. Android updates the keyboard through its input-method system asynchronously. If the outgoing text field is still considered the active input target, the keyboard can temporarily retain its configuration while Android processes detachment, transfers focus, and establishes the incoming Entry’s input connection. ### Description of Change - Clear native focus from the outgoing ContentView content before calling RemoveAllViews() on Android. - Previously, removing content containing a focused Entry could leave stale input-method state. When switching between Entries with different keyboard types, the previous keyboard layout could briefly appear before the correct layout. - Explicitly clearing focus before removing the native view ensures that the outgoing Entry relinquishes focus before the next Entry is attached and focused. ### Issues Fixed Fixes dotnet#38799 ### Tested the behaviour in the following platforms - [x] Android - [ ] Windows - [ ] iOS - [ ] Mac ### Output Screenshot Before Issue Fix | After Issue Fix | |----------|----------| |<video width="300" height="600" alt="Before Fix" src="https://github.com/user-attachments/assets/62b49b56-86e3-48e8-9ae1-19e92106f5b0">|<video width="100" height="100" alt="After Fix" src="https://github.com/user-attachments/assets/55caabe9-2021-43c0-9407-31bbad08db4c">| Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
…et#40175) <!-- Open .NET 11 fix PRs against net11 for review; target main for next-major features. After approval, a maintainer manually retargets the fix PR to the active inflight branch and merges it directly there. Do not merge individual fixes into net11. Bots must not retarget or merge. Candidate integration into net11 and release/* changes are separate, explicitly coordinated release work. --> ### Target Branch | This PR is for | Initial base | | --- | --- | | New features, API changes, or .NET 12 work (including .NET 12 fixes) | `main` | | .NET 11 servicing fixes | `net11`, for review | | Older servicing, release integration, infrastructure, or documentation | The branch designated for that work | - [ ] I selected the applicable base branch using the [contribution guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting). For .NET 11 fixes, only a maintainer retargets the approved PR to the active inflight lane and merges it after CI validates that final base. Do not merge individual fixes directly into `net11`; agents must not retarget or merge. ### Description of Change This pull request primarily improves shadow rendering support for Win2D-based shapes on Windows and updates test conditions related to shadow features. The most significant changes are the addition of logic to handle `W2DGraphicsView` with `ShapeDrawable` in shadow rendering, as well as updates to test preprocessor directives and references. **Shadow rendering improvements:** * [`ShadowExtensions.cs`](diffhunk://#diff-6c904999b229ffd792f069a6a0ddaf850a67a046624c4e915b57ece230ca9a09R43-R51): Added logic in `GetAlphaMaskAsync` to handle `W2DGraphicsView` with `ShapeDrawable`, using the live visual for shadow rendering since `RenderTargetBitmap` cannot capture Win2D content. * [`ShadowExtensions.cs`](diffhunk://#diff-6c904999b229ffd792f069a6a0ddaf850a67a046624c4e915b57ece230ca9a09R7): Added necessary using directives for `Microsoft.Maui.Graphics.Win2D` and aliased `ShapeDrawable` for clarity. [[1]](diffhunk://#diff-6c904999b229ffd792f069a6a0ddaf850a67a046624c4e915b57ece230ca9a09R7) [[2]](diffhunk://#diff-6c904999b229ffd792f069a6a0ddaf850a67a046624c4e915b57ece230ca9a09R16) **Test updates:** * [`ShadowFeatureTests.cs`](diffhunk://#diff-560f9cb1cec21af3a1c6ae51a0b30849aea0f019d519990a0b24dba91971d67fL218-R218): Updated the Windows shadow test exclusion to reference the correct GitHub issue (`40172` instead of `27732`). * [`BoxViewFeatureTests.cs`](diffhunk://#diff-3455b54055dcfe7c51234f9e7cc13af77da827ea7b097f7fe77d44acad4b0f79L163): Removed the preprocessor directive that disabled shadow tests on Windows, re-enabling those tests. [[1]](diffhunk://#diff-3455b54055dcfe7c51234f9e7cc13af77da827ea7b097f7fe77d44acad4b0f79L163) [[2]](diffhunk://#diff-3455b54055dcfe7c51234f9e7cc13af77da827ea7b097f7fe77d44acad4b0f79L235) <!-- Enter description of the fix in this section --> ### 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#31821 ### Tested the behavior in the following platforms - [x] Windows - [ ] Android - [ ] iOS - [ ] Mac | Before Issue Fix | After Issue Fix | |----------|----------| | <img width="998" height="944" alt="BeforeFix1821" src="https://github.com/user-attachments/assets/b4a526d3-a615-4fea-9ede-55129e23314e" /> | <img width="1259" height="952" alt="AfterFix31821" src="https://github.com/user-attachments/assets/17282ba8-85cb-48a0-814b-beac7642c7b6" /> | <!-- Verify the target branch follows the release workflow in docs/ReleaseBranchWorkflow.md. Infrastructure and documentation changes should target the branch where they apply. --> Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
) <!-- 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! <!-- Open .NET 11 fix PRs against net11 for review; target main for next-major features. After approval, a maintainer manually retargets the fix PR to the active inflight branch and merges it directly there. Do not merge individual fixes into net11. Bots must not retarget or merge. Candidate integration into net11 and release/* changes are separate, explicitly coordinated release work. --> ### Target Branch | This PR is for | Initial base | | --- | --- | | New features, API changes, or .NET 12 work (including .NET 12 fixes) | `main` | | .NET 11 servicing fixes | `net11`, for review | | Older servicing, release integration, infrastructure, or documentation | The branch designated for that work | - [x] I selected the applicable base branch using the [contribution guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting). For .NET 11 fixes, only a maintainer retargets the approved PR to the active inflight lane and merges it after CI validates that final base. Do not merge individual fixes directly into `net11`; agents must not retarget or merge. ### Description of Change Most of the recent `net11` `maui-pr-uitests` red comes from Android API 30 jobs that are cancelled at the 240-minute job limit. The cause is a lost emulator, not product regressions. **What happens** (raw logs of build [1680926](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1680926) and [1680462](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1680462), e.g. API 30 Navigation and API 30 CollectionView3): 1. The emulator boots normally, and tests run for about 9–12 minutes. 2. `[Logcat] Logcat terminated with code 255` appears and adb reports `device 'emulator-5554' not found`. The emulator is gone. 3. The remaining fixtures of attempt 1 fail quickly once session recreation fails. 4. `RunUITestsWithRetry` starts **UI test attempt 2** against the still-missing device. Every fixture now waits about 3.7 minutes in `AppiumServerContext.CreateUIClientContext`: 11 tries × Appium's 20-second "Could not find a connected Android device". 5. The job runs until Azure DevOps cancels it at 240 minutes. Most of the failed rows in those builds are these setup failures. The same tests pass on `candidate/11.0.1xx-sr2`, and none of `eng/devices`, `UITest.Appium` or `UITest.NUnit` differs between `net11`, the candidate and `main`. So this is an infrastructure flake that the retry path amplifies, with no existing fix to backport. **Fix** - `RunUITestsWithRetry` gets an optional `beforeAttempt` hook that runs before **every** attempt, including attempt 1. The iOS, Mac Catalyst and Windows callers are unchanged. - Running it only before retries was not enough. In this PR's run [1682445](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1682445), three API 30 jobs installed the app and then lost the emulator during the roughly 2-minute UI-test project build, before attempt 1. Every fixture in attempt 1 then waited 3 min 40 s (Shell1: 68 fixtures, CarouselView: 99, 0 passed), and the jobs were cancelled at 240 minutes before the retry hook could run. - On Android, the hook checks `sys.boot_completed`: - If the device is healthy, it does nothing (one `getprop`). - If the emulator started by the script is gone, it cleans up, restarts the emulator through the existing `HandleVirtualDevice` path, and reinstalls the app with `ExecutePrepareUITests` before the attempt. - If that cleanup throws (for example `AdbEmuKill` fails), the hook kills the old emulator process directly before restarting, so the same AVD is never started twice. In a local fault-injection check, the previous code left the old PID alive, started a duplicate, and timed out after about 10 minutes; with this fallback, recovery finished in 39 s. - Before restarting, the hook waits (bounded by `EmulatorKillTimeoutSeconds`) until the old process has **confirmed exited**. If it hasn't, the hook fails the attempt rather than start a duplicate instance of the same AVD. - If the device was not started by the script, it logs a warning and runs the tests as before. Local runs against a user-supplied device are unchanged. - `uitest-retry.cake`: a retry no longer leaves never-run ignored tests as failures. When the device is lost during a fixture's OneTimeSetUp, NUnit fails every child with `site="Parent"`. If OneTimeTearDown also throws, the fixture site becomes `TearDown` instead of `SetUp`. Ignored tests then come back from a green retry as Skipped/Ignored: either a static `[Ignore]` with the same reason, or a runtime `Assert.Ignore` with `runstate="Runnable"`. The merge accepted only the `SetUp`+static-reason shape, so the job failed even though the retry was green. - The merge now treats a parent-site error as never-run when the fixture failed in setup (site `SetUp`, or the child's message starts with `OneTimeSetUp:`). It accepts a retry that ignores such a test, and accepts fixtures that contain only such recovered ignores. A test that actually ran and failed is still never accepted. **Validation** - `dotnet cake eng/devices/{android,catalyst,windows,ios}.cake --target=uitest --dryrun` compiles. iOS has the same pre-existing local teardown error with and without this change. - Local end-to-end check on an API 30 arm64 emulator (adb pinned to `emulator-5554`): a temporary target ran the real `connectToDevice` and `uitest-prepare` (installed the app), then called `EnsureDeviceForUITestAttempt` as at the attempt-1 call site. | Case | Result | | --- | --- | | Healthy device | Hook returned in 0.0 s (no-op) | | `adb emu kill` after install (the 1682445 mode) | `boot_completed` → null; hook logged the warning, restarted the emulator, and reinstalled the app (XHarness exit code 0) in 46 s; afterwards `boot_completed` = 1 and `pm path` showed the app | | Healthy again after recovery | 0.0 s no-op | | Missing device not started by the script | Warning logged, no throw | - Confirmed-exit fault injection (local, API 30): | Scenario | Before | After | | --- | --- | --- | | Cleanup returns but the emulator stays alive | Duplicate start; boot timed out after 10m32s | Attempt fails after 60 s with "did not exit … not restarting"; no duplicate | | Emulator killed externally | — | One restart, app reinstalled, XHarness exit 0 (49 s) | | Cleanup throws | — | Direct kill, one restart, XHarness exit 0 (41 s) | - **CI proof of recovery:** in this PR's run [1682664](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1682664), Controls (API 30) Label lost the emulator during attempt 1. All 126 tests failed in OneTimeSetUp, about 3m40s each. Before attempt 2 the hook restarted Emulator_30 and reinstalled the app, and **attempt 2 passed 124 tests with 2 skipped** in 14 minutes. - **Retry merge:** that job was still marked failed because two never-run ignored tests stayed Failed: `Issue488TestsLongTextRotation` (static `[Ignore]`, fixture site `TearDown`) and `LabelUITests.IsEnabled` (runtime `Assert.Ignore`). The real TRX and NUnit XML from both attempts were replayed offline through `UITestRetry.MergeResults`: | Input | Before | After | | --- | --- | --- | | Real 1682664 Label artifacts | Merged outcome Failed (`IsEnabled`, `Issue488TestsLongTextRotation`) | Completed, 0 failed, no run errors | | Retry `IsEnabled` actually fails | — | Failed | | Original `IsEnabled` actually ran (site not Parent) | — | Failed | | Static ignore reason mismatch | — | Failed | | No `OneTimeSetUp:` evidence | — | Failed | The replay harness was local only; no test was committed, per policy for CI scripts. - Final validation is this PR's own `maui-pr-uitests` run. ### Issues Fixed Fixes Android API 30 `maui-pr-uitests` jobs on `net11` hanging until the 240-minute timeout after the emulator is lost mid-run. Also fixes recovered retries still failing the job when never-run ignored tests come back as Skipped/Ignored. --------- Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 40295Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 40295" |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
/rebase |
7563115 to
8c99c83
Compare
PR Test Gate
🧪 Gate analysis — click to expand⚠ Inconclusive. Setup, build, or execution did not produce a conclusive result. This does not prove the fix is incorrect. 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. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
PR Test Gate
🧪 Gate analysis — click to expand⚠ Inconclusive. Setup, build, or execution did not produce a conclusive result. This does not prove the fix is incorrect. 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. |
There was a problem hiding this comment.
Expert Review — 0 findings
Reviewed commit 5e93264.
This comment has been minimized.
This comment has been minimized.
PR Test Gate
🧪 Gate analysis — click to expand⚠ Inconclusive. Setup, build, or execution did not produce a conclusive result. This does not prove the fix is incorrect. 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. |
There was a problem hiding this comment.
Expert Review — 0 findings
Reviewed commit 5e93264.
This comment has been minimized.
This comment has been minimized.
PR Test Gate
🧪 Gate analysis — click to expand⚠ Inconclusive. Setup, build, or execution did not produce a conclusive result. This does not prove the fix is incorrect. 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. |
There was a problem hiding this comment.
Expert Review — 0 findings
Reviewed commit 5e93264.
eb20e49
into
dotnet:candidate/11.0.1xx-sr2
#40295) <!-- 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! ### Root cause During Shell-item opening transitions, temporary ancestor transforms can cause safe-area padding to be calculated from transient screen coordinates. The padding can remain incorrect after the transition finishes, leaving top-aligned destination content underneath the status bar. ### Description of Change Register a private fragment-lifecycle callback in Android ShellRenderer to request fresh window insets when the current Shell-item fragment resumes. Filter out unrelated fragments and unregister/dispose the callback when the renderer disconnects. Add a TODO to move the refresh to ShellItemRenderer.OnResume in .NET 12. Add renderer-specific tests covering modal-to-ShellItem/TabBar navigation, custom item renderers, repeated resume without another transition, and centered-content positioning. ### Issues Fixed Fixes #35759 ### Screenshots | Before | After | |---------|--------| | <video src="https://github.com/user-attachments/assets/fa8bfc77-4538-47bc-9ff9-4f2b200299ce" Width="600" Height="400"/> | <video src="https://github.com/user-attachments/assets/8640bc43-0183-4168-b8b0-cf8a17203fe2" Width="600" Height="400"/> | --------- Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
#40295) <!-- 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! ### Root cause During Shell-item opening transitions, temporary ancestor transforms can cause safe-area padding to be calculated from transient screen coordinates. The padding can remain incorrect after the transition finishes, leaving top-aligned destination content underneath the status bar. ### Description of Change Register a private fragment-lifecycle callback in Android ShellRenderer to request fresh window insets when the current Shell-item fragment resumes. Filter out unrelated fragments and unregister/dispose the callback when the renderer disconnects. Add a TODO to move the refresh to ShellItemRenderer.OnResume in .NET 12. Add renderer-specific tests covering modal-to-ShellItem/TabBar navigation, custom item renderers, repeated resume without another transition, and centered-content positioning. ### Issues Fixed Fixes #35759 ### Screenshots | Before | After | |---------|--------| | <video src="https://github.com/user-attachments/assets/fa8bfc77-4538-47bc-9ff9-4f2b200299ce" Width="600" Height="400"/> | <video src="https://github.com/user-attachments/assets/8640bc43-0183-4168-b8b0-cf8a17203fe2" Width="600" Height="400"/> | --------- Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
dotnet#40295) <!-- 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! ### Root cause During Shell-item opening transitions, temporary ancestor transforms can cause safe-area padding to be calculated from transient screen coordinates. The padding can remain incorrect after the transition finishes, leaving top-aligned destination content underneath the status bar. ### Description of Change Register a private fragment-lifecycle callback in Android ShellRenderer to request fresh window insets when the current Shell-item fragment resumes. Filter out unrelated fragments and unregister/dispose the callback when the renderer disconnects. Add a TODO to move the refresh to ShellItemRenderer.OnResume in .NET 12. Add renderer-specific tests covering modal-to-ShellItem/TabBar navigation, custom item renderers, repeated resume without another transition, and centered-content positioning. ### Issues Fixed Fixes dotnet#35759 ### Screenshots | Before | After | |---------|--------| | <video src="https://github.com/user-attachments/assets/fa8bfc77-4538-47bc-9ff9-4f2b200299ce" Width="600" Height="400"/> | <video src="https://github.com/user-attachments/assets/8640bc43-0183-4168-b8b0-cf8a17203fe2" Width="600" Height="400"/> | --------- Co-authored-by: Jakub Florkowski <kubaflo123@gmail.com>
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!
Root cause
During Shell-item opening transitions, temporary ancestor transforms can cause safe-area padding to be calculated from transient screen coordinates. The padding can remain incorrect after the transition finishes, leaving top-aligned destination content underneath the status bar.
Description of Change
Register a private fragment-lifecycle callback in Android ShellRenderer to request fresh window insets when the current Shell-item fragment resumes. Filter out unrelated fragments and unregister/dispose the callback when the renderer disconnects. Add a TODO to move the refresh to ShellItemRenderer.OnResume in .NET 12.
Add renderer-specific tests covering modal-to-ShellItem/TabBar navigation, custom item renderers, repeated resume without another transition, and centered-content positioning.
Issues Fixed
Fixes #35759
Screenshots
BeforeFix53.mov
AfterFix52.mov