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.
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
- Loading branch information
Showing
16 changed files
with
240 additions
and
8 deletions.
There are no files selected for viewing
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
html,body{margin:0;padding:10} | ||
body,p,h1{font-family:Chalkduster;font-style: italic;} |
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,10 @@ | ||
<html> | ||
<head> | ||
<link rel="stylesheet" href="default.css"> | ||
</head> | ||
<body> | ||
<h1>Xamarin.Forms</h1> | ||
<p>This is a local HTML page</p> | ||
|
||
</body> | ||
</html> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
html,body{margin:0;padding:10} | ||
body,p,h1{font-family:Chalkduster;font-style: italic;} |
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,10 @@ | ||
<html> | ||
<head> | ||
<link rel="stylesheet" href="default.css"> | ||
</head> | ||
<body> | ||
<h1>Xamarin.Forms</h1> | ||
<p>This is a local HTML page</p> | ||
|
||
</body> | ||
</html> |
Binary file added
BIN
+6.83 KB
Xamarin.Forms.ControlGallery.WindowsUniversal/WebImages/XamarinLogo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
html,body{margin:0;padding:10} | ||
body,p,h1{font-family:Chalkduster;font-style: italic;} |
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,10 @@ | ||
<html> | ||
<head> | ||
<link rel="stylesheet" href="default.css"> | ||
</head> | ||
<body> | ||
<h1>Xamarin.Forms</h1> | ||
<p>This is a local HTML page</p> | ||
|
||
</body> | ||
</html> |
141 changes: 141 additions & 0 deletions
141
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla32033.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,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; | ||
} | ||
} | ||
} |
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