From 9a4e88408b64864e6ca48a82fdf6657b337f8911 Mon Sep 17 00:00:00 2001 From: Martin Zikmund Date: Sat, 9 Apr 2022 19:39:04 +0200 Subject: [PATCH] fix: Adjust ScrollContentPresenter.ViewportWidth/Height on WASM --- .../Given_ScrollViewer.cs | 20 +++++---- .../ScrollContentPresenter.Managed.cs | 2 + .../ScrollContentPresenter.cs | 41 +++++++++++-------- .../ScrollContentPresenter.mux.cs | 2 +- .../ScrollContentPresenter.wasm.cs | 2 + 5 files changed, 39 insertions(+), 28 deletions(-) diff --git a/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_ScrollViewer.cs b/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_ScrollViewer.cs index 755f4050bad4..4755292de856 100644 --- a/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_ScrollViewer.cs +++ b/src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_ScrollViewer.cs @@ -213,8 +213,13 @@ public async Task When_Presenter_Doesnt_Take_Up_All_Space() Assert.AreEqual(ContentWidth - PresenterActualWidth, SUT.ScrollableWidth); ; } - + [TestMethod] +#if __WASM__ + // Issue needs to be fixed first for WASM for Right and Bottom Margin missing + // Details here: https://github.com/unoplatform/uno/issues/7000 + [Ignore] +#endif public async Task When_ScrollViewer_Centered_With_Margin_Inside_Tall_Rectangle() { const int ContentHeight = 300; @@ -243,14 +248,15 @@ public async Task When_ScrollViewer_Centered_With_Margin_Inside_Tall_Rectangle() const double ScrollViewerHeight = ContentHeight + 2 * ContentMargin; await WindowHelper.WaitForEqual(ScrollViewerHeight, () => SUT.ActualHeight); - // Issue needs to be fixed first for WASM for Right and Bottom Margin missing - // Details here: https://github.com/unoplatform/uno/issues/7000 -#if !__WASM__ Assert.AreEqual(ScrollViewerHeight, SUT.ExtentHeight); -#endif } [TestMethod] +#if __WASM__ + // Issue needs to be fixed first for WASM for Right and Bottom Margin missing + // Details here: https://github.com/unoplatform/uno/issues/7000 + [Ignore] +#endif public async Task When_ScrollViewer_Centered_With_Margin_Inside_Wide_Rectangle() { const int ContentWidth = 300; @@ -279,11 +285,7 @@ public async Task When_ScrollViewer_Centered_With_Margin_Inside_Wide_Rectangle() const double ScrollViewerWidth = ContentWidth + 2 * ContentMargin; await WindowHelper.WaitForEqual(ScrollViewerWidth, () => SUT.ActualWidth); - // Issue needs to be fixed first for WASM for Right and Bottom Margin missing - // Details here: https://github.com/unoplatform/uno/issues/7000 -#if !__WASM__ Assert.AreEqual(ScrollViewerWidth, SUT.ExtentWidth); -#endif } [TestMethod] diff --git a/src/Uno.UI/UI/Xaml/Controls/ScrollContentPresenter/ScrollContentPresenter.Managed.cs b/src/Uno.UI/UI/Xaml/Controls/ScrollContentPresenter/ScrollContentPresenter.Managed.cs index a62ff8a9ae4d..42ee9acd98d2 100644 --- a/src/Uno.UI/UI/Xaml/Controls/ScrollContentPresenter/ScrollContentPresenter.Managed.cs +++ b/src/Uno.UI/UI/Xaml/Controls/ScrollContentPresenter/ScrollContentPresenter.Managed.cs @@ -92,6 +92,8 @@ private static double GetHorizontalScrollWheelDelta(Size size, double delta) internal Size? CustomContentExtent => null; + private object RealContent => Content; + partial void InitializePartial() { #if __SKIA__ diff --git a/src/Uno.UI/UI/Xaml/Controls/ScrollContentPresenter/ScrollContentPresenter.cs b/src/Uno.UI/UI/Xaml/Controls/ScrollContentPresenter/ScrollContentPresenter.cs index cd3e5892e45f..34ea5268f173 100644 --- a/src/Uno.UI/UI/Xaml/Controls/ScrollContentPresenter/ScrollContentPresenter.cs +++ b/src/Uno.UI/UI/Xaml/Controls/ScrollContentPresenter/ScrollContentPresenter.cs @@ -54,22 +54,7 @@ public object ScrollOwner } #endregion - private ScrollViewer Scroller => ScrollOwner as ScrollViewer; - - internal object ManagedContent - { - get - { -#if __ANDROID__ || __IOS__ - if (Content is NativeScrollContentPresenter nativePresenter) - { - return nativePresenter.Content; - } -#endif - - return Content; - } - } + private ScrollViewer Scroller => ScrollOwner as ScrollViewer; #if __WASM__ bool _forceChangeToCurrentView; @@ -116,9 +101,29 @@ bool ILayoutConstraints.IsHeightConstrained(View requester) return this.IsHeightConstrainedSimple() ?? (Parent as ILayoutConstraints)?.IsHeightConstrained(this) ?? false; } - public double ViewportHeight => (DesiredSize.Height - Margin.Top - Margin.Bottom); + public double ViewportHeight + { + get + { +#if !__WASM__ + return DesiredSize.Height - Margin.Top - Margin.Bottom; +#else // Issue needs to be fixed first for WASM for Right and Bottom Margin missing https://github.com/unoplatform/uno/issues/7000 + return DesiredSize.Height - Margin.Top; +#endif + } + } - public double ViewportWidth => (DesiredSize.Width - Margin.Left - Margin.Right); + public double ViewportWidth + { + get + { +#if !__WASM__ + return DesiredSize.Width - Margin.Left - Margin.Right; +#else // Issue needs to be fixed first for WASM for Right and Bottom Margin missing https://github.com/unoplatform/uno/issues/7000 + return DesiredSize.Width - Margin.Left; +#endif + } + } #if UNO_HAS_MANAGED_SCROLL_PRESENTER || __WASM__ protected override Size MeasureOverride(Size availableSize) diff --git a/src/Uno.UI/UI/Xaml/Controls/ScrollContentPresenter/ScrollContentPresenter.mux.cs b/src/Uno.UI/UI/Xaml/Controls/ScrollContentPresenter/ScrollContentPresenter.mux.cs index 96859baa9315..7cad691ecb70 100644 --- a/src/Uno.UI/UI/Xaml/Controls/ScrollContentPresenter/ScrollContentPresenter.mux.cs +++ b/src/Uno.UI/UI/Xaml/Controls/ScrollContentPresenter/ScrollContentPresenter.mux.cs @@ -18,7 +18,7 @@ protected override void OnBringIntoViewRequested(BringIntoViewRequestedEventArgs { base.OnBringIntoViewRequested(args); - UIElement content = ManagedContent as UIElement; + UIElement content = RealContent as UIElement; if (args.Handled || args.TargetElement == this || diff --git a/src/Uno.UI/UI/Xaml/Controls/ScrollContentPresenter/ScrollContentPresenter.wasm.cs b/src/Uno.UI/UI/Xaml/Controls/ScrollContentPresenter/ScrollContentPresenter.wasm.cs index 463da9e18fb3..2b7dd087d7d4 100644 --- a/src/Uno.UI/UI/Xaml/Controls/ScrollContentPresenter/ScrollContentPresenter.wasm.cs +++ b/src/Uno.UI/UI/Xaml/Controls/ScrollContentPresenter/ScrollContentPresenter.wasm.cs @@ -35,6 +35,8 @@ internal Size ScrollBarSize } } + private object RealContent => Content; + private void TryRegisterEvents(ScrollBarVisibility visibility) { if (