Skip to content
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

popup: Implement TextPopupElement view for MAUI #522

Merged
merged 6 commits into from
Sep 15, 2023

Conversation

mstefarov
Copy link
Collaborator

2023-09-11_095730

2023-09-11_100845

2023-09-11_095809

2023-09-11_105216

TextElementPopupView is coming to MAUI!

  • Text maps to Labels with formatted Spans.
  • Blocks (e.g. paragraphs, table cells, list items) map to StackLayouts.
  • Lists map to grids (one column for markers, another for content).
  • Tables map to grids (with some extra logic to handle row/column assignment and rowspans/colspans).
  • Images are loaded through RuntimeImage to take advantage of our authentication and caching stack.

Known limitations

  • Text occasionally has extra space between lines or words. This is due to MAUI implementation being more sensitive to inconsistent newlines/whitespace than WPF's FlowDocument-based viewer. I am a preparing a follow-up PR that adds a document tree simplification pass to the HTML parser that will address this.
  • Text links are not clickable on some platforms due to Gestures don't work on Label Spans dotnet/maui#4734 (might be fixed before NET 8 GA)
  • Subscript (<sub>) and superscript (<sup>) do not have any visual effect, because MAUI does not expose any API to control this font feature.
  • Table columns are always equally-spaced, which might inefficiently distribute space between columns with different amounts of content. "Auto" column width does not work well in MAUI because it prevents line-wrapping and causes the table to stretch out-of-bounds.

@mstefarov mstefarov self-assigned this Sep 11, 2023
Copy link
Member

@dotMorten dotMorten left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking great. Really only found one minor oversight


case MarkupType.Image:
var imageElement = new Image();
if (Uri.TryCreate(node.Content, UriKind.Absolute, out var imgUri))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that his can also begin with data:image/. See

if (sourceUrl.StartsWith("data:image/"))
{
// might be base64
var idx = sourceUrl.IndexOf(";base64,");

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like I missed this from both MAUI and WPF text element views. Fixed!

2023-09-11_144705

@mstefarov
Copy link
Collaborator Author

Tested on iOS and everything looks good except for cases where a popup contains nothing but text-only TextPopupElements. In cases like that, ScrollView does not correctly expand to show contents, and stays collapsed:

This is not a regression in this PR -- it's probably due to a MAUI bug dotnet/maui#15374

@mstefarov mstefarov merged commit 3c74bba into main Sep 15, 2023
1 check passed
@mstefarov mstefarov deleted the matvei/maui-text-popup-element branch September 15, 2023 01:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants