Skip to content

Commit

Permalink
chore: address pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
kazo0 committed May 30, 2023
1 parent 1633448 commit ebbceea
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 36 deletions.
9 changes: 6 additions & 3 deletions src/Uno.Toolkit.RuntimeTests/Tests/SafeAreaTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Uno.Toolkit.UI;
using Uno.UI.RuntimeTests;
using Windows.System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

#if __IOS__
using UIKit;
Expand All @@ -32,8 +33,6 @@
using Windows.UI.Xaml.Navigation;
using Windows.UI;
using Windows.UI.ViewManagement;
using Microsoft.VisualStudio.TestTools.UnitTesting;

#endif

namespace Uno.Toolkit.RuntimeTests.Tests
Expand Down Expand Up @@ -102,7 +101,9 @@ public async Task Translucent_SystemBars_Dynamic()
var windowWithOpaqueBars = redGrid.TransformToVisual(null).TransformBounds(new Windows.Foundation.Rect(0, 0, redGrid.ActualWidth, redGrid.ActualHeight));
var visibleBoundsWithOpaqueBars = ApplicationView.GetForCurrentView().VisibleBounds;

// before: windowWithOpaqueBars should be at (0, [statusBarHeight]) and the same size as visibleBoundsWithOpaqueBars
using var __ = UseTranslucentBars();
// after: windowWithTranslucentBars should be at (0, 0) and should differ from visibleBoundsWithTranslucentBars in height by [statusBarHeight] + [navAreaHeight]

await UnitTestsUIContentHelper.WaitForIdle();

Expand Down Expand Up @@ -131,8 +132,9 @@ private IDisposable UseTranslucentBars()
activity?.Window?.ClearFlags(Android.Views.WindowManagerFlags.TranslucentNavigation | Android.Views.WindowManagerFlags.TranslucentStatus);
});
}
#endif

// The [RequiresFullWindow] attribute sets the app to fullscreen on Android, hiding all system bars.
// This method maintains the fullscreen state, but shows the system bars for tests that need them.
private IDisposable UseFullWindow()
{
UnitTestsUIContentHelper.UseActualWindowRoot = true;
Expand All @@ -144,5 +146,6 @@ private IDisposable UseFullWindow()
UnitTestsUIContentHelper.UseActualWindowRoot = false;
});
}
#endif
}
}
51 changes: 18 additions & 33 deletions src/Uno.Toolkit.UI/Controls/SafeArea/SafeArea.cs
Original file line number Diff line number Diff line change
Expand Up @@ -560,34 +560,27 @@ private void ApplyInsets(Thickness insets)
{
return;
}
#if __ANDROID__
// Dispatching on Android prevents issues where layout/render changes occurring
// during initial loading of the view are not always properly picked up by the layouting/rendering engine.
var dispatcher = owner.GetDispatcherCompat();
dispatcher.Schedule(() =>
#endif
if (_insetMode == InsetMode.Padding &&
!PaddingHelper.GetPadding(owner).Equals(insets) &&
PaddingHelper.SetPadding(owner, insets))
{
_appliedPadding = insets;
LogApplyInsets();
}
else if (_insetMode == InsetMode.Margin)
{
if (_insetMode == InsetMode.Padding &&
!PaddingHelper.GetPadding(owner).Equals(insets) &&
PaddingHelper.SetPadding(owner, insets))
if (!owner.Margin.Equals(insets))
{
_appliedPadding = insets;
_appliedMargin = insets;
owner.Margin = insets;
LogApplyInsets();
}
else if (_insetMode == InsetMode.Margin)
{
if (!owner.Margin.Equals(insets))
{
_appliedMargin = insets;
owner.Margin = insets;
LogApplyInsets();
}
}
owner.InvalidateMeasure();
}

#if __ANDROID__
);
// Dispatching on Android prevents issues where layout/render changes occurring
// during initial loading of the view are not always properly picked up by the layouting/rendering engine.
owner.GetDispatcherCompat().Schedule(owner.InvalidateMeasure);
#endif
void LogApplyInsets()
{
Expand Down Expand Up @@ -661,13 +654,6 @@ internal void OnInsetModeChanged(InsetMode oldValue, InsetMode newValue)

if (Owner is { } owner)
{
#if __ANDROID__
// Dispatching on Android prevents issues where layout/render changes occurring
// during initial loading of the view are not always properly picked up by the layouting/rendering engine.
var dispatcher = owner.GetDispatcherCompat();
dispatcher.Schedule(() =>
#endif
{
if (oldValue == InsetMode.Margin)
{
_appliedMargin = new Thickness(0);
Expand All @@ -678,11 +664,10 @@ internal void OnInsetModeChanged(InsetMode oldValue, InsetMode newValue)
_appliedPadding = new Thickness(0);
PaddingHelper.SetPadding(owner, _originalPadding);
}
owner.InvalidateMeasure();
}
#if __ANDROID__
);
// Dispatching on Android prevents issues where layout/render changes occurring
// during initial loading of the view are not always properly picked up by the layouting/rendering engine.
owner.GetDispatcherCompat().Schedule(owner.InvalidateMeasure);
#endif
}
UpdateInsets();
Expand Down

0 comments on commit ebbceea

Please sign in to comment.