-
Notifications
You must be signed in to change notification settings - Fork 2k
[iOS] Fix issue that does not allow scrolling in WebView with PDF #21571
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
00724aa
7d0d252
cebaa37
f1fab4b
8058fc3
91a0b14
e8653bf
39c66a5
6f4ec3a
412424f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| <?xml version="1.0" encoding="utf-8" ?> | ||
| <ContentPage | ||
| xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
| xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
| x:Class="Maui.Controls.Sample.Issues.Issue18716"> | ||
| <Grid | ||
| RowDefinitions="*, Auto"> | ||
| <WebView | ||
| x:Name="WaitForStubControl" | ||
| AutomationId="WaitForStubControl" | ||
| Source="https://freetestdata.com/wp-content/uploads/2021/09/Free_Test_Data_1MB_PDF.pdf"> | ||
| </WebView> | ||
| <Label | ||
| x:Name="LoadedControl" | ||
| AutomationId="LoadedControl" /> | ||
| </Grid> | ||
| </ContentPage> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| using Microsoft.Maui.Controls; | ||
|
|
||
| namespace Maui.Controls.Sample.Issues | ||
| { | ||
| [Issue(IssueTracker.Github, 18716, "Touch events are not working on WebView when a PDF is displayed", PlatformAffected.iOS)] | ||
| public partial class Issue18716 : ContentPage | ||
| { | ||
| public Issue18716() | ||
| { | ||
| InitializeComponent(); | ||
| } | ||
|
|
||
| protected override void OnAppearing() | ||
| { | ||
| base.OnAppearing(); | ||
| WaitForStubControl.Navigating += OnWebViewNavigating; | ||
| } | ||
|
|
||
| protected override void OnDisappearing() | ||
| { | ||
| base.OnDisappearing(); | ||
| WaitForStubControl.Navigating -= OnWebViewNavigating; | ||
| } | ||
|
|
||
| void OnWebViewNavigating(object sender, WebNavigatingEventArgs e) | ||
| { | ||
| LoadedControl.Text = "Ready"; | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| using NUnit.Framework; | ||
| using UITest.Appium; | ||
| using UITest.Core; | ||
|
|
||
| namespace Microsoft.Maui.AppiumTests.Issues | ||
| { | ||
| public class Issue18716 : _IssuesUITest | ||
| { | ||
| public Issue18716(TestDevice device) | ||
| : base(device) | ||
| { } | ||
|
|
||
| public override string Issue => "Touch events are not working on WebView when a PDF is displayed"; | ||
|
|
||
| [Test] | ||
| [Category(UITestCategories.WebView)] | ||
| public void CanScrollWebView() | ||
| { | ||
| this.IgnoreIfPlatforms(new TestDevice[] { TestDevice.Android, TestDevice.Mac, TestDevice.Windows }); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would this be worth enabling for all platforms?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Enabled on more platforms. Scrolling using gestures, so Android and iOS. |
||
|
|
||
| App.WaitForElement("LoadedControl", timeout: TimeSpan.FromSeconds(1)); | ||
| var result = App.FindElement("LoadedControl").GetText(); | ||
| Assert.AreEqual("Ready", result); | ||
|
|
||
| App.WaitForElement("WaitForStubControl"); | ||
| App.ScrollDown("WaitForStubControl", ScrollStrategy.Gesture, 0.75); | ||
| App.Screenshot("Scrolling has been done correctly."); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| using System; | ||
| using System.Linq; | ||
| using CoreGraphics; | ||
| using UIKit; | ||
|
|
||
|
|
@@ -6,7 +8,7 @@ namespace Microsoft.Maui.Platform | |
| public class LayoutView : MauiView | ||
| { | ||
| bool _userInteractionEnabled; | ||
|
|
||
| public override void SubviewAdded(UIView uiview) | ||
| { | ||
| InvalidateConstraintsCache(); | ||
|
|
@@ -26,9 +28,11 @@ public override void WillRemoveSubview(UIView uiview) | |
| var result = base.HitTest(point, uievent); | ||
|
|
||
| if (result is null) | ||
| { | ||
| return null; | ||
| } | ||
|
|
||
| if (!_userInteractionEnabled && this.Equals(result)) | ||
| if (!_userInteractionEnabled && Equals(result)) | ||
| { | ||
| // If user interaction is disabled (IOW, if the corresponding Layout is InputTransparent), | ||
| // then we exclude the LayoutView itself from hit testing. But it's children are valid | ||
|
|
@@ -37,11 +41,10 @@ public override void WillRemoveSubview(UIView uiview) | |
| return null; | ||
| } | ||
|
|
||
| if (!result.UserInteractionEnabled) | ||
| if (Subviews.Contains(result) && !result.UserInteractionEnabled) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be better to rather do
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, I am thinking we can't just check the result, we need to find the parent that is the child of the layout. So I am thinking: while (result.Superview is not null && result.Superview != this)
result = result.Superview;
if (result.Superview == this && !result.UserInteractionEnabled)If we have a secret scroll view in our webview, we still need to find that webview and read the property the user set in XAML. |
||
| { | ||
| // If the child also has user interaction disabled (IOW the child is InputTransparent), | ||
| // then we also want to exclude it from the hit testing. | ||
|
|
||
| // then we also want to exclude it from the hit testing. } | ||
| return null; | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better to maybe add a local pdf that would make sure we don't hit any connection issues loading this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, we can maybe at least host the pdf in the maui repo since we cannot control what this pdf is/does in the future.