diff --git a/samples/Uno.Toolkit.Samples/Uno.Toolkit.Samples.Shared/Content/Controls/ShadowContainerSamplePage.WinUI.xaml b/samples/Uno.Toolkit.Samples/Uno.Toolkit.Samples.Shared/Content/Controls/ShadowContainerSamplePage.WinUI.xaml
index fb34c882c..a0f368ad9 100644
--- a/samples/Uno.Toolkit.Samples/Uno.Toolkit.Samples.Shared/Content/Controls/ShadowContainerSamplePage.WinUI.xaml
+++ b/samples/Uno.Toolkit.Samples/Uno.Toolkit.Samples.Shared/Content/Controls/ShadowContainerSamplePage.WinUI.xaml
@@ -125,13 +125,8 @@
BorderBrush="{StaticResource CardStrokeColorDefaultBrush}"
CornerRadius="20"
BorderThickness="1">
-
-
-
-
-
-
-
+
+
@@ -178,8 +173,8 @@
-
-
+
+
-
+
-
-
-
-
+
-
-
-
+
-
-
-
+
-
-
-
+
-
-
-
-
-
-
-
+
+
+
+
-
-
-
+
-
-
-
+
-
-
-
+
-
-
-
+
-
-
-
-
+
+
-
-
-
-
+
-
-
-
+
-
-
-
+
-
-
-
+
-
-
-
-
+
-
-
-
+
+
-
-
-
-
+
-
-
-
+
-
-
-
+
-
-
-
+
-
-
-
-
+
-
-
-
+
+
-
-
-
-
+
-
-
-
+
@@ -767,11 +762,11 @@
-
-
-
+
-
-
-
+
-
-
-
+
-
-
-
+
-
-
-
+
-
-
-
+
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/samples/Uno.Toolkit.Samples/Uno.Toolkit.Samples.Shared/Content/Controls/ShadowContainerSamplePage.WinUI.xaml.cs b/samples/Uno.Toolkit.Samples/Uno.Toolkit.Samples.Shared/Content/Controls/ShadowContainerSamplePage.WinUI.xaml.cs
index d404d680d..1b7993b4a 100644
--- a/samples/Uno.Toolkit.Samples/Uno.Toolkit.Samples.Shared/Content/Controls/ShadowContainerSamplePage.WinUI.xaml.cs
+++ b/samples/Uno.Toolkit.Samples/Uno.Toolkit.Samples.Shared/Content/Controls/ShadowContainerSamplePage.WinUI.xaml.cs
@@ -22,7 +22,7 @@ public ShadowContainerSamplePage()
{
_shadows = shadowContainer.Shadows;
- var shadowsItemsControl = SamplePageLayout.GetSampleChild(Design.Agnostic, "ShadowsItemsControl");
+ var shadowsItemsControl = SamplePageLayout.GetSampleChild(Design.Agnostic, "ShadowsItemsControl");
shadowsItemsControl.ItemsSource = _shadows;
}
};
diff --git a/src/Uno.Toolkit.RuntimeTests/Tests/ShadowContainerTests.cs b/src/Uno.Toolkit.RuntimeTests/Tests/ShadowContainerTests.cs
index 5f0eff0b1..943e88c97 100644
--- a/src/Uno.Toolkit.RuntimeTests/Tests/ShadowContainerTests.cs
+++ b/src/Uno.Toolkit.RuntimeTests/Tests/ShadowContainerTests.cs
@@ -17,9 +17,6 @@
using Windows.Storage;
using System.IO;
using System.Runtime.InteropServices.WindowsRuntime;
-
-
-
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Media;
@@ -113,7 +110,6 @@ public async Task Displays_Content_With_Margin()
await renderer.AssertColorAt(Colors.Green, 75, 225);
}
-#if !(__ANDROID__ || __IOS__)
[TestMethod]
[DataRow(10, 10, false)]
[DataRow(10, 10, true)]
diff --git a/src/Uno.Toolkit.Skia.WinUI/Controls/Shadows/ShadowContainer.cs b/src/Uno.Toolkit.Skia.WinUI/Controls/Shadows/ShadowContainer.cs
index 9f992ea6d..c8bd133fc 100644
--- a/src/Uno.Toolkit.Skia.WinUI/Controls/Shadows/ShadowContainer.cs
+++ b/src/Uno.Toolkit.Skia.WinUI/Controls/Shadows/ShadowContainer.cs
@@ -3,6 +3,7 @@
using System.Collections.Specialized;
using System.ComponentModel;
using System.Linq;
+using System.Threading.Tasks;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Media;
@@ -32,7 +33,7 @@ public partial class ShadowContainer : ContentControl
private static readonly ShadowsCache Cache = new ShadowsCache();
private readonly SerialDisposable _eventSubscriptions = new();
-
+
private Grid? _panel;
private Canvas? _canvas;
private SKXamlCanvas? _shadowHost;
@@ -256,9 +257,26 @@ protected override void OnApplyTemplate()
private void InvalidateCanvasLayout()
{
if (Content is not FrameworkElement contentAsFE ||
- _panel == null ||
- _canvas == null ||
- _shadowHost == null)
+ _panel == null ||
+ _canvas == null ||
+ _shadowHost == null)
+ {
+ return;
+ }
+
+#if __ANDROID__ || __IOS__
+ this.GetDispatcherCompat().Schedule(() => InvalidateCanvasLayoutSize());
+#else
+ InvalidateCanvasLayoutSize();
+#endif
+
+ }
+ private void InvalidateCanvasLayoutSize()
+ {
+ if (Content is not FrameworkElement contentAsFE ||
+ _panel == null ||
+ _canvas == null ||
+ _shadowHost == null)
{
return;
}
@@ -270,6 +288,10 @@ private void InvalidateCanvasLayout()
return;
}
+
+#if __ANDROID__ || __IOS__
+ _canvas.GetDispatcherCompat().Schedule(() => _canvas.InvalidateMeasure());
+#endif
double absoluteMaxOffsetX = 0;
double absoluteMaxOffsetY = 0;
double maxBlurRadius = 0;
@@ -280,82 +302,35 @@ private void InvalidateCanvasLayout()
absoluteMaxOffsetX = shadows.Max(s => Math.Abs(s.OffsetX));
absoluteMaxOffsetY = shadows.Max(s => Math.Abs(s.OffsetY));
maxBlurRadius = shadows.Max(s => s.BlurRadius);
- maxSpread = shadows.Max(s => s.Spread);
+ maxSpread = shadows.Max(s => Math.Abs(s.Spread));
}
- // _canvas.Height = childHeight;
- // _canvas.Width = childWidth;
- //#if __ANDROID__ || __IOS__
- // _canvas.GetDispatcherCompat().Schedule(() => _canvas.InvalidateMeasure());
- //#endif
- // double newHostHeight = childHeight + maxBlurRadius * 2 + absoluteMaxOffsetY * 2 + maxSpread * 2;
- // double newHostWidth = childWidth + maxBlurRadius * 2 + absoluteMaxOffsetX * 2 + maxSpread * 2;
- // _shadowHost.Height = newHostHeight;
- // _shadowHost.Width = newHostWidth;
-
- // double diffWidthShadowHostChild = newHostWidth - childWidth;
- // double diffHeightShadowHostChild = newHostHeight - childHeight;
-
- // float left = (float)(-diffWidthShadowHostChild / 2 + contentAsFE.Margin.Left);
- // float top = (float)(-diffHeightShadowHostChild / 2 + contentAsFE.Margin.Top);
-
- _canvas.Width = Math.Max(contentAsFE.ActualWidth - contentAsFE.Margin.Left - contentAsFE.Margin.Right, 0);
- _canvas.Height = Math.Max(contentAsFE.ActualHeight - contentAsFE.Margin.Top - contentAsFE.Margin.Bottom, 0);
-
- _canvas.HorizontalAlignment = contentAsFE.HorizontalAlignment;
- _canvas.VerticalAlignment = contentAsFE.VerticalAlignment;
-
double newHostSpreedHeight = maxBlurRadius + absoluteMaxOffsetY + maxSpread;
double newHostSpreedWidth = maxBlurRadius + absoluteMaxOffsetX + maxSpread;
- double newHostHeight = contentAsFE.ActualHeight + newHostSpreedHeight * 2;
- double newHostWidth = contentAsFE.ActualWidth + newHostSpreedWidth * 2;
-
+ double newHostHeight = childHeight + newHostSpreedHeight * 2;
+ double newHostWidth = childWidth + newHostSpreedWidth * 2;
_shadowHost.Height = newHostHeight;
_shadowHost.Width = newHostWidth;
+ _canvas.Height = childHeight / 2;
+ _canvas.Width = childWidth / 2;
+ _canvas.Margin = contentAsFE.Margin;
+ _canvas.HorizontalAlignment = contentAsFE.HorizontalAlignment;
+ _canvas.VerticalAlignment = contentAsFE.VerticalAlignment;
- double top = 0;
- double left = 0;
- if (contentAsFE.VerticalAlignment == VerticalAlignment.Center)
- {
- _canvas.Margin = contentAsFE.Margin;
- _canvas.Margin = contentAsFE.Margin;
- if (contentAsFE.Margin == new Thickness(0, 0, 0, 0))
- {
- left = -newHostSpreedWidth;
- top = -newHostSpreedHeight;
- }
- else
- {
- left = -newHostSpreedWidth
- - (contentAsFE.HorizontalAlignment == HorizontalAlignment.Left ? 0 : 0)
- - (contentAsFE.HorizontalAlignment == HorizontalAlignment.Right ? contentAsFE.ActualWidth : 0)
- - (contentAsFE.HorizontalAlignment == HorizontalAlignment.Stretch ? +contentAsFE.Margin.Left / 2 + contentAsFE.Margin.Right / 2 : 0)
- - (contentAsFE.HorizontalAlignment == HorizontalAlignment.Center ? contentAsFE.ActualWidth / 2 : 0)
-
- ;
- top = -newHostSpreedHeight - contentAsFE.ActualHeight / 2;
- }
+ double left =
+ +(contentAsFE.HorizontalAlignment == HorizontalAlignment.Left ? -newHostSpreedWidth : 0)
+ + (contentAsFE.HorizontalAlignment == HorizontalAlignment.Right ? -newHostSpreedWidth - childWidth / 2 : 0)
+ + (contentAsFE.HorizontalAlignment == HorizontalAlignment.Stretch ? -newHostSpreedWidth - childWidth / 4 : 0)
+ + (contentAsFE.HorizontalAlignment == HorizontalAlignment.Center ? -newHostSpreedWidth - childWidth / 4 : 0);
+ double top =
+ +(contentAsFE.VerticalAlignment == VerticalAlignment.Top ? -newHostSpreedHeight : 0)
+ + (contentAsFE.VerticalAlignment == VerticalAlignment.Bottom ? -newHostSpreedHeight - childHeight / 2 : 0)
+ + (contentAsFE.VerticalAlignment == VerticalAlignment.Stretch ? -newHostSpreedHeight - childHeight / 4 : 0)
+ + (contentAsFE.VerticalAlignment == VerticalAlignment.Center ? -newHostSpreedHeight - childHeight / 4 : 0);
- }
- else
- {
- left = -(newHostSpreedWidth
- + (contentAsFE.HorizontalAlignment == HorizontalAlignment.Left ? -contentAsFE.Margin.Left : 0)
- + (contentAsFE.HorizontalAlignment == HorizontalAlignment.Right && contentAsFE.VerticalAlignment != VerticalAlignment.Center ? contentAsFE.Margin.Right == 0 ? 0 :
- contentAsFE.ActualWidth + contentAsFE.Margin.Right - _canvas.Margin.Right : 0)
- + (contentAsFE.HorizontalAlignment == HorizontalAlignment.Stretch ? contentAsFE.Margin.Right : 0)
- + (contentAsFE.HorizontalAlignment == HorizontalAlignment.Center ? contentAsFE.Margin.Left : 0)
- );
- top = -(newHostSpreedHeight
- + (contentAsFE.VerticalAlignment == VerticalAlignment.Top ? -contentAsFE.Margin.Top : 0)
- + (contentAsFE.VerticalAlignment == VerticalAlignment.Bottom ? +contentAsFE.Margin.Bottom + contentAsFE.ActualHeight : 0)
- + (contentAsFE.VerticalAlignment == VerticalAlignment.Stretch ? contentAsFE.Margin.Bottom : 0)
- + (contentAsFE.VerticalAlignment == VerticalAlignment.Center ? contentAsFE.Margin.Top : 0)
- );
- }
Canvas.SetLeft(_shadowHost, left);
Canvas.SetTop(_shadowHost, top);
}