Skip to content

Commit

Permalink
perf: Update IsTextTrimmed lazily on WASM
Browse files Browse the repository at this point in the history
  • Loading branch information
ebariche committed Feb 28, 2024
1 parent 30d3cb1 commit 0bca5fc
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
40 changes: 37 additions & 3 deletions src/Uno.UI/UI/Xaml/Controls/TextBlock/TextBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -706,10 +706,31 @@ private void OnTextDecorationsChanged()
#endregion

#region DependencyProperty: IsTextTrimmed
private TypedEventHandler<TextBlock, IsTextTrimmedChangedEventArgs> _isTextTrimmedChanged;

#if false || false || IS_UNIT_TESTS || false || false || __NETSTD_REFERENCE__ || __MACOS__
[NotImplemented("IS_UNIT_TESTS", "__NETSTD_REFERENCE__", "__MACOS__")]
#endif
public event TypedEventHandler<TextBlock, IsTextTrimmedChangedEventArgs> IsTextTrimmedChanged;
public event TypedEventHandler<TextBlock, IsTextTrimmedChangedEventArgs> IsTextTrimmedChanged
{
add
{
#if __WASM__
if (!_shouldUpdateIsTextTrimmed)
{
UpdateIsTextTrimmed();

_shouldUpdateIsTextTrimmed = true;
}
#endif

_isTextTrimmedChanged += value;
}
remove
{
_isTextTrimmedChanged -= value;
}
}

#if false || false || IS_UNIT_TESTS || false || false || __NETSTD_REFERENCE__ || __MACOS__
[NotImplemented("IS_UNIT_TESTS", "__NETSTD_REFERENCE__", "__MACOS__")]
Expand All @@ -725,14 +746,27 @@ private void OnTextDecorationsChanged()
#endif
public bool IsTextTrimmed
{
get => (bool)GetValue(IsTextTrimmedProperty);
get
{
#if __WASM__
if (!_shouldUpdateIsTextTrimmed)
{
UpdateIsTextTrimmed();

_shouldUpdateIsTextTrimmed = true;
}
#endif

return (bool)GetValue(IsTextTrimmedProperty);
}

private set => SetValue(IsTextTrimmedProperty, value);
}

private void OnIsTextTrimmedChanged()
{
OnIsTextTrimmedChangedPartial();
IsTextTrimmedChanged?.Invoke(this, new());
_isTextTrimmedChanged?.Invoke(this, new());
}

partial void OnIsTextTrimmedChangedPartial();
Expand Down
7 changes: 6 additions & 1 deletion src/Uno.UI/UI/Xaml/Controls/TextBlock/TextBlock.wasm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ partial class TextBlock : FrameworkElement
private bool _textWrappingChanged;
private bool _paddingChangedChanged;

private bool _shouldUpdateIsTextTrimmed;

public TextBlock() : base("p")
{
SetDefaultForeground(ForegroundProperty);
Expand Down Expand Up @@ -165,7 +167,10 @@ internal override void OnLayoutUpdated()
{
base.OnLayoutUpdated();

UpdateIsTextTrimmed();
if (_shouldUpdateIsTextTrimmed)
{
UpdateIsTextTrimmed();
}
}

partial void OnFontStyleChangedPartial() => _fontStyleChanged = true;
Expand Down

0 comments on commit 0bca5fc

Please sign in to comment.