Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue32971.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 32971, "WebView content does not scroll when placed inside a ScrollView", PlatformAffected.Android)]
public class Issue32971 : ContentPage
{
public Issue32971()
{
Label _scrollStateLabel = new Label
{
Text = "NotScrolled",
AutomationId = "ScrollStateLabel",
FontSize = 20,
HorizontalTextAlignment = TextAlignment.Center,
};

WebView _webView = new WebView
{
AutomationId = "TestWebView",
HeightRequest = 600,
VerticalOptions = LayoutOptions.Start,
};

_webView.Source = new HtmlWebViewSource
{
Html = @"
<!DOCTYPE html>
<html>
<head>
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
<style>
body { font-family: Arial; padding: 20px; margin: 0; }
.section { border: 2px solid #0066cc; padding: 20px; margin: 10px 0; background: #f0f8ff; min-height: 300px; }
</style>
</head>
<body>
<h1>WebView Scrolling Test</h1>
<div class='section'><h2>Section 1</h2><p>Scroll down to test...</p></div>
<div class='section'><h2>Section 2</h2><p>Keep scrolling...</p></div>
<div class='section'><h2>Section 3</h2><p>More content...</p></div>
<div class='section'><h2>Section 4</h2><p>Almost there...</p></div>
<div class='section'><h2>Section 5</h2><p>Bottom reached!</p></div>
</body>
</html>"
};

var checkButton = new Button
{
Text = "Check Scroll State",
AutomationId = "CheckButton",
};

checkButton.Clicked += async (s, e) =>
{
var result = await _webView.EvaluateJavaScriptAsync("Math.round(window.pageYOffset);");
if (int.TryParse(result, out int scrollPos) && scrollPos > 50)
{
_scrollStateLabel.Text = "Scrolled";
}
};

var scrollView = new ScrollView
{
AutomationId = "TestScrollView",
Content = new VerticalStackLayout
{
Children = { _scrollStateLabel, checkButton, _webView }
}
};

Content = scrollView;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;

public class Issue32971 : _IssuesUITest
{
public override string Issue => "WebView content does not scroll when placed inside a ScrollView";

public Issue32971(TestDevice device) : base(device)
{
}

[Test]
[Category(UITestCategories.WebView)]
public void WebViewShouldScrollInsideScrollView()
{
App.WaitForElement("TestScrollView");
App.ScrollDown("TestScrollView");
App.Tap("CheckButton");
var scrollStateLabel = App.FindElement("ScrollStateLabel").GetText();
Assert.That(scrollStateLabel, Is.EqualTo("Scrolled"));
}
}
22 changes: 22 additions & 0 deletions src/Core/src/Platform/Android/MauiWebView.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using Android.Content;
using Android.Graphics;
using Android.Views;
using Android.Webkit;

namespace Microsoft.Maui.Platform
Expand Down Expand Up @@ -42,6 +43,27 @@ protected override void OnSizeChanged(int width, int height, int oldWidth, int o
}
}

public override bool OnTouchEvent(MotionEvent? e)
{
if (e == null)
return false;

switch (e.Action)
{
case MotionEventActions.Down:
case MotionEventActions.Move:
Parent?.RequestDisallowInterceptTouchEvent(true);
break;

case MotionEventActions.Up:
case MotionEventActions.Cancel:
Parent?.RequestDisallowInterceptTouchEvent(false);
break;
}

return base.OnTouchEvent(e);
}

void IWebViewDelegate.LoadHtml(string? html, string? baseUrl)
{
_handler?.CurrentNavigationEvent = WebNavigationEvent.NewPage;
Expand Down
1 change: 1 addition & 0 deletions src/Core/src/PublicAPI/net-android/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ override Microsoft.Maui.Platform.LayoutViewGroup.HasOverlappingRendering.get ->
override Microsoft.Maui.Platform.WrapperView.HasOverlappingRendering.get -> bool
override Microsoft.Maui.Platform.MauiHybridWebView.OnSizeChanged(int width, int height, int oldWidth, int oldHeight) -> void
override Microsoft.Maui.Platform.MauiWebView.OnSizeChanged(int width, int height, int oldWidth, int oldHeight) -> void
override Microsoft.Maui.Platform.MauiWebView.OnTouchEvent(Android.Views.MotionEvent? e) -> bool
Loading