feat: Add Uno.WinUI compatibility for net5-windows

This commit is contained in:
Jerome Laban 2021-04-12 15:43:57 -04:00
Родитель a8e8ebac81
Коммит c04b549360
10 изменённых файлов: 49 добавлений и 31 удалений

Просмотреть файл

@ -252,6 +252,9 @@
<Move SourceFiles=".\uno.winui.targets" DestinationFiles=".\$(PackageNamePrefix).targets" Condition="'$(UNO_UWP_BUILD)'=='true'"/> <Move SourceFiles=".\uno.winui.targets" DestinationFiles=".\$(PackageNamePrefix).targets" Condition="'$(UNO_UWP_BUILD)'=='true'"/>
<XmlUpdate XmlFileName=".\Uno.WinUI.nuspec" XPath="/x:package/x:files/x:file[@src='Uno.WinUI.targets']/@src" Value="$(PackageNamePrefix).targets" Namespace="$(NugetNamespace)" Prefix="x" Condition="'$(UNO_UWP_BUILD)'=='true'"/> <XmlUpdate XmlFileName=".\Uno.WinUI.nuspec" XPath="/x:package/x:files/x:file[@src='Uno.WinUI.targets']/@src" Value="$(PackageNamePrefix).targets" Namespace="$(NugetNamespace)" Prefix="x" Condition="'$(UNO_UWP_BUILD)'=='true'"/>
<!-- Adjust for net5-windows -->
<XmlUpdate XmlFileName=".\Uno.WinUI.nuspec" XPath="/x:package/x:files/x:file[@src='..\src\Uno.UI.Toolkit\bin\Release\$winuisourcepath$\Uno.UI.Toolkit\**']/@src" Value="..\src\Uno.UI.Toolkit\bin\Release\$winuisourcepath$\Themes\**" Namespace="$(NugetNamespace)" Prefix="x" Condition="'$(UNO_UWP_BUILD)'!='true'"/>
<!-- Adjust build targets file for UAP --> <!-- Adjust build targets file for UAP -->
<XmlUpdate XmlFileName=".\Uno.WinUI.nuspec" XPath="/x:package/x:files/x:file[@target='buildTransitive\uap10.0.16299\uno.winui.targets']/@target" Value="buildTransitive\uap10.0.16299\$(PackageNamePrefix).targets" Namespace="$(NugetNamespace)" Prefix="x" Condition="'$(UNO_UWP_BUILD)'=='true'"/> <XmlUpdate XmlFileName=".\Uno.WinUI.nuspec" XPath="/x:package/x:files/x:file[@target='buildTransitive\uap10.0.16299\uno.winui.targets']/@target" Value="buildTransitive\uap10.0.16299\$(PackageNamePrefix).targets" Namespace="$(NugetNamespace)" Prefix="x" Condition="'$(UNO_UWP_BUILD)'=='true'"/>
<XmlUpdate XmlFileName=".\Uno.WinUI.nuspec" XPath="/x:package/x:files/x:file[@target='buildTransitive\uap10.0.17763\uno.winui.targets']/@target" Value="buildTransitive\uap10.0.17763\$(PackageNamePrefix).targets" Namespace="$(NugetNamespace)" Prefix="x" Condition="'$(UNO_UWP_BUILD)'=='true'"/> <XmlUpdate XmlFileName=".\Uno.WinUI.nuspec" XPath="/x:package/x:files/x:file[@target='buildTransitive\uap10.0.17763\uno.winui.targets']/@target" Value="buildTransitive\uap10.0.17763\$(PackageNamePrefix).targets" Namespace="$(NugetNamespace)" Prefix="x" Condition="'$(UNO_UWP_BUILD)'=='true'"/>
@ -304,6 +307,9 @@
<Target Name="BuildNuGetPackage"> <Target Name="BuildNuGetPackage">
<PropertyGroup> <PropertyGroup>
<NuSpecProperties>NoWarn=NU5100,NU5105,NU5131;branch=$(GITVERSION_BranchName);commitid=$(GITVERSION_VersionSourceSha)</NuSpecProperties> <NuSpecProperties>NoWarn=NU5100,NU5105,NU5131;branch=$(GITVERSION_BranchName);commitid=$(GITVERSION_VersionSourceSha)</NuSpecProperties>
<NuSpecProperties Condition="'$(UNO_UWP_BUILD)'=='true'">$(NuSpecProperties);winuisourcepath=uap10.0.17763;winuitargetpath=UAP</NuSpecProperties>
<NuSpecProperties Condition="'$(UNO_UWP_BUILD)'!='true'">$(NuSpecProperties);winuisourcepath=net5.0-windows10.0.18362.0;winuitargetpath=net5.0-windows10.0.18362.0</NuSpecProperties>
</PropertyGroup> </PropertyGroup>
<!-- Create the packages --> <!-- Create the packages -->

Просмотреть файл

@ -135,10 +135,10 @@
<files> <files>
<!-- UAP --> <!-- UAP -->
<file src="..\src\Uno.UI.Toolkit\bin\Release\uap10.0.17763\Uno.UI.Toolkit.dll" target="lib\UAP" /> <file src="..\src\Uno.UI.Toolkit\bin\Release\$winuisourcepath$\Uno.UI.Toolkit*.dll" target="lib\$winuitargetpath$" />
<file src="..\src\Uno.UI.Toolkit\bin\Release\uap10.0.17763\Uno.UI.Toolkit.pdb" target="lib\UAP" /> <file src="..\src\Uno.UI.Toolkit\bin\Release\$winuisourcepath$\Uno.UI.Toolkit*.pdb" target="lib\$winuitargetpath$" />
<file src="..\src\Uno.UI.Toolkit\bin\Release\uap10.0.17763\Uno.UI.Toolkit.pri" target="lib\UAP" /> <file src="..\src\Uno.UI.Toolkit\bin\Release\$winuisourcepath$\Uno.UI.Toolkit*.pri" target="lib\$winuitargetpath$" />
<file src="..\src\Uno.UI.Toolkit\bin\Release\uap10.0.17763\Uno.UI.Toolkit\**" target="lib\UAP\Uno.UI.Toolkit" /> <file src="..\src\Uno.UI.Toolkit\bin\Release\$winuisourcepath$\Uno.UI.Toolkit\**" target="lib\$winuitargetpath$\Uno.UI.Toolkit" />
<!-- Android 9.0 --> <!-- Android 9.0 -->
<file src="..\src\Uno.UI\Bin\Release\MonoAndroid11.0\Uno.dll" target="lib\MonoAndroid11.0" /> <file src="..\src\Uno.UI\Bin\Release\MonoAndroid11.0\Uno.dll" target="lib\MonoAndroid11.0" />
@ -297,6 +297,7 @@
<!-- Force UAP to ignore netstandard 2.0 --> <!-- Force UAP to ignore netstandard 2.0 -->
<file src="uno.winui.uap.targets" target="buildTransitive\uap10.0.16299\uno.winui.targets" /> <file src="uno.winui.uap.targets" target="buildTransitive\uap10.0.16299\uno.winui.targets" />
<file src="uno.winui.uap.targets" target="buildTransitive\uap10.0.17763\uno.winui.targets" /> <file src="uno.winui.uap.targets" target="buildTransitive\uap10.0.17763\uno.winui.targets" />
<file src="uno.winui.uap.targets" target="buildTransitive\net5.0-windows\uno.winui.targets" />
<file src="..\src\SourceGenerators\Uno.UI.SourceGenerators\Content\Uno.UI.SourceGenerators.props" target="buildTransitive" /> <file src="..\src\SourceGenerators\Uno.UI.SourceGenerators\Content\Uno.UI.SourceGenerators.props" target="buildTransitive" />
</files> </files>

Просмотреть файл

@ -1,4 +1,4 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
using Windows.UI.Xaml; using Windows.UI.Xaml;

Просмотреть файл

@ -1,4 +1,4 @@
using System; using System;
using Windows.UI; using Windows.UI;
using Windows.UI.Xaml; using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Controls;
@ -20,7 +20,7 @@ namespace Uno.UI.Toolkit
[TemplatePart(Name = "PART_Border", Type = typeof(Border))] [TemplatePart(Name = "PART_Border", Type = typeof(Border))]
[TemplatePart(Name = "PART_ShadowHost", Type = typeof(Grid))] [TemplatePart(Name = "PART_ShadowHost", Type = typeof(Grid))]
public sealed partial class ElevatedView : Control public sealed partial class ElevatedView : Control
#if !NETFX_CORE #if !NETFX_CORE && !NETCOREAPP
, ICustomClippingElement , ICustomClippingElement
#endif #endif
{ {
@ -59,7 +59,7 @@ namespace Uno.UI.Toolkit
{ {
DefaultStyleKey = typeof(ElevatedView); DefaultStyleKey = typeof(ElevatedView);
#if !NETFX_CORE #if !NETFX_CORE && !NETCOREAPP
Loaded += (snd, evt) => SynchronizeContentTemplatedParent(); Loaded += (snd, evt) => SynchronizeContentTemplatedParent();
// Patch to deactivate the clipping by ContentControl // Patch to deactivate the clipping by ContentControl
@ -114,7 +114,7 @@ namespace Uno.UI.Toolkit
set => SetValue(ElevatedContentProperty, value); set => SetValue(ElevatedContentProperty, value);
} }
#if !NETFX_CORE #if !NETFX_CORE && !NETCOREAPP
public new static DependencyProperty BackgroundProperty { get ; } = DependencyProperty.Register( public new static DependencyProperty BackgroundProperty { get ; } = DependencyProperty.Register(
"Background", "Background",
typeof(Brush), typeof(Brush),
@ -178,7 +178,7 @@ namespace Uno.UI.Toolkit
return; // not initialized yet return; // not initialized yet
} }
#if !NETFX_CORE #if !NETFX_CORE && !NETCOREAPP
SynchronizeContentTemplatedParent(); SynchronizeContentTemplatedParent();
#endif #endif
@ -197,13 +197,13 @@ namespace Uno.UI.Toolkit
// The elevation must be applied on the border, since // The elevation must be applied on the border, since
// it will get the right shape (with rounded corners) // it will get the right shape (with rounded corners)
_border.SetElevationInternal(Elevation, ShadowColor); _border.SetElevationInternal(Elevation, ShadowColor);
#elif NETFX_CORE #elif NETFX_CORE || NETCOREAPP
(ElevatedContent as DependencyObject).SetElevationInternal(Elevation, ShadowColor, _shadowHost as DependencyObject, CornerRadius); (ElevatedContent as DependencyObject).SetElevationInternal(Elevation, ShadowColor, _shadowHost as DependencyObject, CornerRadius);
#endif #endif
} }
} }
#if !NETFX_CORE #if !NETFX_CORE && !NETCOREAPP
bool ICustomClippingElement.AllowClippingToLayoutSlot => false; // Never clip, since it will remove the shadow bool ICustomClippingElement.AllowClippingToLayoutSlot => false; // Never clip, since it will remove the shadow
bool ICustomClippingElement.ForceClippingToLayoutSlot => false; bool ICustomClippingElement.ForceClippingToLayoutSlot => false;

Просмотреть файл

@ -1,4 +1,4 @@
#if !__IOS__ && !__ANDROID__ #if !__IOS__ && !__ANDROID__
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;

Просмотреть файл

@ -1,4 +1,4 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
using Windows.UI.Xaml; using Windows.UI.Xaml;

Просмотреть файл

@ -1,4 +1,4 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;

Просмотреть файл

@ -1,4 +1,4 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;

Просмотреть файл

@ -1,4 +1,4 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Numerics; using System.Numerics;
using System.Reflection; using System.Reflection;
@ -12,6 +12,10 @@ using Windows.UI.Xaml.Shapes;
using Uno.Extensions; using Uno.Extensions;
using Uno.Logging; using Uno.Logging;
#if NETCOREAPP
using Microsoft.UI;
#endif
#if __IOS__ || __MACOS__ #if __IOS__ || __MACOS__
using CoreGraphics; using CoreGraphics;
#endif #endif
@ -25,7 +29,7 @@ namespace Uno.UI.Toolkit
#endif #endif
public static class UIElementExtensions public static class UIElementExtensions
{ {
#region Elevation #region Elevation
public static void SetElevation(this UIElement element, double elevation) public static void SetElevation(this UIElement element, double elevation)
{ {
@ -58,7 +62,7 @@ namespace Uno.UI.Toolkit
#if __IOS__ || __MACOS__ #if __IOS__ || __MACOS__
internal static void SetElevationInternal(this DependencyObject element, double elevation, Color shadowColor, CGPath path = null) internal static void SetElevationInternal(this DependencyObject element, double elevation, Color shadowColor, CGPath path = null)
#elif NETFX_CORE #elif NETFX_CORE || NETCOREAPP
internal static void SetElevationInternal(this DependencyObject element, double elevation, Color shadowColor, DependencyObject host = null, CornerRadius cornerRadius = default(CornerRadius)) internal static void SetElevationInternal(this DependencyObject element, double elevation, Color shadowColor, DependencyObject host = null, CornerRadius cornerRadius = default(CornerRadius))
#else #else
internal static void SetElevationInternal(this DependencyObject element, double elevation, Color shadowColor) internal static void SetElevationInternal(this DependencyObject element, double elevation, Color shadowColor)
@ -79,7 +83,7 @@ namespace Uno.UI.Toolkit
if (element is AppKit.NSView view) if (element is AppKit.NSView view)
#else #else
if (element is UIKit.UIView view) if (element is UIKit.UIView view)
#endif #endif
{ {
if (elevation > 0) if (elevation > 0)
{ {
@ -88,17 +92,17 @@ namespace Uno.UI.Toolkit
const float y = 0.92f * 0.5f; // Looks more accurate than the recommended 0.92f. const float y = 0.92f * 0.5f; // Looks more accurate than the recommended 0.92f.
const float blur = 0.5f; const float blur = 0.5f;
#if __MACOS__ #if __MACOS__
view.WantsLayer = true; view.WantsLayer = true;
view.Shadow ??= new AppKit.NSShadow(); view.Shadow ??= new AppKit.NSShadow();
#endif #endif
view.Layer.MasksToBounds = false; view.Layer.MasksToBounds = false;
view.Layer.ShadowOpacity = shadowColor.A / 255f; view.Layer.ShadowOpacity = shadowColor.A / 255f;
#if __MACOS__ #if __MACOS__
view.Layer.ShadowColor = AppKit.NSColor.FromRgb(shadowColor.R, shadowColor.G, shadowColor.B).CGColor; view.Layer.ShadowColor = AppKit.NSColor.FromRgb(shadowColor.R, shadowColor.G, shadowColor.B).CGColor;
#else #else
view.Layer.ShadowColor = UIKit.UIColor.FromRGB(shadowColor.R, shadowColor.G, shadowColor.B).CGColor; view.Layer.ShadowColor = UIKit.UIColor.FromRGB(shadowColor.R, shadowColor.G, shadowColor.B).CGColor;
#endif #endif
view.Layer.ShadowRadius = (nfloat)(blur * elevation); view.Layer.ShadowRadius = (nfloat)(blur * elevation);
view.Layer.ShadowOffset = new CoreGraphics.CGSize(x * elevation, y * elevation); view.Layer.ShadowOffset = new CoreGraphics.CGSize(x * elevation, y * elevation);
view.Layer.ShadowPath = path; view.Layer.ShadowPath = path;
@ -129,7 +133,7 @@ namespace Uno.UI.Toolkit
uiElement.UnsetCssClasses("noclip"); uiElement.UnsetCssClasses("noclip");
} }
} }
#elif NETFX_CORE #elif NETFX_CORE || NETCOREAPP
if (element is UIElement uiElement) if (element is UIElement uiElement)
{ {
var compositor = ElementCompositionPreview.GetElementVisual(uiElement).Compositor; var compositor = ElementCompositionPreview.GetElementVisual(uiElement).Compositor;
@ -318,7 +322,7 @@ namespace Uno.UI.Toolkit
{ {
uiElement.Log().Warn($"The {propertyName} dependency property does not exist on {type}"); uiElement.Log().Warn($"The {propertyName} dependency property does not exist on {type}");
} }
#if !NETFX_CORE #if !NETFX_CORE && !NETCOREAPP
else if (property.Type != propertyType) else if (property.Type != propertyType)
{ {
uiElement.Log().Warn($"The {propertyName} dependency property {type} is not of the {propertyType} Type."); uiElement.Log().Warn($"The {propertyName} dependency property {type} is not of the {propertyType} Type.");

Просмотреть файл

@ -2,6 +2,9 @@
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>xamarinmac20;MonoAndroid11.0;uap10.0.17763;xamarinios10;netstandard2.0</TargetFrameworks> <TargetFrameworks>xamarinmac20;MonoAndroid11.0;uap10.0.17763;xamarinios10;netstandard2.0</TargetFrameworks>
<TargetFrameworksCI>MonoAndroid11.0;MonoAndroid10.0;uap10.0.17763;xamarinios10;netstandard2.0;xamarinmac20</TargetFrameworksCI> <TargetFrameworksCI>MonoAndroid11.0;MonoAndroid10.0;uap10.0.17763;xamarinios10;netstandard2.0;xamarinmac20</TargetFrameworksCI>
<TargetFrameworks Condition="'$(UNO_UWP_BUILD)'!='true'">$(TargetFrameworks);net5.0-windows10.0.18362.0</TargetFrameworks>
<TargetFrameworksCI Condition="'$(UNO_UWP_BUILD)'!='true'">$(TargetFrameworksCI);net5.0-windows10.0.18362.0</TargetFrameworksCI>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(UnoTargetFrameworkOverride)'!=''"> <PropertyGroup Condition="'$(UnoTargetFrameworkOverride)'!=''">
@ -82,15 +85,15 @@
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>
<ItemGroup Condition="'$(TargetFramework)'=='uap10.0.17763'"> <ItemGroup Condition="'$(TargetFramework)'=='net5.0-windows10.0.18362.0' or '$(TargetFramework)'=='uap10.0.17763'">
<PackageReference Include="Microsoft.WinUI" Condition="'$(UNO_UWP_BUILD)'!='true'"> <PackageReference Include="Microsoft.ProjectReunion.WinUI" Condition="'$(UNO_UWP_BUILD)'!='true'">
<Version>3.0.0-alpha.200210.0</Version> <Version>0.5.0</Version>
</PackageReference> </PackageReference>
<Compile Include="$(MSBuildThisFileDirectory)..\Uno.UI\Extensions\DependencyObjectExtensions.cs"> <Compile Include="$(MSBuildThisFileDirectory)..\Uno.UI\Extensions\DependencyObjectExtensions.cs">
<Link>Uno.UI\Extensions\%(RecursiveDir)%(FileName)%(Extension)</Link> <Link>Uno.UI\Extensions\%(RecursiveDir)%(FileName)%(Extension)</Link>
</Compile> </Compile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Page Remove="Themes\Generic.xaml" /> <Page Remove="Themes\Generic.xaml" />
<Page Include="Themes\Generic.xaml" /> <Page Include="Themes\Generic.xaml" />
@ -130,4 +133,8 @@
<Copy SourceFiles="@(_OutputFiles)" DestinationFiles="@(_OutputFiles->'$(_TargetNugetFolder)\%(RecursiveDir)%(Filename)%(Extension)')" /> <Copy SourceFiles="@(_OutputFiles)" DestinationFiles="@(_OutputFiles->'$(_TargetNugetFolder)\%(RecursiveDir)%(Filename)%(Extension)')" />
<Copy SourceFiles="@(_OutputFilesPDB)" DestinationFiles="@(_OutputFilesPDB->'$(_TargetNugetFolder)\%(RecursiveDir)%(Filename).pdb')" /> <Copy SourceFiles="@(_OutputFilesPDB)" DestinationFiles="@(_OutputFilesPDB->'$(_TargetNugetFolder)\%(RecursiveDir)%(Filename).pdb')" />
</Target> </Target>
<!-- https://github.com/microsoft/microsoft-ui-xaml/issues/4503 -->
<Target Name="_CalculateXbfSupport" Condition="'$(TargetFramework)'=='uap10.0.17763'"/>
</Project> </Project>