Repository navigation
Conversation
…r/DragLeave (dotnet#40441) <!-- 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 On iOS, `DragEventArgs.GetPosition()` can throw a `NullReferenceException` inside a `DragOver` or `DragLeave` handler. The exception crashes the app. **CI evidence.** The `DropEventCoordinates` UI test crashed the HostApp on both attempts on the iOS CoreCLR lane of SR2 candidate dotnet#40116 (maui-pr-uitests [1690394](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1690394), iOS latest Editor..Fr job). The job's `.ips` reports show SIGABRT from `xamarin_process_managed_exception` under `-[UIDropInteraction _dragDestinationGestureStateChanged:]`. The logarchive shows the managed exception: ``` System.NullReferenceException at DragAndDropDelegate.CalculatePosition(IElement, WeakReference, WeakReference) at DragAndDropBetweenLayouts.OnDragOver(...) // HostApp calls e.GetPosition(...) at DragAndDropDelegate.<HandleDragOver>... at DragAndDropDelegate.SendEventArgs(...) at DragAndDropDelegate.HandleDragOver(...) at DragAndDropDelegate.SessionDidUpdate(...) ``` **Root cause.** - `SessionDidUpdate` and `SessionDidExit` pass `session.LocalDragSession`, a transient managed wrapper of the native local drag session, into `HandleDragOver` and `HandleDragLeave`. - Those methods put only a `WeakReference` to it in the `GetPosition` callback, and nothing else on the path keeps it alive: `PlatformDragEventArgs` holds the outer `IUIDropSession`, not the local drag session. - A GC while the user's handler is running can therefore collect the wrapper. `CalculatePosition` then calls `LocationInView` on a null session. - Separately, `HandleDragOver` built a weak reference even when `LocalDragSession` is null (a drag from another app), so `GetPosition` always threw in that case. `HandleDragLeave` and `HandleDrop` already return null there. The weak references date from 2023, and the code is identical on `net11`, the candidate and `main`. This is a latent bug that the CoreCLR lane's GC timing exposed, not a candidate regression. **Fix** (`DragAndDropDelegate.cs`, iOS/Mac Catalyst): - `HandleDragOver` and `HandleDragLeave` call `GC.KeepAlive(session)` after dispatching to the recognizers. The session stays alive while handlers can synchronously call `GetPosition`, and the event args still don't hold it strongly. - `HandleDragOver` uses a null `sessionRef` when there is no local drag session, matching `HandleDragLeave` and `HandleDrop`. - `CalculatePosition` returns `null` when the session reference is missing or its target has already been collected, instead of dereferencing null. This covers a `GetPosition` call made after the handler returns. **Tests** (`DragAndDropTests.iOS.cs`, `Gesture` category): - `DragPositionIsAvailableAfterGarbageCollectionDuringHandler(dragLeave: false/true)`: a fake drop session returns a fresh local drag session wrapper each time, the handler forces a full GC and then calls `GetPosition`, and the test asserts the fake session's location. - `DragOverPositionIsNullWithoutLocalDragSession`: with no local drag session, `GetPosition` in `DragOver` returns `null`. **Validation** (iOS 18.5 simulator, Release, CoreCLR, the same runtime as the failing CI lane): | Command | Result | | --- | --- | | `pwsh .github/skills/run-device-tests/scripts/Run-DeviceTests.ps1 -Project Controls -Platform ios -TestFilter "Category=Gesture" -DeviceUdid <iOS 18.5 sim> -SkipXcodeVersionCheck` with only the new tests (no fix) | **Failed**: 45 passed, 3 failed. All three new cases throw `NullReferenceException` at `DragAndDropDelegate.CalculatePosition`, the same frame as the CI crash. | | Same command with the fix | **Passed**: 48 passed, 0 failed | | `dotnet format whitespace --folder --include <changed files> --verify-no-changes` | Passed | The UI test itself was not rerun locally, because its crash depends on when a GC happens. ### Issues Fixed No existing issue; found while investigating SR2 candidate dotnet#40116 CI. Searched for related issues and PRs and found no duplicate. dotnet#28416/dotnet#28417 is an unrelated Mac Catalyst `DragAndDropDelegate` NRE. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
BlazorWebChromeClient never overrode OnShowCustomView, so the Android WebView reported document.fullscreenEnabled as false: requestFullscreen() rejected and the fullscreen button of <video> and of embedded players (YouTube) was disabled. MauiWebChromeClient already implements fullscreen for the WebView control. Its OnShowCustomView/OnHideCustomView code moves unchanged into an internal WebViewFullScreenPresenter that both chrome clients use, so the two controls enter and leave fullscreen the same way. Fixes dotnet#22049
The handler detaches the chrome client before it destroys the WebView, so Chromium's own OnHideCustomView never arrived and the fullscreen overlay, the landscape lock and the hidden system bars stayed on the activity. The shared presenter also ignores a hide without a shown view, which used to reset the orientation to a stale value, and tells the page right away when there is no activity to show the view in. The fullscreen device tests restore the test activity in a finally block.
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 40456Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 40456" |
This comment has been minimized.
This comment has been minimized.
|
Hey there @Kebechet! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
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. |
…creen Review follow-up for the shared fullscreen presenter and the BlazorWebView chrome client: - Fullscreen no longer calls WindowCompat.SetDecorFitsSystemWindows. Leaving fullscreen set it to true while MauiAppCompatActivity sets false, so the content moved down by the status bar height after each fullscreen (128 px on an API 34 emulator; not on API 36, which keeps apps edge to edge). Android has no getter for it on API 30+, and the custom view sits on the decor view, outside the content it pads. - On API 30+ the status bar, the navigation bar and the caption bar are restored separately; before, an app with one of them hidden got all of them back. Below API 30 all bars are still assumed visible. - Show reports the view hidden when the activity is finishing, destroyed or has no attached window, instead of throwing or covering a window that is not on screen. - BlazorWebChromeClient.Disconnect (was ExitFullScreen) also rejects later OnShowCustomView calls: the WebView keeps the client until its components are disposed, and nothing would hide a view shown then. - Device tests for the disconnect race, the bar state, the layout policy, the missing window and the two guards added earlier. They run against the test runner's activity, because the external navigation tests leave Platform.CurrentActivity on activities that finished in OnCreate.
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. |
|
|
||
| // Store current state | ||
| _windowInsetsController = windowInsetsController; | ||
| _systemBarsToRestore = WindowInsetsCompat.Type.SystemBars(); // Assume visible by default |
There was a problem hiding this comment.
[major] Logic and Correctness Verification - On Android 24-29, a Blazor app with a hidden status bar and visible navigation bar gets its status bar shown after a video fullscreen round trip. This branch unconditionally records SystemBars(), and Hide shows that entire mask, including bars that were already hidden. Separate-bar restoration resolves the earlier finding only on API 30+; the defect remains newly reachable through BlazorWebView on older supported versions. Capture and restore the pre-fullscreen visibility on this branch too, and cover it without the API-30-only test skip.
| await WebViewHelpers.WaitForWebViewReady(platformWebView); | ||
|
|
||
| var activityState = new ActivityStateBeforeFullScreen(activity); | ||
| var chromeClient = platformWebView.WebChromeClient; |
There was a problem hiding this comment.
[moderate] Android Platform Specifics - WebView.WebChromeClient's getter requires API 26, but these tests run without a version guard and the device-test project supports API 24. On Android 7.0/7.1 (API 24/25), ShowCustomViewCoversActivityUntilHidden, DisconnectingHandlerLeavesFullScreen and ShowCustomViewAfterDisconnectIsRejected fail retrieving the client before exercising fullscreen. Obtain the installed client through an API-24-compatible test hook/cached reference, or explicitly guard these tests for API 26+, as Core WebViewHandler does for this getter.
| Assert.Equal<object>(activity.Window!.DecorView, customView.Parent); | ||
| Assert.Equal(ScreenOrientation.Landscape, activity.RequestedOrientation); | ||
|
|
||
| chromeClient.OnHideCustomView(); |
There was a problem hiding this comment.
[moderate] Regression Prevention and Test Coverage - Assert system-bar visibility while fullscreen is showing, before immediately hiding it. This test checks only parentage and orientation; the other bar test checks visibility only after exit. Removing the presenter's system-bar Hide calls would leave these assertions unchanged even though entering fullscreen from an activity with visible bars would leave those bars over the video. Establish visible bars, enter fullscreen, wait for their visibility to become false and assert it before testing restoration.
952a4ae
into
dotnet:candidate/11.0.1xx-sr2
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!
Target Branch
mainnet11, for reviewDescription of Change
Root cause: on Android,
BlazorWebViewinstalls its ownBlazorWebChromeClient, and it never overrodeOnShowCustomView. The Android WebView only lets web content enter fullscreen when theWebChromeClientoverridesOnShowCustomView, so inside aBlazorWebViewdocument.fullscreenEnabledisfalse,element.requestFullscreen()rejects withTypeError: Fullscreen is not supported, and the fullscreen button of<video>is disabled. TheWebViewcontrol got fullscreen support in #15472, but that code lives inMauiWebChromeClient, whichBlazorWebViewdoes not use.Fix:
OnShowCustomView/OnHideCustomViewcode ofMauiWebChromeClientmoves into an internalWebViewFullScreenPresenterin Core, and both chrome clients delegate to it, soWebViewandBlazorWebViewenter and leave fullscreen the same way. The view the page puts in fullscreen covers the decor view, the activity turns to landscape and hides the system bars; on exit the view is removed, the orientation is restored and the system bars come back.BlazorWebViewHandlerpasses the hosting activity toBlazorWebChromeClient, which keeps it in a weak reference asMauiWebChromeClientdoes.BlazorWebViewHandler.DisconnectHandlercallsBlazorWebChromeClient.Disconnect(), which leaves fullscreen if it is showing and refuses to enter it again. The WebView keeps the chrome client until its components are disposed, so the page can still ask for fullscreen in that time, and the handler then detaches the client before destroying the WebView, so Chromium's ownOnHideCustomViewnever arrives. Without this, the overlay, the landscape lock and the hidden system bars would stay on the activity. A request afterDisconnect()getsOnCustomViewHidden()and shows nothing.Changes in the moved code, which also apply to
WebView:WindowCompat.SetDecorFitsSystemWindows. Leaving fullscreen set it totrue, whileMauiAppCompatActivitysets it tofalse. With that policy, one fullscreen round trip moved the app's content down by the status bar height:android.R.id.contentwent from y=0 to y=128 on an API 34 emulator, and stayed at 0 on Android 16 (API 36). Android has no getter for this policy on API 30+, so the presenter cannot put the app's own value back; it also does not need to change it, because the custom view goes on the decor view, outside the content that the policy pads, and the system bars are hidden while it shows.Showcombined their visibility with OR, so an app with only one of them visible got all of them back after fullscreen. Below API 30 the presenter still assumes all bars were visible, as before.Hidedoes nothing unless a view is showing. Before, a strayOnHideCustomViewreset the orientation to a stale value.Showwithout an activity, or with one that is finishing, destroyed or has no window attached, callsOnCustomViewHidden()right away, so the page does not stay in a fullscreen state that nothing displays. Before, a missing activity was ignored, and a detached window threw aNullReferenceExceptionreading its insets.No public API change.
WebViewFullScreenPresenteris internal (Core already grantsInternalsVisibleTotoMicrosoft.AspNetCore.Components.WebView.Maui), andMauiWebChromeClientonly loses private fields.Behaviour a
BlazorWebViewnow inherits from theWebViewcontrol: any element the page puts in fullscreen, not only<video>, gets the landscape orientation and the white background theWebViewcode sets, and the window keeps theBehaviorShowTransientBarsBySwipesystem bar behaviour after fullscreen.Not covered here:
WebViewstill does not leave fullscreen when its handler disconnects, andHybridWebViewsets no chrome client, so its content cannot enter fullscreen either.Tests
Device tests in
BlazorWebViewTests.FullScreen.Android.cs:WebContentReportsFullScreenAsEnabledreadsdocument.fullscreenEnabledfrom a runningBlazorWebView.ShowCustomViewCoversActivityUntilHiddendrives the WebView's chrome client. AfterOnShowCustomViewthe custom view is a child of the activity's decor view and the orientation is landscape. AfterOnHideCustomViewthe view is removed, the orientation is restored andOnCustomViewHiddenwas called once.DisconnectingHandlerLeavesFullScreenshows a custom view and disconnects the handler; the view is removed, the orientation is restored andOnCustomViewHiddenwas called once.ShowCustomViewAfterDisconnectIsRejecteddisconnects the handler, then asks the still attached chrome client for fullscreen; nothing is shown andOnCustomViewHiddenis called once.ShowCustomViewWithoutActivityReportsTheViewHiddenandShowCustomViewWithoutAWindowOnScreenReportsTheViewHidden: a chrome client with no activity, or with an activity that has no window, reports the view hidden and keeps no showing state.HidingAgainAfterLeavingFullScreenChangesNothingleaves fullscreen, changes the orientation, callsOnHideCustomViewagain and checks the orientation and the callback count do not change.LeavingFullScreenKeepsTheActivityEdgeToEdgegives the activity the edge-to-edge policy ofMauiAppCompatActivity, enters and leaves fullscreen, and checks the content has not moved.LeavingFullScreenKeepsAHiddenStatusBarHidden(API 30+) hides the status bar, enters and leaves fullscreen, and checks the status bar is still hidden and the navigation bar is as it was.The tests that show a custom view put the activity back in a
finally(overlay, orientation, system bar behaviour) and wait for the rotation and bar animations to finish. They run against the test runner's activity rather thanPlatform.CurrentActivity, because the external navigation tests start activities that finish themselves, and the current activity can still point at one of those.All
MauiBlazorWebView.DeviceTests, run with xharness on a Pixel 6 (Android 16, API 36) and an API 34 emulator (Google APIs, x86_64), on this branch's basenet11(d1bb681):fullscreenEnabledisfalse; the custom view never reaches the decor view)DisconnectHandlerchangeDisconnectingHandlerLeavesFullScreen: the overlay stays on the decor view)ShowCustomViewAfterDisconnectIsRejected(the view lands on the decor view),LeavingFullScreenKeepsAHiddenStatusBarHidden(the status bar comes back),ShowCustomViewWithoutAWindowOnScreenReportsTheViewHidden(NullPointerException)LeavingFullScreenKeepsTheActivityEdgeToEdge(the content moves from y=0 to y=128)HidingAgainAfterLeavingFullScreenChangesNothingandShowCustomViewWithoutActivityReportsTheViewHiddencover guards that were already in 0d6eaf5; each fails when its guard is removed (the orientation is reset toUnspecified; the callback count is 0).API 19 to 29 were not run.
By hand, in a template Blazor Hybrid app on MAUI 10.0.130 with a copy of this code installed from app code as the
BlazorWebView's chrome client: a tap that callsrequestFullscreen()on a<video>resolves, the element goes fullscreen in landscape with the system bars hidden, and Back leaves fullscreen with the page layout as it was. The video file itself did not load on that network, so this checked the fullscreen handling, not playback. That check predates the review follow-up.What NOT to Do (for future agents)
BlazorWebChromeClient. The two controls would drift apart; shareWebViewFullScreenPresenter.requestFullscreen()throughEvaluateJavascript, as the device tests run script. That gives the page no user activation, so the call rejects.document.fullscreenEnableddoes not depend on one.SetDecorFitsSystemWindowsin the presenter. Android cannot report the app's value on API 30+, so whatever the presenter sets on exit overrides the app's layout policy.Platform.CurrentActivityin these device tests. After the external navigation tests it can be an activity that finished inOnCreateand has no window.Issues Fixed
Fixes #22049