diff options
author | E.Z. Hart <hartez@users.noreply.github.com> | 2016-08-03 15:22:14 -0600 |
---|---|---|
committer | Jason Smith <jason.smith@xamarin.com> | 2016-08-03 14:22:14 -0700 |
commit | b186254d1f4a0547c67f4fd30669df9d4cf36b65 (patch) | |
tree | 6278a0f3217c726aed4e29c2027b10eb61522aeb /Xamarin.Forms.Controls.Issues | |
parent | b60fa6acf84d897d6283310e58b1c6c6365c391c (diff) | |
download | xamarin-forms-b186254d1f4a0547c67f4fd30669df9d4cf36b65.tar.gz xamarin-forms-b186254d1f4a0547c67f4fd30669df9d4cf36b65.tar.bz2 xamarin-forms-b186254d1f4a0547c67f4fd30669df9d4cf36b65.zip |
Enable WebView to render local HTML files on WinRT platforms (#277)
* Enable WebView to render local HTML files on WinRT platforms
* Add test to demonstrate that the solution works even if
<head> isn't in the HTML string
Diffstat (limited to 'Xamarin.Forms.Controls.Issues')
2 files changed, 142 insertions, 0 deletions
diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla32033.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla32033.cs new file mode 100644 index 00000000..2576525a --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla32033.cs @@ -0,0 +1,141 @@ +using Xamarin.Forms.CustomAttributes; +using Xamarin.Forms.Internals; + +namespace Xamarin.Forms.Controls +{ + [Preserve (AllMembers = true)] + [Issue (IssueTracker.Bugzilla, 32033, "WebView on Windows does not display local HTML files", PlatformAffected.WinRT)] + public class Bugzilla32033 : TestNavigationPage + { + protected override void Init () + { + PushAsync(Menu()); + } + + ContentPage Menu() + { + var page = new ContentPage(); + + var layout = new StackLayout(); + + var buttonLocal = new Button() {Text = "Local HTML file"}; + buttonLocal.Clicked += (sender, args) => Navigation.PushAsync(LocalUrl()); + + var buttonHtmlString = new Button() {Text = "HTML string with links/refs to local files"}; + buttonHtmlString.Clicked += (sender, args) => Navigation.PushAsync(HtmlString()); + + var buttonHtmlStringNoHead = new Button() {Text = "HTML string with links/refs to local files (no <head>)"}; + buttonHtmlStringNoHead.Clicked += (sender, args) => Navigation.PushAsync(HtmlStringNoHead()); + + layout.Children.Add(buttonLocal); + layout.Children.Add(buttonHtmlString); + layout.Children.Add(buttonHtmlStringNoHead); + + page.Content = layout; + + return page; + } + + static ContentPage LocalUrl() + { + var page = new ContentPage(); + + var instructions = new Label + { + Text = @"The WebView below should contain the heading 'Xamarin Forms' and text reading 'This is a local HTML page'. All text should be italicized." + }; + + var webView = new WebView + { + WidthRequest = 300, + HeightRequest = 500, + HorizontalOptions = LayoutOptions.Fill, + VerticalOptions = LayoutOptions.Fill, + Source = new UrlWebViewSource() { Url = "local.html" } + }; + + var layout = new StackLayout { Children = { instructions, webView } }; + page.Content = layout; + + return page; + } + + static ContentPage HtmlString() + { + var page = new ContentPage(); + + var instructions = new Label + { + Text = +@"The WebView below should contain the heading 'Xamarin Forms', display the Xamarin logo, and have a link labeled 'next page'. +Clicking that link should navigate to a page with the heading 'Xamarin Forms' and text reading 'This is a local HTML page'. All text on both pages should be italicized." + }; + + var webView = new WebView + { + WidthRequest = 300, + HeightRequest = 500, + HorizontalOptions = LayoutOptions.Fill, + VerticalOptions = LayoutOptions.Fill, + Source = new HtmlWebViewSource + { + Html = @"<html> +<head> +<link rel=""stylesheet"" href=""default.css""> +</head> +<body> +<h1>Xamarin.Forms</h1> +<p>The CSS and image are loaded from local files!</p> +<img src='WebImages/XamarinLogo.png'/> +<p><a href=""local.html"">next page</a></p> +</body> +</html>" + } + }; + + + var layout = new StackLayout {HorizontalOptions = LayoutOptions.Fill, VerticalOptions = LayoutOptions.Fill, Children = { instructions, webView } }; + page.Content = layout; + + return page; + } + + // This test verifies that the <base> injection solution works even if the HTML string doesn't explicitly include a <head> section + static ContentPage HtmlStringNoHead() + { + var page = new ContentPage(); + + var instructions = new Label + { + Text = +@"The WebView below should contain the heading 'Xamarin Forms', display the Xamarin logo, and have a link labeled 'next page'. +Clicking that link should navigate to a page with the heading 'Xamarin Forms' and text reading 'This is a local HTML page'. " + }; + + var webView = new WebView + { + WidthRequest = 300, + HeightRequest = 500, + HorizontalOptions = LayoutOptions.Fill, + VerticalOptions = LayoutOptions.Fill, + Source = new HtmlWebViewSource + { + Html = @"<html> +<body> +<h1>Xamarin.Forms</h1> +<p>The CSS and image are loaded from local files!</p> +<img src='WebImages/XamarinLogo.png'/> +<p><a href=""local.html"">next page</a></p> +</body> +</html>" + } + }; + + + var layout = new StackLayout {HorizontalOptions = LayoutOptions.Fill, VerticalOptions = LayoutOptions.Fill, Children = { instructions, webView } }; + page.Content = layout; + + return page; + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems index 4fdb18fd..8d1e0b40 100644 --- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems @@ -46,6 +46,7 @@ <Compile Include="$(MSBuildThisFileDirectory)Bugzilla31333.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Bugzilla31366.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Bugzilla31964.cs" /> + <Compile Include="$(MSBuildThisFileDirectory)Bugzilla32033.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Bugzilla32034.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Bugzilla32776.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Bugzilla32842.xaml.cs"> |