Skip to content

Commit

Permalink
feat: Naive implementation of UIElement.UpdateLayout
Browse files Browse the repository at this point in the history
  • Loading branch information
dr1rrb committed Nov 16, 2020
1 parent 9b19af3 commit af4370f
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Uno.UI/Generated/3.0.0.0/Windows.UI.Xaml/UIElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1156,7 +1156,7 @@ public void InvalidateArrange()
global::Windows.Foundation.Metadata.ApiInformation.TryRaiseNotImplemented("Windows.UI.Xaml.UIElement", "void UIElement.InvalidateArrange()");
}
#endif
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
#if false
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "NET461", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public void UpdateLayout()
{
Expand Down
46 changes: 46 additions & 0 deletions src/Uno.UI/UI/Xaml/UIElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,52 @@ private void OpenContextFlyout(object sender, RightTappedRoutedEventArgs args)

internal bool IsRenderingSuspended { get; set; }

[ThreadStatic]
private static bool _isInUpdateLayout;

private const int MaxLayoutIterations = 250;

public void UpdateLayout()
{
if (_isInUpdateLayout)
{
return;
}

var root = Window.Current.RootElement;
if (root is null)
{
return;
}

try
{
_isInUpdateLayout = true;

for (var i = 0; i < MaxLayoutIterations; i++)
{
if (root.IsMeasureDirty)
{
root.Measure(LayoutInformation.GetLayoutSlot(root).Size);
}
else if (root.IsArrangeDirty)
{
root.Arrange(LayoutInformation.GetLayoutSlot(root));
}
else
{
return;
}
}

throw new InvalidOperationException("Layout cycle detected.");
}
finally
{
_isInUpdateLayout = false;
}
}

internal void ApplyClip()
{
Rect rect;
Expand Down

0 comments on commit af4370f

Please sign in to comment.