Fix WebView SwipeView gestures on Android - #36499
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: cf5a6299-1e58-4157-b7fd-b85efaa14755
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 36499Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 36499" |
There was a problem hiding this comment.
Pull request overview
This PR fixes an Android regression where SwipeView can no longer reliably detect swipe gestures when the user swipes directly on a nested WebView. It updates the Android platform implementations to let the WebView consume gestures while it can scroll in the gesture direction, and lets SwipeView handle the gesture when the WebView is at its scroll edge, with UI-test coverage added for the regression scenario.
Changes:
- Android
MauiWebViewavoids callingRequestDisallowInterceptTouchEvent(true)when hosted within aSwipeView, preventingFLAG_DISALLOW_INTERCEPTfrom blockingSwipeViewgesture detection. - Android
MauiSwipeViewadds aWebView-specific intercept decision usingCanScrollHorizontally/VerticallyandSwipeDirection. - Adds a HostApp repro page and a Shared UI test for issue #36154.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/Core/src/Platform/Android/MauiWebView.cs | Caches whether the WebView is inside a MauiSwipeView and conditionally suppresses RequestDisallowInterceptTouchEvent(true) to allow SwipeView swipes. |
| src/Core/src/Platform/Android/MauiSwipeView.cs | Adds direction-aware WebView edge detection (ShouldInterceptWebViewTouch) to decide when SwipeView should intercept. |
| src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue36154.cs | Adds a UI regression test that swipes on the SwipeView/WebView area and asserts the RightItems command was invoked. |
| src/Controls/tests/TestCases.HostApp/Issues/Issue36154.cs | Adds a HostApp issue page with a WebView inside SwipeView to reproduce/validate the behavior. |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: cf5a6299-1e58-4157-b7fd-b85efaa14755
| <p>Scroll down to verify WebView vertical scrolling works inside SwipeView.</p> | ||
| <p>Then swipe left/right to reveal swipe items.</p> | ||
| <p>At the top edge, swipe down to reveal TopItems.</p> | ||
| <p>At the bottom edge, swipe up to reveal BottomItems.</p> | ||
| """ + string.Concat(Enumerable.Range(1, 40).Select(i => | ||
| $"<p>Line {i}: Lorem ipsum dolor sit amet consectetur adipiscing elit.</p>")) | ||
| + "</body></html>" |
| // Swipe left (finger moves left) → reveals RightItems | ||
| App.DragCoordinates(centerX, centerY, centerX - 200, centerY); | ||
|
|
||
| Assert.That(App.WaitForElement("ResultLabel").GetText(), Is.EqualTo("RIGHT invoked!")); |
| // Determines whether the SwipeView should intercept touch events when the content is a WebView, based on the WebView's scroll position and the swipe direction. | ||
| static bool ShouldInterceptWebViewTouch(AWebView webView, SwipeDirection swipeDirection) => | ||
| swipeDirection switch | ||
| { | ||
| SwipeDirection.Right => !webView.CanScrollHorizontally(-1), // at left edge | ||
| SwipeDirection.Left => !webView.CanScrollHorizontally(1), // at right edge | ||
| SwipeDirection.Down => !webView.CanScrollVertically(-1), // at top | ||
| SwipeDirection.Up => !webView.CanScrollVertically(1), // at bottom | ||
| _ => true, | ||
| }; |
|
/backport to release/10.0.1xx-sr9 |
|
Started backporting to |
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!
Fixes #36154.
Forward-ports the final implementation and regression coverage from #36231 to
main, preserving the newer WebView lifecycle handling already present onmain.The Android SwipeView now yields to a nested WebView while it can scroll in the gesture direction, and handles the gesture at the WebView edge.