Skip to content

Commit

Permalink
Add test harness to support XAML hot reload (#478)
Browse files Browse the repository at this point in the history
* Add test harness to support XAML hot reload.

* Make the apps run on WinUI.
  • Loading branch information
davidbritch committed Jun 11, 2024
1 parent 78bbe66 commit 1b8cd57
Show file tree
Hide file tree
Showing 40 changed files with 1,032 additions and 493 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
<UseMaui>true</UseMaui>
<MauiEnablePlatformUsings>true</MauiEnablePlatformUsings>

<!-- Visual Studio doesn't support Hot Reload in non-MAUI apps -->
<EnableHotReload>false</EnableHotReload>

<ApplicationId>com.companyname.nativeembeddingdemo</ApplicationId>
<ApplicationVersion>1</ApplicationVersion>
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0-maccatalyst</TargetFramework>
Expand All @@ -9,6 +9,9 @@
<SupportedOSPlatformVersion>14.2</SupportedOSPlatformVersion>
<UseMaui>true</UseMaui>
<MauiEnablePlatformUsings>true</MauiEnablePlatformUsings>

<!-- Visual Studio doesn't support Hot Reload in non-MAUI apps -->
<EnableHotReload>false</EnableHotReload>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
<UseMaui>true</UseMaui>
<MauiEnablePlatformUsings>true</MauiEnablePlatformUsings>
<EnableDefaultMauiItems>false</EnableDefaultMauiItems>

<!-- Visual Studio doesn't support Hot Reload in non-MAUI apps -->
<EnableHotReload>false</EnableHotReload>
</PropertyGroup>

<ItemGroup>
Expand All @@ -30,7 +33,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.4.230913002" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.240428000" />
<Manifest Include="$(ApplicationManifest)" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
<SupportedOSPlatformVersion>13.0</SupportedOSPlatformVersion>
<UseMaui>true</UseMaui>
<MauiEnablePlatformUsings>true</MauiEnablePlatformUsings>

<!-- Visual Studio doesn't support Hot Reload in non-MAUI apps -->
<EnableHotReload>false</EnableHotReload>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NativeEmbeddingDemo.Library
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NativeEmbeddingDemo.Droid", "NativeEmbeddingDemo.Droid\NativeEmbeddingDemo.Droid.csproj", "{76B43FBB-1DEA-4260-8802-7DC0015A916F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NativeEmbeddingDemo.MacCatalyst", "NativeEmbeddingDemo.MacCatalyst\NativeEmbeddingDemo.MacCatalyst.csproj", "{A63220BF-4101-4D60-A75D-CF2693646A6A}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NativeEmbeddingDemo.MacCatalyst", "NativeEmbeddingDemo.MacCatalyst\NativeEmbeddingDemo.MacCatalyst.csproj", "{A63220BF-4101-4D60-A75D-CF2693646A6A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestHarnessApp", "TestHarnessApp\TestHarnessApp.csproj", "{B14E3633-E1E0-4CD7-A2BC-E8FE76F53560}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -163,6 +165,23 @@ Global
{A63220BF-4101-4D60-A75D-CF2693646A6A}.Release|x86.ActiveCfg = Release|Any CPU
{A63220BF-4101-4D60-A75D-CF2693646A6A}.Release|x86.Build.0 = Release|Any CPU
{A63220BF-4101-4D60-A75D-CF2693646A6A}.Release|x86.Deploy.0 = Release|Any CPU
{B14E3633-E1E0-4CD7-A2BC-E8FE76F53560}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B14E3633-E1E0-4CD7-A2BC-E8FE76F53560}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B14E3633-E1E0-4CD7-A2BC-E8FE76F53560}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
{B14E3633-E1E0-4CD7-A2BC-E8FE76F53560}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{B14E3633-E1E0-4CD7-A2BC-E8FE76F53560}.Debug|ARM64.Build.0 = Debug|Any CPU
{B14E3633-E1E0-4CD7-A2BC-E8FE76F53560}.Debug|x64.ActiveCfg = Debug|Any CPU
{B14E3633-E1E0-4CD7-A2BC-E8FE76F53560}.Debug|x64.Build.0 = Debug|Any CPU
{B14E3633-E1E0-4CD7-A2BC-E8FE76F53560}.Debug|x86.ActiveCfg = Debug|Any CPU
{B14E3633-E1E0-4CD7-A2BC-E8FE76F53560}.Debug|x86.Build.0 = Debug|Any CPU
{B14E3633-E1E0-4CD7-A2BC-E8FE76F53560}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B14E3633-E1E0-4CD7-A2BC-E8FE76F53560}.Release|Any CPU.Build.0 = Release|Any CPU
{B14E3633-E1E0-4CD7-A2BC-E8FE76F53560}.Release|ARM64.ActiveCfg = Release|Any CPU
{B14E3633-E1E0-4CD7-A2BC-E8FE76F53560}.Release|ARM64.Build.0 = Release|Any CPU
{B14E3633-E1E0-4CD7-A2BC-E8FE76F53560}.Release|x64.ActiveCfg = Release|Any CPU
{B14E3633-E1E0-4CD7-A2BC-E8FE76F53560}.Release|x64.Build.0 = Release|Any CPU
{B14E3633-E1E0-4CD7-A2BC-E8FE76F53560}.Release|x86.ActiveCfg = Release|Any CPU
{B14E3633-E1E0-4CD7-A2BC-E8FE76F53560}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
<?xml version = "1.0" encoding = "UTF-8" ?>
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:NativeEmbeddingDemo"
x:Class="NativeEmbeddingDemo.App">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources/Styles/Colors.xaml" />
<ResourceDictionary Source="Resources/Styles/Styles.xaml" />
<ResourceDictionary Source="Resources/Styles/Colors.xaml;assembly=NativeEmbeddingDemo" />
<ResourceDictionary Source="Resources/Styles/Styles.xaml;assembly=NativeEmbeddingDemo" />
</ResourceDictionary.MergedDictionaries>

<!-- Example styles to demonstrate how to use main app vs test app styles -->
<Style x:Key="MainAppOnlyStyle" TargetType="VisualElement" ApplyToDerivedTypes="True">
</Style>
<Style x:Key="TestAppOnlyStyle" TargetType="VisualElement" ApplyToDerivedTypes="True">
<Setter Property="IsVisible" Value="False" />
</Style>

</ResourceDictionary>
</Application.Resources>
</Application>
Original file line number Diff line number Diff line change
@@ -1,26 +1,39 @@
using Microsoft.Extensions.Logging;

namespace NativeEmbeddingDemo
namespace NativeEmbeddingDemo;

public static class MauiProgram
{
public static class MauiProgram
/// <summary>
/// Create a new MauiApp using the default application.
/// </summary>
/// <param name="additional"></param>
/// <returns></returns>
public static MauiApp CreateMauiApp(Action<MauiAppBuilder>? additional = null) =>
CreateMauiApp<App>(additional);

/// <summary>
/// Create a new MauiAPp using the specified application.
/// </summary>
/// <typeparam name="TApp"></typeparam>
/// <param name="additional"></param>
/// <returns></returns>
public static MauiApp CreateMauiApp<TApp>(Action<MauiAppBuilder>? additional = null) where TApp : App
{
public static MauiApp CreateMauiApp(Action<MauiAppBuilder>? additional = null)
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
});
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<TApp>()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
});

#if DEBUG
builder.Logging.AddDebug();
builder.Logging.AddDebug();
#endif
additional?.Invoke(builder);
additional?.Invoke(builder);

return builder.Build();
}
return builder.Build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,15 @@
SemanticProperties.Hint="Counts the number of times you click"
Clicked="OnCounterClicked"
HorizontalOptions="Fill" />

<Label Text="This is a MAIN app only feature!"
HorizontalOptions="Center"
Style="{StaticResource MainAppOnlyStyle}"
SemanticProperties.HeadingLevel="Level2" />

<Label Text="This is a TEST app only feature!"
HorizontalOptions="Center"
Style="{StaticResource TestAppOnlyStyle}"
SemanticProperties.HeadingLevel="Level2" />
</VerticalStackLayout>
</ContentView>
Original file line number Diff line number Diff line change
@@ -1,45 +1,43 @@
<?xml version="1.0" encoding="UTF-8" ?>
<?xaml-comp compile="true" ?>
<ResourceDictionary
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">

<!-- Note: For Android please see also Platforms\Android\Resources\values\colors.xml -->

<Color x:Key="Primary">#512BD4</Color>
<Color x:Key="PrimaryDark">#ac99ea</Color>
<Color x:Key="PrimaryDarkText">#242424</Color>
<Color x:Key="Secondary">#DFD8F7</Color>
<Color x:Key="SecondaryDarkText">#9880e5</Color>
<Color x:Key="Tertiary">#2B0B98</Color>

<Color x:Key="White">White</Color>
<Color x:Key="Black">Black</Color>
<Color x:Key="Magenta">#D600AA</Color>
<Color x:Key="MidnightBlue">#190649</Color>
<Color x:Key="OffBlack">#1f1f1f</Color>

<Color x:Key="Gray100">#E1E1E1</Color>
<Color x:Key="Gray200">#C8C8C8</Color>
<Color x:Key="Gray300">#ACACAC</Color>
<Color x:Key="Gray400">#919191</Color>
<Color x:Key="Gray500">#6E6E6E</Color>
<Color x:Key="Gray600">#404040</Color>
<Color x:Key="Gray900">#212121</Color>
<Color x:Key="Gray950">#141414</Color>

<SolidColorBrush x:Key="PrimaryBrush" Color="{StaticResource Primary}"/>
<SolidColorBrush x:Key="SecondaryBrush" Color="{StaticResource Secondary}"/>
<SolidColorBrush x:Key="TertiaryBrush" Color="{StaticResource Tertiary}"/>
<SolidColorBrush x:Key="WhiteBrush" Color="{StaticResource White}"/>
<SolidColorBrush x:Key="BlackBrush" Color="{StaticResource Black}"/>

<SolidColorBrush x:Key="Gray100Brush" Color="{StaticResource Gray100}"/>
<SolidColorBrush x:Key="Gray200Brush" Color="{StaticResource Gray200}"/>
<SolidColorBrush x:Key="Gray300Brush" Color="{StaticResource Gray300}"/>
<SolidColorBrush x:Key="Gray400Brush" Color="{StaticResource Gray400}"/>
<SolidColorBrush x:Key="Gray500Brush" Color="{StaticResource Gray500}"/>
<SolidColorBrush x:Key="Gray600Brush" Color="{StaticResource Gray600}"/>
<SolidColorBrush x:Key="Gray900Brush" Color="{StaticResource Gray900}"/>
<SolidColorBrush x:Key="Gray950Brush" Color="{StaticResource Gray950}"/>
</ResourceDictionary>
<?xml version="1.0" encoding="utf-8" ?>
<ResourceDictionary xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="NativeEmbeddingDemo.Resources.Styles.Colors">
<!-- Note: For Android please see also Platforms\Android\Resources\values\colors.xml -->

<Color x:Key="Primary">#512BD4</Color>
<Color x:Key="PrimaryDark">#ac99ea</Color>
<Color x:Key="PrimaryDarkText">#242424</Color>
<Color x:Key="Secondary">#DFD8F7</Color>
<Color x:Key="SecondaryDarkText">#9880e5</Color>
<Color x:Key="Tertiary">#2B0B98</Color>

<Color x:Key="White">White</Color>
<Color x:Key="Black">Black</Color>
<Color x:Key="Magenta">#D600AA</Color>
<Color x:Key="MidnightBlue">#190649</Color>
<Color x:Key="OffBlack">#1f1f1f</Color>

<Color x:Key="Gray100">#E1E1E1</Color>
<Color x:Key="Gray200">#C8C8C8</Color>
<Color x:Key="Gray300">#ACACAC</Color>
<Color x:Key="Gray400">#919191</Color>
<Color x:Key="Gray500">#6E6E6E</Color>
<Color x:Key="Gray600">#404040</Color>
<Color x:Key="Gray900">#212121</Color>
<Color x:Key="Gray950">#141414</Color>

<SolidColorBrush x:Key="PrimaryBrush" Color="{StaticResource Primary}"/>
<SolidColorBrush x:Key="SecondaryBrush" Color="{StaticResource Secondary}"/>
<SolidColorBrush x:Key="TertiaryBrush" Color="{StaticResource Tertiary}"/>
<SolidColorBrush x:Key="WhiteBrush" Color="{StaticResource White}"/>
<SolidColorBrush x:Key="BlackBrush" Color="{StaticResource Black}"/>

<SolidColorBrush x:Key="Gray100Brush" Color="{StaticResource Gray100}"/>
<SolidColorBrush x:Key="Gray200Brush" Color="{StaticResource Gray200}"/>
<SolidColorBrush x:Key="Gray300Brush" Color="{StaticResource Gray300}"/>
<SolidColorBrush x:Key="Gray400Brush" Color="{StaticResource Gray400}"/>
<SolidColorBrush x:Key="Gray500Brush" Color="{StaticResource Gray500}"/>
<SolidColorBrush x:Key="Gray600Brush" Color="{StaticResource Gray600}"/>
<SolidColorBrush x:Key="Gray900Brush" Color="{StaticResource Gray900}"/>
<SolidColorBrush x:Key="Gray950Brush" Color="{StaticResource Gray950}"/>
</ResourceDictionary>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace NativeEmbeddingDemo.Resources.Styles;

public partial class Colors : ResourceDictionary
{
public Colors()
{
InitializeComponent();
}
}

0 comments on commit 1b8cd57

Please sign in to comment.