Skip to content
This repository has been archived by the owner on Oct 29, 2024. It is now read-only.

Commit

Permalink
Fix Labels with multiple Spans
Browse files Browse the repository at this point in the history
- The recent change to allow Spans directly inside a Label didn't handle that when adding multiple Spans the sibling index calculation must be adjusted
- Whitespace trimming was removed from Spans because it ends up removing significant whitespace when a multi-span label has whitespace.
  • Loading branch information
Eilon committed May 18, 2020
1 parent c51e314 commit 6a49cb9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,17 @@ public virtual int GetPhysicalSiblingIndex()
// A ScrollView can have only 1 child, so the child's index is always 0.
return 0;
}
case XF.Label _:
case XF.Label parentAsLabel:
{
// A Label can have only 1 child, so the child's index is always 0.
// There are two cases to consider:
// 1. A Xamarin.Forms Label can have only 1 child (a FormattedString), so the child's index is always 0.
// 2. But to simplify things, in MobileBlazorBindings a Label can contain a Span directly, so if the child
// is a Span, we have to compute its sibling index.
if (nativeComponent is XF.Span childAsSpan)
{
return parentAsLabel.FormattedText?.Spans.IndexOf(childAsSpan) ?? 0;
}

return 0;
}
case XF.FormattedString parentAsFormattedString:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Microsoft.MobileBlazorBindings.Elements.Handlers
{
public partial class SpanHandler : GestureElementHandler, IHandleChildContentText
{
private readonly TextSpanContainer _textSpanContainer = new TextSpanContainer();
private readonly TextSpanContainer _textSpanContainer = new TextSpanContainer(trimWhitespace: false);

public void HandleText(int index, string text)
{
Expand Down

0 comments on commit 6a49cb9

Please sign in to comment.