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

feat(SplashScreen): sample for uno toolkit control #658

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Resource.Designer.cs

# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
.DS_Store

# Build results
[Dd]ebug[-\w]*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<RuntimeIdentifier Condition="'$(TargetFramework)' == 'net8.0-macos'">osx-x64</RuntimeIdentifier>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Uno.Toolkit.WinUI" Version="5.1.7" />
<PackageReference Include="Uno.WinUI" Version="5.1.87" />
<PackageReference Include="Uno.WinUI.DevServer" Version="5.1.87" Condition="'$(Configuration)'=='Debug'" />
<PackageReference Include="Uno.UI.Adapter.Microsoft.Extensions.Logging" Version="5.1.87" />
Expand Down
5 changes: 3 additions & 2 deletions UI/SplashScreenSample/SplashScreenSample.Shared/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
<!-- Add resource dictionaries here -->
</ResourceDictionary.MergedDictionaries>
<!-- Add resource dictionaries here -->
<ToolkitResources xmlns="using:Uno.Toolkit.UI" />
</ResourceDictionary.MergedDictionaries>
<!-- Add resources here -->
</ResourceDictionary>
</Application.Resources>
Expand Down
34 changes: 30 additions & 4 deletions UI/SplashScreenSample/SplashScreenSample.Shared/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -58,17 +59,14 @@ 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<MainPage>();

rootFrame.NavigationFailed += OnNavigationFailed;

if (args.UWPLaunchActivatedEventArgs.PreviousExecutionState == ApplicationExecutionState.Terminated)
{
// TODO: Load state from previously suspended application
}

// Place the frame in the current Window
_window.Content = rootFrame;
}

#if !(NET6_0_OR_GREATER && WINDOWS)
Expand Down Expand Up @@ -111,6 +109,34 @@ private void OnSuspending(object sender, SuspendingEventArgs e)
deferral.Complete();
}

private Frame WaitWithSplashScreen<T>() where T : Page, new()
{
var shell = new Shell();
if (Shell.IsSplashCapable)
{
_window.Content = shell;

Frame rootFrame = new Frame();
async void PageNavigated(object s, NavigationEventArgs e)
{
await Task.Delay(3000);
_window.Content = rootFrame;
rootFrame.Navigated -= PageNavigated;
};

rootFrame.Navigated += PageNavigated;
rootFrame.Navigate(typeof(T));
return rootFrame;
}
else
{
var page = new T();
Frame rootFrame = new Frame();
rootFrame.Navigate(typeof(T));
return rootFrame;
}
}

/// <summary>
/// Configures global Uno Platform logging
/// </summary>
Expand Down
50 changes: 50 additions & 0 deletions UI/SplashScreenSample/SplashScreenSample.Shared/Shell.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<UserControl
x:Class="SplashScreenSample.Shell"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:SplashScreenSample"
xmlns:utu="using:Uno.Toolkit.UI"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006">

<Grid>
<utu:ExtendedSplashScreen x:Name="Splash"
Platforms="Windows">
<utu:ExtendedSplashScreen.LoadingContentTemplate>
<DataTemplate>
<Grid Padding="0,72" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<StackPanel Spacing="48" Orientation="Vertical">
<!-- Splash Screen Image -->
<Viewbox x:Name="SplashScreenImageViewbox"
Width="270"
Height="185"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Stretch="None">
<Image x:Name="SplashScreenImage"
Source="Assets/SplashScreen.png" />
</Viewbox>

<!-- App Name -->
<TextBlock x:Name="SplashScreenAppName"
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="20"
LineHeight="32">
<Run FontWeight="SemiBold"
Text="SplashScreenSample" />
</TextBlock>

<!-- Loading Indicator -->
<ProgressRing x:Name="SplashScreenLoadingIndicator"
VerticalAlignment="Bottom"
HorizontalAlignment="Center"
IsActive="True"
IsIndeterminate="True" />
</StackPanel>
</Grid>
</DataTemplate>
</utu:ExtendedSplashScreen.LoadingContentTemplate>
</utu:ExtendedSplashScreen>
</Grid>
</UserControl>
23 changes: 23 additions & 0 deletions UI/SplashScreenSample/SplashScreenSample.Shared/Shell.xaml.cs
Original file line number Diff line number Diff line change
@@ -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
{
public static bool IsSplashCapable = false;

public Shell()
{
this.InitializeComponent();
#if NET6_0_OR_GREATER && WINDOWS && !HAS_UNO
IsSplashCapable = true;
#endif
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,16 @@
<Compile Include="$(MSBuildThisFileDirectory)MainPage.xaml.cs">
<DependentUpon>MainPage.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Shell.xaml.cs">
<DependentUpon>Shell.xaml</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<Page Include="$(MSBuildThisFileDirectory)MainPage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Shell.xaml" />
</ItemGroup>
<ItemGroup>
<None Include="$(MSBuildThisFileDirectory)Assets\SharedAssets.md" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
<PackageReference Include="Uno.Toolkit.WinUI" Version="5.1.7" />
<PackageReference Include="Uno.WinUI.Skia.Gtk" Version="5.1.87" />
<PackageReference Include="Uno.WinUI.DevServer" Version="5.1.87" Condition="'$(Configuration)'=='Debug'" />
<PackageReference Include="Uno.UI.Adapter.Microsoft.Extensions.Logging" Version="5.1.87" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<PackageReference Include="Uno.WinUI.DevServer" Version="5.1.87" Condition="'$(Configuration)'=='Debug'" />
<PackageReference Include="Uno.UI.Adapter.Microsoft.Extensions.Logging" Version="5.1.87" />
<PackageReference Include="Uno.WinUI.Lottie" Version="5.1.87" />
<PackageReference Include="Uno.Toolkit.WinUI" Version="5.1.7" />
<PackageReference Include="SkiaSharp.Skottie" Version="2.88.7" />
<PackageReference Include="SkiaSharp.Views.Uno.WinUI" Version="2.88.7" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<PackageReference Include="Uno.WinUI.DevServer" Version="5.1.87" Condition="'$(Configuration)'=='Debug'" />
<PackageReference Include="Uno.UI.Adapter.Microsoft.Extensions.Logging" Version="5.1.87" />
<PackageReference Include="Uno.Wasm.Bootstrap" Version="8.0.11" />
<PackageReference Include="Uno.Toolkit.WinUI" Version="5.1.7" />
<PackageReference Include="Uno.Wasm.Bootstrap.DevServer" Version="8.0.11" />
<PackageReference Include="Uno.WinUI.Lottie" Version="5.1.87" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.3233" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
<PackageReference Include="Uno.Core.Extensions.Logging.Singleton" Version="4.0.1" />
<PackageReference Include="Uno.Toolkit.WinUI" Version="5.1.7" />

<Manifest Include="$(ApplicationManifest)" />
</ItemGroup>
Expand Down