From 718d35da2e42968e5712530bac8d2fda3492c220 Mon Sep 17 00:00:00 2001 From: Luke Blevins Date: Wed, 10 Apr 2024 09:08:37 -0400 Subject: [PATCH 1/5] chore: Add Uno.Toolkit.WinUI package references to projects --- .../SplashScreenSample.Mobile/SplashScreenSample.Mobile.csproj | 1 + .../SplashScreenSample.Skia.Gtk.csproj | 1 + .../SplashScreenSample.Skia.WPF.csproj | 1 + .../SplashScreenSample.Wasm/SplashScreenSample.Wasm.csproj | 1 + .../SplashScreenSample.Windows/SplashScreenSample.Windows.csproj | 1 + 5 files changed, 5 insertions(+) diff --git a/UI/SplashScreenSample/SplashScreenSample.Mobile/SplashScreenSample.Mobile.csproj b/UI/SplashScreenSample/SplashScreenSample.Mobile/SplashScreenSample.Mobile.csproj index f82bf9976..04eab427b 100644 --- a/UI/SplashScreenSample/SplashScreenSample.Mobile/SplashScreenSample.Mobile.csproj +++ b/UI/SplashScreenSample/SplashScreenSample.Mobile/SplashScreenSample.Mobile.csproj @@ -14,6 +14,7 @@ osx-x64 + diff --git a/UI/SplashScreenSample/SplashScreenSample.Skia.Gtk/SplashScreenSample.Skia.Gtk.csproj b/UI/SplashScreenSample/SplashScreenSample.Skia.Gtk/SplashScreenSample.Skia.Gtk.csproj index 330411d48..9f80ac7d0 100644 --- a/UI/SplashScreenSample/SplashScreenSample.Skia.Gtk/SplashScreenSample.Skia.Gtk.csproj +++ b/UI/SplashScreenSample/SplashScreenSample.Skia.Gtk/SplashScreenSample.Skia.Gtk.csproj @@ -16,6 +16,7 @@ + diff --git a/UI/SplashScreenSample/SplashScreenSample.Skia.WPF/SplashScreenSample.Skia.WPF.csproj b/UI/SplashScreenSample/SplashScreenSample.Skia.WPF/SplashScreenSample.Skia.WPF.csproj index d3356143a..19ef31d08 100644 --- a/UI/SplashScreenSample/SplashScreenSample.Skia.WPF/SplashScreenSample.Skia.WPF.csproj +++ b/UI/SplashScreenSample/SplashScreenSample.Skia.WPF/SplashScreenSample.Skia.WPF.csproj @@ -22,6 +22,7 @@ + diff --git a/UI/SplashScreenSample/SplashScreenSample.Wasm/SplashScreenSample.Wasm.csproj b/UI/SplashScreenSample/SplashScreenSample.Wasm/SplashScreenSample.Wasm.csproj index a008a4d41..f38454406 100644 --- a/UI/SplashScreenSample/SplashScreenSample.Wasm/SplashScreenSample.Wasm.csproj +++ b/UI/SplashScreenSample/SplashScreenSample.Wasm/SplashScreenSample.Wasm.csproj @@ -48,6 +48,7 @@ + diff --git a/UI/SplashScreenSample/SplashScreenSample.Windows/SplashScreenSample.Windows.csproj b/UI/SplashScreenSample/SplashScreenSample.Windows/SplashScreenSample.Windows.csproj index 92b13b122..e2d8c9914 100644 --- a/UI/SplashScreenSample/SplashScreenSample.Windows/SplashScreenSample.Windows.csproj +++ b/UI/SplashScreenSample/SplashScreenSample.Windows/SplashScreenSample.Windows.csproj @@ -28,6 +28,7 @@ + From 691110b308db338959c74b89e1c58861a5a8f093 Mon Sep 17 00:00:00 2001 From: Luke Blevins Date: Wed, 10 Apr 2024 09:09:06 -0400 Subject: [PATCH 2/5] fix: .DS_Store file being tracked with .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 3698cd9b4..596f1ee67 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,7 @@ Resource.Designer.cs # User-specific files (MonoDevelop/Xamarin Studio) *.userprefs +.DS_Store # Build results [Dd]ebug[-\w]*/ From 2f744f6a07201054f6a12e3b533b3bb1b0781555 Mon Sep 17 00:00:00 2001 From: Luke Blevins Date: Wed, 10 Apr 2024 09:11:14 -0400 Subject: [PATCH 3/5] feat: Add Shell control to the SplashScreenSample project --- .../SplashScreenSample.Shared/Shell.xaml | 51 +++++++++++++++++++ .../SplashScreenSample.Shared/Shell.xaml.cs | 23 +++++++++ .../SplashScreenSample.Shared.projitems | 4 ++ 3 files changed, 78 insertions(+) create mode 100644 UI/SplashScreenSample/SplashScreenSample.Shared/Shell.xaml create mode 100644 UI/SplashScreenSample/SplashScreenSample.Shared/Shell.xaml.cs diff --git a/UI/SplashScreenSample/SplashScreenSample.Shared/Shell.xaml b/UI/SplashScreenSample/SplashScreenSample.Shared/Shell.xaml new file mode 100644 index 000000000..824f64cf0 --- /dev/null +++ b/UI/SplashScreenSample/SplashScreenSample.Shared/Shell.xaml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/UI/SplashScreenSample/SplashScreenSample.Shared/Shell.xaml.cs b/UI/SplashScreenSample/SplashScreenSample.Shared/Shell.xaml.cs new file mode 100644 index 000000000..f58f32181 --- /dev/null +++ b/UI/SplashScreenSample/SplashScreenSample.Shared/Shell.xaml.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Controls.Primitives; + +namespace SplashScreenSample +{ + public sealed partial class Shell : UserControl + { +#if NET6_0_OR_GREATER && WINDOWS && !HAS_UNO + public bool IsSplashCapable => true; +#else + public bool IsSplashCapable => false; +#endif + public Shell() + { + this.InitializeComponent(); + } + } +} \ No newline at end of file diff --git a/UI/SplashScreenSample/SplashScreenSample.Shared/SplashScreenSample.Shared.projitems b/UI/SplashScreenSample/SplashScreenSample.Shared/SplashScreenSample.Shared.projitems index 79adaaed7..78b20123e 100644 --- a/UI/SplashScreenSample/SplashScreenSample.Shared/SplashScreenSample.Shared.projitems +++ b/UI/SplashScreenSample/SplashScreenSample.Shared/SplashScreenSample.Shared.projitems @@ -21,12 +21,16 @@ MainPage.xaml + + Shell.xaml + Designer MSBuild:Compile + From 07937a36fa292e83f0234476d38772718c1b877d Mon Sep 17 00:00:00 2001 From: Luke Blevins Date: Wed, 10 Apr 2024 09:12:01 -0400 Subject: [PATCH 4/5] feat(SplashScreenSample): Refactor App.xaml.cs to use Shell control --- .../SplashScreenSample.Shared/App.xaml.cs | 33 ++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/UI/SplashScreenSample/SplashScreenSample.Shared/App.xaml.cs b/UI/SplashScreenSample/SplashScreenSample.Shared/App.xaml.cs index f65f68694..35395902a 100644 --- a/UI/SplashScreenSample/SplashScreenSample.Shared/App.xaml.cs +++ b/UI/SplashScreenSample/SplashScreenSample.Shared/App.xaml.cs @@ -58,7 +58,7 @@ protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs ar if (rootFrame == null) { // Create a Frame to act as the navigation context and navigate to the first page - rootFrame = new Frame(); + rootFrame = WaitWithSplashScreen(); rootFrame.NavigationFailed += OnNavigationFailed; @@ -66,9 +66,6 @@ protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs ar { // TODO: Load state from previously suspended application } - - // Place the frame in the current Window - _window.Content = rootFrame; } #if !(NET6_0_OR_GREATER && WINDOWS) @@ -111,6 +108,34 @@ private void OnSuspending(object sender, SuspendingEventArgs e) deferral.Complete(); } + private Frame WaitWithSplashScreen() where T : Page, new() + { + var shell = new Shell(); + if (shell.IsSplashCapable) + { + _window.Content = shell; + var page = new T(); + + Frame rootFrame = new Frame(); + void PageLoad(object s, RoutedEventArgs e) + { + _window.Content = rootFrame; + page.Loaded -= PageLoad; + }; + + page.Loaded += PageLoad; + rootFrame.Content = page; + return rootFrame; + } + else + { + var page = new T(); + Frame rootFrame = new Frame(); + rootFrame.Navigate(typeof(T)); + return rootFrame; + } + } + /// /// Configures global Uno Platform logging /// From b4ff949e3902b517fc32bb13f1b54b98a87a9ace Mon Sep 17 00:00:00 2001 From: Luke Blevins Date: Wed, 10 Apr 2024 11:00:07 -0400 Subject: [PATCH 5/5] fix: toolkit splash control resources --- .../SplashScreenSample.Shared/App.xaml | 5 +++-- .../SplashScreenSample.Shared/App.xaml.cs | 13 +++++++------ .../SplashScreenSample.Shared/Shell.xaml | 9 ++++----- .../SplashScreenSample.Shared/Shell.xaml.cs | 10 +++++----- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/UI/SplashScreenSample/SplashScreenSample.Shared/App.xaml b/UI/SplashScreenSample/SplashScreenSample.Shared/App.xaml index c9c900926..7361f11c2 100644 --- a/UI/SplashScreenSample/SplashScreenSample.Shared/App.xaml +++ b/UI/SplashScreenSample/SplashScreenSample.Shared/App.xaml @@ -8,8 +8,9 @@ - - + + + diff --git a/UI/SplashScreenSample/SplashScreenSample.Shared/App.xaml.cs b/UI/SplashScreenSample/SplashScreenSample.Shared/App.xaml.cs index 35395902a..39708dbb7 100644 --- a/UI/SplashScreenSample/SplashScreenSample.Shared/App.xaml.cs +++ b/UI/SplashScreenSample/SplashScreenSample.Shared/App.xaml.cs @@ -3,6 +3,7 @@ using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Navigation; using System; +using System.Threading.Tasks; using Windows.ApplicationModel; using Windows.ApplicationModel.Activation; @@ -111,20 +112,20 @@ private void OnSuspending(object sender, SuspendingEventArgs e) private Frame WaitWithSplashScreen() where T : Page, new() { var shell = new Shell(); - if (shell.IsSplashCapable) + if (Shell.IsSplashCapable) { _window.Content = shell; - var page = new T(); Frame rootFrame = new Frame(); - void PageLoad(object s, RoutedEventArgs e) + async void PageNavigated(object s, NavigationEventArgs e) { + await Task.Delay(3000); _window.Content = rootFrame; - page.Loaded -= PageLoad; + rootFrame.Navigated -= PageNavigated; }; - page.Loaded += PageLoad; - rootFrame.Content = page; + rootFrame.Navigated += PageNavigated; + rootFrame.Navigate(typeof(T)); return rootFrame; } else diff --git a/UI/SplashScreenSample/SplashScreenSample.Shared/Shell.xaml b/UI/SplashScreenSample/SplashScreenSample.Shared/Shell.xaml index 824f64cf0..a38bac723 100644 --- a/UI/SplashScreenSample/SplashScreenSample.Shared/Shell.xaml +++ b/UI/SplashScreenSample/SplashScreenSample.Shared/Shell.xaml @@ -12,13 +12,13 @@ Platforms="Windows"> - - + + diff --git a/UI/SplashScreenSample/SplashScreenSample.Shared/Shell.xaml.cs b/UI/SplashScreenSample/SplashScreenSample.Shared/Shell.xaml.cs index f58f32181..6a3b040ff 100644 --- a/UI/SplashScreenSample/SplashScreenSample.Shared/Shell.xaml.cs +++ b/UI/SplashScreenSample/SplashScreenSample.Shared/Shell.xaml.cs @@ -10,14 +10,14 @@ namespace SplashScreenSample { public sealed partial class Shell : UserControl { -#if NET6_0_OR_GREATER && WINDOWS && !HAS_UNO - public bool IsSplashCapable => true; -#else - public bool IsSplashCapable => false; -#endif + public static bool IsSplashCapable = false; + public Shell() { this.InitializeComponent(); +#if NET6_0_OR_GREATER && WINDOWS && !HAS_UNO + IsSplashCapable = true; +#endif } } } \ No newline at end of file