Skip to content

Commit

Permalink
fix: VisibleBoundsPadding was setting Padding too late.
Browse files Browse the repository at this point in the history
This was causing some layout problems, specially in TextBlock when the `UseLayoutManager` was activated. It was set on `LayoutUpdated`, which was a little too late.  Setting it on `Loaded` instead fixed the problem.
  • Loading branch information
carldebilly committed Mar 24, 2020
1 parent d349323 commit e4c5e1a
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions src/Uno.UI/Behaviors/VisibleBoundsPadding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,11 @@ internal VisibleBoundsDetails(FrameworkElement owner)

_visibleBoundsChanged = (s2, e2) => UpdatePadding();

owner.LayoutUpdated += (s, e) => UpdatePadding();
owner.Loaded += (s, e) => ApplicationView.GetForCurrentView().VisibleBoundsChanged += _visibleBoundsChanged;
owner.Loaded += (s, e) =>
{
UpdatePadding();
ApplicationView.GetForCurrentView().VisibleBoundsChanged += _visibleBoundsChanged;
};
owner.Unloaded += (s, e) => ApplicationView.GetForCurrentView().VisibleBoundsChanged -= _visibleBoundsChanged;
}

Expand All @@ -164,6 +167,11 @@ private void UpdatePadding()
return;
}

if (!Owner.IsLoaded)
{
return;
}

Thickness visibilityPadding;

if (WindowPadding != default(Thickness))
Expand Down Expand Up @@ -269,18 +277,9 @@ private Thickness CalculateAppliedPadding(PaddingMask mask, Thickness visibility

private void ApplyPadding(Thickness padding)
{
#if __IOS__
// Requeue the set of padding to prevent bugs with text alignment like
// defined in this issue: https://github.com/unoplatform/uno/issues/2836
Owner.Dispatcher.RunAsync(CoreDispatcherPriority.High, Set);

void Set()
#endif
if (Owner.SetPadding(padding) && _log.Value.IsEnabled(LogLevel.Debug))
{
if (Owner.SetPadding(padding) && _log.Value.IsEnabled(LogLevel.Debug))
{
_log.Value.LogDebug($"ApplyPadding={padding}");
}
_log.Value.LogDebug($"ApplyPadding={padding}");
}
}

Expand Down

0 comments on commit e4c5e1a

Please sign in to comment.