Skip to content

Commit

Permalink
fix: safe area scrollviewer calc
Browse files Browse the repository at this point in the history
  • Loading branch information
kazo0 committed Oct 30, 2023
1 parent a8c7fca commit 820de78
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/Uno.Toolkit.UI/Controls/SafeArea/SafeArea.cs
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ internal class SafeAreaDetails
private Thickness _appliedPadding = new Thickness(0);
private Thickness _appliedMargin = new Thickness(0);
private readonly CompositeDisposable _subscriptions = new();
private ScrollViewer? _scrollAncestor;

internal SafeAreaDetails(FrameworkElement owner)
{
Expand Down Expand Up @@ -347,6 +348,14 @@ private void RegisterEvents()
inputPane.Hiding -= OnInputPaneChanged;
});
}

if (GetScrollAncestor() is { } scrollAncestor)
{
_scrollAncestor = scrollAncestor;

_scrollAncestor.SizeChanged += OnInsetUpdateRequired;
_subscriptions.Add(() => _scrollAncestor.SizeChanged -= OnInsetUpdateRequired);
}
}

private void Unregister()
Expand Down Expand Up @@ -420,20 +429,18 @@ private void UpdateInsets()

if (windowPadding != default)
{
var scrollAncestor = GetScrollAncestor();

// If the owner view is scrollable, the visibility of interest is that of the scroll viewport.
var fixedControl = scrollAncestor ?? Owner;
var fixedControl = _scrollAncestor ?? Owner;

// Using relativeTo: null instead of Window.Current.Content since there are cases when the current UIElement
// may be outside the bounds of the current Window content, for example, when the element is hosted in a modal window.
var controlBounds = GetRelativeBounds(fixedControl, relativeTo: null);

visibilityPadding = CalculateVisibilityInsets(OffsetVisibleBounds, controlBounds);

if (scrollAncestor != null)
if (_scrollAncestor is { } scrollViewer)
{
visibilityPadding = AdjustScrollableInsets(visibilityPadding, scrollAncestor);
visibilityPadding = AdjustScrollableInsets(visibilityPadding, scrollViewer);
}
}
else
Expand Down

0 comments on commit 820de78

Please sign in to comment.