Skip to content

Commit

Permalink
Merge pull request #2979 from PrismLibrary/dev/ds/uno-splash-support
Browse files Browse the repository at this point in the history
  • Loading branch information
dansiegel authored Oct 10, 2023
2 parents e6170f8 + 22ab59f commit 17b9843
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 16 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,7 @@ FakesAssemblies/
.mfractor/

# Jetbrains files
.idea*
.idea*

# Binlog
*.binlog
53 changes: 39 additions & 14 deletions e2e/Uno/HelloWorld/Views/Shell.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,52 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:pr="using:Prism.Navigation.Regions"
xmlns:pvm="using:Prism.Mvvm"
xmlns:toolkit="using:Uno.Toolkit.UI"
pvm:ViewModelLocator.AutowireViewModel="true"
xmlns:local="using:HelloWorld.Views"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" >

<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<StackPanel Margin="20"
<toolkit:ExtendedSplashScreen x:Name="Splash"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch">
<toolkit:ExtendedSplashScreen.LoadingContentTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="2*" />
<RowDefinition />
</Grid.RowDefinitions>

<ProgressRing IsActive="True"
Grid.Row="1"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Height="100"
Width="100" />
</Grid>
</DataTemplate>
</toolkit:ExtendedSplashScreen.LoadingContentTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<StackPanel Margin="20"
HorizontalAlignment="Center"
Spacing="15">
<Image Source="ms-appx:///HelloWorld/Assets/prism.png"
<Image Source="ms-appx:///HelloWorld/Assets/prism.png"
MaxHeight="80"/>
<TextBlock Text="{Binding Title}" FontSize="30" />
<StackPanel Orientation="Horizontal"
<TextBlock Text="{Binding Title}" FontSize="30" />
<StackPanel Orientation="Horizontal"
Spacing="15">
<Button Command="{Binding NavigateCommand}" CommandParameter="ViewA">Navigate to View A</Button>
<Button Command="{Binding NavigateCommand}" CommandParameter="ViewB">Navigate to View B</Button>
<Button Command="{Binding NavigateCommand}" CommandParameter="ViewA">Navigate to View A</Button>
<Button Command="{Binding NavigateCommand}" CommandParameter="ViewB">Navigate to View B</Button>
</StackPanel>
</StackPanel>
</StackPanel>
<ContentControl Grid.Row="1" pr:RegionManager.RegionName="ContentRegion" />
</Grid>
<ContentControl Grid.Row="1" pr:RegionManager.RegionName="ContentRegion" />
</Grid>
</toolkit:ExtendedSplashScreen>

</Page>
10 changes: 9 additions & 1 deletion e2e/Uno/HelloWorld/Views/Shell.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
using Uno.Toolkit;

namespace HelloWorld.Views;

/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class Shell : Page
public sealed partial class Shell : Page, ILoadableShell
{
public Shell()
{
this.InitializeComponent();
}

public ILoadable Source
{
get => Splash.Source;
set => Splash.Source = value;
}
}
Binary file removed e2e/Uno/HelloWorld/msbuild.binlog
Binary file not shown.
9 changes: 9 additions & 0 deletions src/Uno/Prism.Uno/ILoadableShell.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Uno.Toolkit;

namespace Prism;

#nullable enable
public interface ILoadableShell
{
ILoadable Source { get; set; }
}
1 change: 1 addition & 0 deletions src/Uno/Prism.Uno/Prism.Uno.WinUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Uno.Toolkit.WinUI" />
<PackageReference Include="Uno.WinUI" />
<PackageReference Include="Uno.Extensions.Hosting.WinUI" />
</ItemGroup>
Expand Down
10 changes: 10 additions & 0 deletions src/Uno/Prism.Uno/PrismApplicationBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Prism.Modularity;
using Prism.Mvvm;
using Prism.Navigation.Regions;
using Uno.Toolkit;
using Application = Microsoft.UI.Xaml.Application;

#nullable enable
Expand Down Expand Up @@ -122,9 +123,16 @@ protected virtual void Initialize(IApplicationBuilder builder)

RegisterFrameworkExceptionTypes();

var loadable = new PrismShellLoadable();
var shell = CreateShell();

if (shell != null)
{
if (shell is ILoadableShell loadableShell)
{
loadableShell.Source = loadable;
}

MvvmHelpers.AutowireViewModel(shell);
builder.Window.Content = shell;
builder.Window.Activate();
Expand All @@ -136,6 +144,8 @@ void FinalizeInitialization()
_host = builder.Build();
InitializeModules();
OnInitialized();
loadable.FinishLoading();
MvvmHelpers.ViewAndViewModelAction<IActiveAware>(shell, x => x.IsActive = true);
}

if (shell is FrameworkElement fe)
Expand Down
20 changes: 20 additions & 0 deletions src/Uno/Prism.Uno/PrismShellLoadable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace Prism;

#nullable enable
internal sealed class PrismShellLoadable : Uno.ILoadable, Uno.Toolkit.ILoadable
{
public bool IsExecuting { get; private set; } = true;

public bool IsLoaded { get; private set; }

public event EventHandler? IsExecutingChanged;
public event EventHandler<EventArgs>? Loaded;

public void FinishLoading()
{
IsExecuting = false;
IsLoaded = true;
IsExecutingChanged?.Invoke(this, EventArgs.Empty);
Loaded?.Invoke(this, EventArgs.Empty);
}
}

0 comments on commit 17b9843

Please sign in to comment.