This repository has been archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…4919 closes #5460 * [Android] Fixes cancel Webview Navigation * - added fix 4891 - refactoring * Fix obsolete message Co-authored-by: Ralph Brackert <[email protected]>
- Loading branch information
Showing
5 changed files
with
221 additions
and
35 deletions.
There are no files selected for viewing
105 changes: 105 additions & 0 deletions
105
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue4891.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
using System; | ||
using Xamarin.Forms.CustomAttributes; | ||
using Xamarin.Forms.Internals; | ||
|
||
#if UITEST | ||
using Xamarin.Forms.Core.UITests; | ||
using Xamarin.UITest; | ||
using NUnit.Framework; | ||
#endif | ||
|
||
namespace Xamarin.Forms.Controls.Issues | ||
{ | ||
#if UITEST | ||
[Category(UITestCategories.ManualReview)] | ||
#endif | ||
[Preserve(AllMembers = true)] | ||
[Issue(IssueTracker.Github, 4891, "[Android] WebView Navigating Cancel property not working with custom scheme", PlatformAffected.Android)] | ||
public class Issue4891 : TestContentPage // or TestMasterDetailPage, etc ... | ||
{ | ||
Button _back; | ||
WebView _myWebView; | ||
Label _log; | ||
ScrollView _logScrollView; | ||
|
||
protected override void Init() | ||
{ | ||
|
||
_back = new Button | ||
{ | ||
Text = "Back" | ||
}; | ||
_back.Clicked += Back_Clicked; | ||
|
||
_myWebView = new WebView | ||
{ | ||
HorizontalOptions = LayoutOptions.StartAndExpand, | ||
VerticalOptions = LayoutOptions.Start, | ||
HeightRequest = 240 | ||
}; | ||
_myWebView.Navigating += MyWebView_Navigating; | ||
_myWebView.Navigated += MyWebView_Navigated; | ||
_myWebView.Source = new HtmlWebViewSource() | ||
{ | ||
Html = "<html><body>Click on the link below. Expected results:<br/>1. Navigating event logged.<br/>2. Navigated event NOT logged.<br/>3. This page stays loaded in the WebView control.<br/><br/><a href='xamforms4223://custom'>Navigate to Custom xamforms4223 scheme</a></body></html>" | ||
}; | ||
|
||
_log = new Label | ||
{ | ||
VerticalOptions = LayoutOptions.StartAndExpand, | ||
HorizontalOptions = LayoutOptions.FillAndExpand, | ||
Text = "" | ||
}; | ||
|
||
_logScrollView = new ScrollView | ||
{ | ||
VerticalOptions = LayoutOptions.StartAndExpand, | ||
HorizontalOptions = LayoutOptions.FillAndExpand, | ||
Content = _log | ||
}; | ||
|
||
Content = new StackLayout | ||
{ | ||
Children = | ||
{ | ||
_myWebView, | ||
_back, | ||
_logScrollView | ||
} | ||
}; | ||
} | ||
|
||
|
||
void MyWebView_Navigating(object sender, WebNavigatingEventArgs e) | ||
{ | ||
LogToScreen($"Navigating: {e.Url}"); | ||
if (e.Url.StartsWith("xamforms4223", StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
LogToScreen("Caught custom scheme, cancelling navigation."); | ||
e.Cancel = true; | ||
} | ||
} | ||
|
||
void MyWebView_Navigated(object sender, WebNavigatedEventArgs e) | ||
{ | ||
LogToScreen($"Navigated: ({e.Result}) {e.Url}"); | ||
} | ||
|
||
void LogToScreen(string text) | ||
{ | ||
_log.Text += $"{text}\n"; | ||
|
||
InvalidateMeasure(); | ||
_logScrollView.ScrollToAsync(_log, ScrollToPosition.End, false); | ||
} | ||
|
||
void Back_Clicked(object sender, EventArgs e) | ||
{ | ||
if (_myWebView.CanGoBack) | ||
{ | ||
_myWebView.GoBack(); | ||
} | ||
} | ||
|
||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue4919.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using Xamarin.Forms.CustomAttributes; | ||
using Xamarin.Forms.Internals; | ||
|
||
namespace Xamarin.Forms.Controls.Issues | ||
{ | ||
[Preserve(AllMembers = true)] | ||
[Issue(IssueTracker.Github, 4919, "Webview Navigation cancel not working", PlatformAffected.Android)] | ||
public class Issue4919 : TestContentPage // or TestMasterDetailPage, etc ... | ||
{ | ||
protected override void Init() | ||
{ | ||
var url = "https://www.microsoft.com/"; | ||
var cancel = true; | ||
var log = new Label | ||
{ | ||
VerticalOptions = LayoutOptions.StartAndExpand, | ||
HorizontalOptions = LayoutOptions.FillAndExpand, | ||
Text = "" | ||
}; | ||
var webView = new WebView() | ||
{ | ||
HorizontalOptions = LayoutOptions.Fill, | ||
VerticalOptions = LayoutOptions.FillAndExpand, | ||
Source = url | ||
}; | ||
webView.Navigating += (_, e) => | ||
{ | ||
e.Cancel = cancel; | ||
var resultText = cancel ? "[Canceled]" : "[OK]"; | ||
log.Text += $"{resultText} {e.Url}{System.Environment.NewLine}"; | ||
}; | ||
|
||
Content = new StackLayout | ||
{ | ||
Children = | ||
{ | ||
new Label { Text = "WebView must be empty on init" }, | ||
webView, | ||
new Button | ||
{ | ||
Text = "Go to github", | ||
Command = new Command(() => webView.Source = "https://github.com/xamarin/Xamarin.Forms") | ||
}, | ||
new Button | ||
{ | ||
Text = "Toggle cancel navigation", | ||
Command = new Command(() => cancel = !cancel) | ||
}, | ||
new ScrollView | ||
{ | ||
VerticalOptions = LayoutOptions.EndAndExpand, | ||
HorizontalOptions = LayoutOptions.FillAndExpand, | ||
Content = log | ||
} | ||
} | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters