-
Notifications
You must be signed in to change notification settings - Fork 2k
[Android] Fix: WebView clamping small CSS font sizes #36559
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f316caf
Fixed Android Webview font size issue
SubhikshaSf4851 2d82913
updated review concern
SubhikshaSf4851 a160386
Added review concerns
SubhikshaSf4851 46bcc2c
updated review concern
SubhikshaSf4851 8af6bee
updated test sample review concerns
SubhikshaSf4851 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,69 @@ | ||
| namespace Maui.Controls.Sample.Issues | ||
| { | ||
| [Issue(IssueTracker.Github, 26924, "Font Size of span Element Not Rendering Correctly in Mobile Mode in .NET MAUI Blazor", PlatformAffected.All)] | ||
| public class Issue26924 : TestContentPage | ||
| { | ||
| WebView _webView; | ||
| Label _resultLabel; | ||
| Button _checkButton; | ||
|
|
||
| const string SmallFontSpanId = "smallFontSpan"; | ||
| internal const string SmallFontCssValue = "4.87761px"; | ||
|
|
||
| protected override void Init() | ||
| { | ||
| var html = $@" | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head></head> | ||
| <body> | ||
| <p>Hi, this is a paragraph.</p> | ||
| <span id=""{SmallFontSpanId}"" style=""font-size:{SmallFontCssValue};"">tiny span text</span> | ||
| </body> | ||
| </html>"; | ||
|
Comment on lines
+15
to
+23
|
||
|
|
||
| _webView = new WebView | ||
| { | ||
| Source = new HtmlWebViewSource { Html = html }, | ||
| HeightRequest = 100, | ||
| AutomationId = "SmallFontWebView" | ||
| }; | ||
|
|
||
| _resultLabel = new Label | ||
| { | ||
| Text = "Not checked yet", | ||
| AutomationId = "ComputedFontSizeLabel" | ||
| }; | ||
|
|
||
| _checkButton = new Button | ||
| { | ||
| Text = "Get computed font size of span", | ||
| AutomationId = "CheckFontSizeButton", | ||
| Command = new Command(async () => await CheckComputedFontSizeAsync()) | ||
| }; | ||
|
|
||
| // Update the result label once the WebView finishes loading the HTML, so the test | ||
| // can wait for "WebView loaded" before tapping the button instead of racing navigation. | ||
| _webView.Navigated += (_, __) => _resultLabel.Text = "WebView loaded"; | ||
|
|
||
| Content = new VerticalStackLayout | ||
| { | ||
| Children = | ||
| { | ||
| new Label { Text = $"Expected computed font-size to stay close to {SmallFontCssValue} (i.e. under 8px), not be clamped up by the platform WebView's minimum font size." }, | ||
| _webView, | ||
| _checkButton, | ||
| _resultLabel | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| async Task CheckComputedFontSizeAsync() | ||
| { | ||
| var computedFontSize = await _webView.EvaluateJavaScriptAsync( | ||
| $"window.getComputedStyle(document.getElementById('{SmallFontSpanId}')).fontSize"); | ||
|
|
||
| _resultLabel.Text = computedFontSize?.Trim('"') ?? string.Empty; | ||
| } | ||
| } | ||
| } | ||
30 changes: 30 additions & 0 deletions
30
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue26924.cs
This file contains hidden or 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,30 @@ | ||
| using System.Globalization; | ||
| using NUnit.Framework; | ||
| using UITest.Appium; | ||
| using UITest.Core; | ||
|
|
||
| namespace Microsoft.Maui.TestCases.Tests.Issues; | ||
|
|
||
| public class Issue26924 : _IssuesUITest | ||
| { | ||
| public Issue26924(TestDevice device) : base(device) | ||
| { | ||
| } | ||
|
|
||
| public override string Issue => "Font Size of span Element Not Rendering Correctly in Mobile Mode in .NET MAUI Blazor"; | ||
|
|
||
| [Test] | ||
| [Category(UITestCategories.WebView)] | ||
| public void SmallFontSizeSpanIsNotClampedByMinimumFontSize() | ||
| { | ||
| // The result label is updated to "WebView loaded" once the WebView finishes loading | ||
| // the HTML, so wait for that before tapping the button to avoid racing navigation. | ||
| App.WaitForTextToBePresentInElement("ComputedFontSizeLabel", "WebView loaded"); | ||
| App.Tap("CheckFontSizeButton"); | ||
| App.WaitForTextToBePresentInElement("ComputedFontSizeLabel", "px"); | ||
| var computedFontSizeText = App.WaitForElement("ComputedFontSizeLabel").GetText(); | ||
| Assert.That(computedFontSizeText, Is.Not.Null); | ||
| Assert.That(float.Parse(computedFontSizeText!.Trim().TrimEnd('p', 'x'), CultureInfo.InvariantCulture), Is.LessThan(8f)); | ||
| } | ||
| } | ||
|
|
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.