Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ShadowContainer on wasm wasn't repainting when unloaded then loaded #1183

Merged
merged 5 commits into from
Jul 31, 2024

Conversation

ramezgerges
Copy link
Contributor

@ramezgerges ramezgerges commented Jul 10, 2024

GitHub Issue (If applicable): closes unoplatform/uno#17366

PR Type

What kind of change does this PR introduce?

What is the current behavior?

What is the new behavior?

PR Checklist

Please check if your PR fulfills the following requirements:

Other information

Internal Issue (If applicable):

@ramezgerges
Copy link
Contributor Author

Not sure who to ping, maybe @kazo0. Is there a way to add a UI test in Toolkit? RenderTargetBitmap isn't available on WASm, so adding runtime tests that do image comparisons is not feasible.

For reference, here's a small repro as a diff that can be converted to a test. When the rectangle unloads and loads again, the shadow disappears, which shouldn't happen.

Index: samples/Uno.Toolkit.Samples/Uno.Toolkit.Samples.Shared/App.xaml.cs
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/samples/Uno.Toolkit.Samples/Uno.Toolkit.Samples.Shared/App.xaml.cs b/samples/Uno.Toolkit.Samples/Uno.Toolkit.Samples.Shared/App.xaml.cs
--- a/samples/Uno.Toolkit.Samples/Uno.Toolkit.Samples.Shared/App.xaml.cs	(revision e07a955a412551c1357ec6c55cf3c4b761c5111a)
+++ b/samples/Uno.Toolkit.Samples/Uno.Toolkit.Samples.Shared/App.xaml.cs	(date 1720649215271)
@@ -1,7 +1,10 @@
 using Microsoft.Extensions.Logging;
+using Microsoft.UI.Dispatching;
+using Microsoft.UI.Xaml.Shapes;
 using System;
 using System.Globalization;
 using System.Threading.Tasks;
+using Uno.Extensions;
 using Uno.Toolkit.UI;
 using Uno.UI;
 using Windows.ApplicationModel;
@@ -117,7 +120,29 @@
 				// This is to allow the splash/loading view to start to render, before we finishing building shell etc
 				await Task.Yield();
 
-				splash.Content = _shell = BuildShell();
+				var sc = new ShadowContainer()
+				{
+					Shadows = new ShadowCollection().Apply(sc => sc.Add(new Uno.Toolkit.UI.Shadow() { BlurRadius = 50, Color = Microsoft.UI.Colors.FromARGB("#928F99"), Opacity = 0.5 })),
+					Content = new Rectangle()
+					{
+						Width = 100,
+						Height = 100,
+						Fill = new SolidColorBrush(Microsoft.UI.Colors.Red)
+					}
+				};
+				splash.Content = sc;
+
+				DispatcherQueue.GetForCurrentThread().TryEnqueue(DispatcherQueuePriority.Low, async () =>
+				{
+					await Task.Delay(1000);
+					splash.Content = null;
+					DispatcherQueue.GetForCurrentThread().TryEnqueue(DispatcherQueuePriority.Low, async () =>
+					{
+						await Task.Delay(1000);
+						splash.Content = sc;
+					});
+				});
+
 				loadable.IsExecuting = false;
 			}
 

@kazo0
Copy link
Contributor

kazo0 commented Jul 10, 2024

Not sure who to ping, maybe @kazo0. Is there a way to add a UI test in Toolkit? RenderTargetBitmap isn't available on WASm, so adding runtime tests that do image comparisons is not feasible.

For reference, here's a small repro as a diff that can be converted to a test. When the rectangle unloads and loads again, the shadow disappears, which shouldn't happen.

Index: samples/Uno.Toolkit.Samples/Uno.Toolkit.Samples.Shared/App.xaml.cs
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/samples/Uno.Toolkit.Samples/Uno.Toolkit.Samples.Shared/App.xaml.cs b/samples/Uno.Toolkit.Samples/Uno.Toolkit.Samples.Shared/App.xaml.cs
--- a/samples/Uno.Toolkit.Samples/Uno.Toolkit.Samples.Shared/App.xaml.cs	(revision e07a955a412551c1357ec6c55cf3c4b761c5111a)
+++ b/samples/Uno.Toolkit.Samples/Uno.Toolkit.Samples.Shared/App.xaml.cs	(date 1720649215271)
@@ -1,7 +1,10 @@
 using Microsoft.Extensions.Logging;
+using Microsoft.UI.Dispatching;
+using Microsoft.UI.Xaml.Shapes;
 using System;
 using System.Globalization;
 using System.Threading.Tasks;
+using Uno.Extensions;
 using Uno.Toolkit.UI;
 using Uno.UI;
 using Windows.ApplicationModel;
@@ -117,7 +120,29 @@
 				// This is to allow the splash/loading view to start to render, before we finishing building shell etc
 				await Task.Yield();
 
-				splash.Content = _shell = BuildShell();
+				var sc = new ShadowContainer()
+				{
+					Shadows = new ShadowCollection().Apply(sc => sc.Add(new Uno.Toolkit.UI.Shadow() { BlurRadius = 50, Color = Microsoft.UI.Colors.FromARGB("#928F99"), Opacity = 0.5 })),
+					Content = new Rectangle()
+					{
+						Width = 100,
+						Height = 100,
+						Fill = new SolidColorBrush(Microsoft.UI.Colors.Red)
+					}
+				};
+				splash.Content = sc;
+
+				DispatcherQueue.GetForCurrentThread().TryEnqueue(DispatcherQueuePriority.Low, async () =>
+				{
+					await Task.Delay(1000);
+					splash.Content = null;
+					DispatcherQueue.GetForCurrentThread().TryEnqueue(DispatcherQueuePriority.Low, async () =>
+					{
+						await Task.Delay(1000);
+						splash.Content = sc;
+					});
+				});
+
 				loadable.IsExecuting = false;
 			}
 

@ramezgerges You should be able add UI Tests here: https://github.com/unoplatform/uno.toolkit.ui/blob/main/src/Uno.Toolkit.UITest/Controls/ShadowContainer/Given_ShadowContainer.cs

@ramezgerges ramezgerges force-pushed the shadowcontainer_canvas_disappears_wasm branch 2 times, most recently from 88621e3 to 14299d6 Compare July 11, 2024 14:20
@ramezgerges ramezgerges force-pushed the shadowcontainer_canvas_disappears_wasm branch from 14299d6 to f938b3f Compare July 11, 2024 14:57
@kazo0
Copy link
Contributor

kazo0 commented Jul 17, 2024

@ramezgerges it looks like the test you added is failing. I believe because its failing to navigate to your test page. We have to do some funky hacks for the ShadowContainer tests since it is only available in WinUI and not UWP.

you may need to add the ShadowContainerTestPage2 page

here:

<Compile Include="$(MSBuildThisFileDirectory)Content\TestPages\ShadowContainerTestPage.WinUI.xaml.cs" />

and here:

<Page Include="$(MSBuildThisFileDirectory)Content\Controls\ShadowContainerSamplePage.WinUI.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>

@ramezgerges
Copy link
Contributor Author

@kazo0 Most likely not, but it's an invalidation issue, so anything with a "this thing should show but it doesn't" problem could be affected.

@kazo0 kazo0 enabled auto-merge (squash) July 30, 2024 13:19
@kazo0 kazo0 merged commit 3d2632a into main Jul 31, 2024
25 checks passed
@kazo0 kazo0 deleted the shadowcontainer_canvas_disappears_wasm branch July 31, 2024 16:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Gallery][Wasm][Home Page] Dropdown menu from Navigation Bar appears without background table.
3 participants