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

Commit

Permalink
Invalidate measure of Label when FormattedText changes (#303)
Browse files Browse the repository at this point in the history
  • Loading branch information
akihikodaki authored and Jason Smith committed Aug 16, 2016
1 parent 414e5d1 commit 966683a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
26 changes: 26 additions & 0 deletions Xamarin.Forms.Core.UnitTests/LabelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,32 @@ public void TextAndAttributedTextMutuallyExclusive ()
Assert.IsNull (label.FormattedText);
}

[Test]
public void InvalidateMeasureWhenTextChanges ()
{
var label = new Label();

bool fired;
label.MeasureInvalidated += (sender, args) =>
{
fired = true;
};

fired = false;
label.Text = "Foo";
Assert.IsTrue (fired);

var fs = new FormattedString ();

fired = false;
label.FormattedText = fs;
Assert.IsTrue (fired);

fired = false;
fs.Spans.Add (new Span {Text = "bar"});
Assert.IsTrue (fired);
}

[Test]
public void AssignToFontStructUpdatesFontFamily (
[Values (NamedSize.Default, NamedSize.Large, NamedSize.Medium, NamedSize.Small, NamedSize.Micro)] NamedSize size,
Expand Down
1 change: 1 addition & 0 deletions Xamarin.Forms.Core/Label.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ static void OnFontSizeChanged(BindableObject bindable, object oldValue, object n

void OnFormattedTextChanged(object sender, PropertyChangedEventArgs e)
{
InvalidateMeasureInternal(InvalidationTrigger.MeasureChanged);
OnPropertyChanged("FormattedText");
}

Expand Down

0 comments on commit 966683a

Please sign in to comment.