Skip to content

Commit

Permalink
chore: update for mvp spec
Browse files Browse the repository at this point in the history
  • Loading branch information
dansiegel authored and nickrandolph committed Jul 25, 2023
1 parent 1399eb2 commit cec4a98
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 28 deletions.
4 changes: 2 additions & 2 deletions src/Uno.Extensions.Maui/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@
global using WinUIColor = Windows.UI.Color;
global using NativeMauiColor = Microsoft.Maui.Graphics.Color;
global using MauiResourceDictionary = Microsoft.Maui.Controls.ResourceDictionary;
global using MauiConverter = Microsoft.Maui.Controls.IValueConverter;
global using WinUIConverter = Microsoft.UI.Xaml.Data.IValueConverter;
global using IMauiConverter = Microsoft.Maui.Controls.IValueConverter;
global using IWinUIConverter = Microsoft.UI.Xaml.Data.IValueConverter;

22 changes: 12 additions & 10 deletions src/Uno.Extensions.Maui/Internals/ConversionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,18 @@ public static Microsoft.Maui.Controls.ResourceDictionary ToMauiResources(this Re

private static void TryAddValue(ref Microsoft.Maui.Controls.ResourceDictionary resources, object sourceKey, object value)
{
if (value is Style winUIStyle)
{
// This needs to be nested to prevent further processing if we cannot generate a Maui Style
if(Interop.MauiInterop.TryGetStyle(winUIStyle, out var style) && style != null)
{
var key = sourceKey is string str ? str : style.TargetType.FullName;
resources[key] = style;
}
}
else if (sourceKey is string key && !string.IsNullOrEmpty(key) && !resources.ContainsKey(key))
// NOTE: Interop was part of the POC and is out of scope for the MVP
// if (value is Style winUIStyle)
// {
// // This needs to be nested to prevent further processing if we cannot generate a Maui Style
// if(Interop.MauiInterop.TryGetStyle(winUIStyle, out var style) && style != null)
// {
// var key = sourceKey is string str ? str : style.TargetType.FullName;
// resources[key] = style;
// }
// }
// else
if (sourceKey is string key && !string.IsNullOrEmpty(key) && !resources.ContainsKey(key))
{
var mauiValue = ConversionHelpers.ToMauiValue(value);
resources[key] = mauiValue ?? value;
Expand Down
8 changes: 4 additions & 4 deletions src/Uno.Extensions.Maui/Internals/ConversionHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal static class ConversionHelpers
int valueAsInt => valueAsInt,
double valueAsDouble => valueAsDouble,
float valueAsFloat => valueAsFloat,
WinUIConverter converter => new UnoHostConverter(converter),
IWinUIConverter converter => new UnoHostConverter(converter),
SolidColorBrush solidColorBrush => new Microsoft.Maui.Controls.SolidColorBrush(new NativeMauiColor(solidColorBrush.Color.R, solidColorBrush.Color.G, solidColorBrush.Color.B, solidColorBrush.Color.A)),
WinUIColor color => new NativeMauiColor(color.R, color.G, color.B, color.A),
Thickness thickness => new Microsoft.Maui.Thickness(thickness.Left, thickness.Top, thickness.Right, thickness.Bottom),
Expand Down Expand Up @@ -42,11 +42,11 @@ private static LayoutOptions GetLayoutOptions(VerticalAlignment alignment) =>
_ => LayoutOptions.Fill
};

private class UnoHostConverter : MauiConverter
private class UnoHostConverter : IMauiConverter
{
private WinUIConverter _converter { get; }
private IWinUIConverter _converter { get; }

public UnoHostConverter(WinUIConverter converter) => _converter = converter;
public UnoHostConverter(IWinUIConverter converter) => _converter = converter;

public object Convert(object value, Type targetType, object parameter, CultureInfo culture) =>
_converter.Convert(value, targetType, parameter, culture.Name);
Expand Down
8 changes: 4 additions & 4 deletions src/Uno.Extensions.Maui/MauiBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ protected override void SetValue(View view, Type viewType, Type propertyType, Mi
}


MauiConverter? converter = null;
if (Converter is MauiConverter converterAsMauiConverter)
IMauiConverter? converter = null;
if (Converter is IMauiConverter converterAsMauiConverter)
{
converter = converterAsMauiConverter;
}
else if (Converter is WinUIConverter winUIConverter)
else if (Converter is IWinUIConverter winUIConverter)
{
var value = ConversionHelpers.ToMauiValue(winUIConverter);
if (value is MauiConverter mauiConverter)
if (value is IMauiConverter mauiConverter)
{
converter = mauiConverter;
}
Expand Down
3 changes: 3 additions & 0 deletions src/Uno.Extensions.Maui/MauiEmbedding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public static void UseMauiEmbedding(this Microsoft.UI.Xaml.Application app, Acti
}
#endif

// NOTE: This was part of the POC and is out of scope for the MVP. Keeping it in case we want to add it back later.
/*
public static MauiAppBuilder MapControl<TWinUI, TMaui>(this MauiAppBuilder builder)
where TWinUI : FrameworkElement
where TMaui : Microsoft.Maui.Controls.View
Expand All @@ -65,4 +67,5 @@ public static MauiAppBuilder MapStyleHandler<THandler>(this MauiAppBuilder build
Interop.MauiInterop.MapStyleHandler<THandler>();
return builder;
}
*/
}
14 changes: 6 additions & 8 deletions src/Uno.Extensions.Maui/Uno.Extensions.Maui.WinUI.csproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net7.0;net7.0-android;net7.0-ios;net7.0-maccatalyst</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net7.0-windows10.0.19041</TargetFrameworks>
<TargetFrameworks>net6.0;net6.0-android;net6.0-ios;net6.0-maccatalyst</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net6.0-windows10.0.19041</TargetFrameworks>
<UseMaui>true</UseMaui>
<RootNamespace>Uno.Extensions.Maui</RootNamespace>
<NoWarn>$(NoWarn);CS1591;NU5104;NU5048;NU1009</NoWarn>
<Description>Extensions to embed .NET MAUI controls within your Uno app.</Description>
<DefineConstants Condition="$(TargetFramework) == 'net7.0'">$(DefineConstants);NO_PLATFORM</DefineConstants>
<DefineConstants Condition="$(TargetFramework) == 'net6.0'">$(DefineConstants);NO_PLATFORM</DefineConstants>
</PropertyGroup>

<ItemGroup>
Expand All @@ -31,9 +31,7 @@
</EmbeddedResource>
</ItemGroup>

<PropertyGroup Condition=" $(TargetFramework.Contains('-windows10')) ">
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<SupportedOSPlatformVersion>$(TargetPlatformMinVersion)</SupportedOSPlatformVersion>
<RuntimeIdentifiers>win10-x86;win10-x64;win10-arm64</RuntimeIdentifiers>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Interop\*.cs" />
</ItemGroup>
</Project>

0 comments on commit cec4a98

Please sign in to comment.