Remove `Microsoft.Maui.Controls.Compatibility` Dependency (#2006)

* Replace Color.ToAndroid (MAUI compatibility) with Color.ToPlatform (MAUI core)

* Remove references to `Microsoft.Maui.Controls.Compatibility`

* Remove Compatibility dependency on Tizen

* Remove `IVisualNativeElementRenderer`

* Remove `<UseMaui>`

---------

Co-authored-by: Brandon Minnick <13558917+brminnick@users.noreply.github.com>
Co-authored-by: Jay Cho <chojoong@gmail.com>
This commit is contained in:
Filip Navara 2024-07-24 01:25:49 +02:00 коммит произвёл GitHub
Родитель 3f6b991d26
Коммит f9519ba45b
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
11 изменённых файлов: 39 добавлений и 47 удалений

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

@ -5,7 +5,6 @@
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);$(NetVersion)-windows10.0.19041.0</TargetFrameworks>
<TargetFrameworks Condition="'$(IncludeTizenTargetFrameworks)' == 'true'">$(TargetFrameworks);$(NetVersion)-tizen</TargetFrameworks>
<OutputType>Exe</OutputType>
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
<RootNamespace>CommunityToolkit.Maui.Sample</RootNamespace>
@ -52,7 +51,6 @@
<MauiFont Include="Resources\Fonts\*" />
<PackageReference Include="Microsoft.Maui.Controls" Version="*"/>
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="*"/>
<PackageReference Include="CommunityToolkit.Maui.Markup" Version="4.0.0" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
<PackageReference Include="Microsoft.Extensions.Http.Resilience" Version="8.3.0" />

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

@ -3,7 +3,6 @@
<PropertyGroup>
<TargetFramework>$(NetVersion)</TargetFramework>
<IsPackable>false</IsPackable>
<UseMaui>true</UseMaui>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GF</CompilerGeneratedFilesOutputPath>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
@ -20,7 +19,6 @@
<PackageReference Include="coverlet.collector" Version="6.0.2" PrivateAssets="All" />
<PackageReference Include="Microsoft.CodeAnalysis" Version="4.9.2" />
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiPackageVersion)"/>
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiPackageVersion)"/>
</ItemGroup>
<ItemGroup>

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

@ -3,8 +3,7 @@
<PropertyGroup>
<TargetFrameworks>$(NetVersion);$(NetVersion)-android;$(NetVersion)-ios;$(NetVersion)-maccatalyst</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);$(NetVersion)-windows10.0.19041.0</TargetFrameworks>
<TargetFrameworks Condition="'$(IncludeTizenTargetFrameworks)' == 'true'">$(TargetFrameworks);$(NetVersion)-tizen</TargetFrameworks>
<UseMaui>true</UseMaui>
<TargetFrameworks Condition="'$(IncludeTizenTargetFrameworks)' == 'true'">$(TargetFrameworks);$(NetVersion)-tizen</TargetFrameworks>
<SingleProject>true</SingleProject>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
@ -72,7 +71,6 @@
<ItemGroup>
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiPackageVersion)"/>
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiPackageVersion)"/>
</ItemGroup>

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

@ -4,7 +4,6 @@
<TargetFrameworks>$(NetVersion);$(NetVersion)-android;$(NetVersion)-ios;$(NetVersion)-maccatalyst</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);$(NetVersion)-windows10.0.19041.0</TargetFrameworks>
<TargetFrameworks Condition="'$(IncludeTizenTargetFrameworks)' == 'true'">$(TargetFrameworks);$(NetVersion)-tizen</TargetFrameworks>
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
@ -51,7 +50,6 @@
<ItemGroup>
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiPackageVersion)"/>
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiPackageVersion)"/>
<PackageReference Include="Microsoft.Maui.Controls.Maps" Version="$(MauiPackageVersion)"/>
</ItemGroup>

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

@ -4,7 +4,6 @@
<TargetFrameworks>$(NetVersion);$(NetVersion)-android;$(NetVersion)-ios;$(NetVersion)-maccatalyst</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);$(NetVersion)-windows10.0.19041.0</TargetFrameworks>
<TargetFrameworks Condition="'$(IncludeTizenTargetFrameworks)' == 'true'">$(TargetFrameworks);$(NetVersion)-tizen</TargetFrameworks>
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
@ -66,7 +65,6 @@
<ItemGroup>
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiPackageVersion)"/>
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiPackageVersion)"/>
</ItemGroup>
</Project>

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

@ -2,9 +2,9 @@
using CommunityToolkit.Maui.Core.Primitives;
using CommunityToolkit.Maui.Core.Views;
using CommunityToolkit.Maui.Views;
using Microsoft.Maui.Controls.Compatibility.Platform.Tizen;
using Tizen.Multimedia;
using Tizen.NUI.BaseComponents;
using AppFW = Tizen.Applications;
namespace CommunityToolkit.Maui.Core.Views;
@ -181,7 +181,7 @@ public partial class MediaManager : IDisposable
var path = resourceMediaSource.Path;
if (!string.IsNullOrWhiteSpace(path))
{
Player.SetSource(new MediaUriSource(ResourcePath.GetPath(path)));
Player.SetSource(new MediaUriSource(GetResourcePath(path)));
IsUriStreaming = false;
}
}
@ -387,6 +387,36 @@ public partial class MediaManager : IDisposable
MediaElement.CurrentStateChanged(newsState);
}
string GetResourcePath(string res)
{
if (System.IO.Path.IsPathRooted(res))
{
return res;
}
foreach (AppFW.ResourceManager.Category category in Enum.GetValues(typeof(AppFW.ResourceManager.Category)))
{
var path = AppFW.ResourceManager.TryGetPath(category, res);
if (path != null)
{
return path;
}
}
AppFW.Application app = AppFW.Application.Current;
if (app != null)
{
string resPath = app.DirectoryInfo.Resource + res;
if (File.Exists(resPath))
{
return resPath;
}
}
return res;
}
async void PreparePlayer()
{
if (Player is not null)

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

@ -2,7 +2,6 @@
<PropertyGroup>
<TargetFramework>$(NetVersion)</TargetFramework>
<UseMaui>true</UseMaui>
<IsPackable>false</IsPackable>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GF</CompilerGeneratedFilesOutputPath>
@ -17,7 +16,6 @@
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" PrivateAssets="All" />
<PackageReference Include="coverlet.collector" Version="6.0.2" PrivateAssets="All" />
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiPackageVersion)"/>
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiPackageVersion)"/>
</ItemGroup>
<ItemGroup>

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

@ -4,8 +4,8 @@ using Android.Graphics.Drawables;
using Android.Util;
using Android.Widget;
using Google.Android.Material.Snackbar;
using Microsoft.Maui.Controls.Compatibility.Platform.Android;
using Microsoft.Maui.Controls.Platform;
using Microsoft.Maui.Platform;
using Object = Java.Lang.Object;
using View = Android.Views.View;
@ -119,7 +119,7 @@ public partial class Snackbar
{
if (snackbarView.Background is GradientDrawable shape)
{
shape.SetColor(VisualOptions.BackgroundColor.ToAndroid().ToArgb());
shape.SetColor(VisualOptions.BackgroundColor.ToPlatform().ToArgb());
var density = snackbarView.Context?.Resources?.DisplayMetrics?.Density ?? 1;
var cornerRadius = new Thickness(
@ -149,7 +149,7 @@ public partial class Snackbar
var snackTextView = snackbarView.FindViewById<TextView>(Resource.Id.snackbar_text) ?? throw new InvalidOperationException("Unable to find Snackbar text view");
snackTextView.SetMaxLines(10);
snackTextView.SetTextColor(VisualOptions.TextColor.ToAndroid());
snackTextView.SetTextColor(VisualOptions.TextColor.ToPlatform());
if (VisualOptions.Font.Size > 0)
{
snackTextView.SetTextSize(ComplexUnitType.Dip, (float)VisualOptions.Font.Size);
@ -165,7 +165,7 @@ public partial class Snackbar
{
var snackActionButtonView = platformSnackbar.View.FindViewById<TextView>(Resource.Id.snackbar_action) ?? throw new InvalidOperationException("Unable to find Snackbar action button");
platformSnackbar.SetActionTextColor(VisualOptions.ActionButtonTextColor.ToAndroid());
platformSnackbar.SetActionTextColor(VisualOptions.ActionButtonTextColor.ToPlatform());
if (VisualOptions.ActionButtonFont.Size > 0)
{
snackActionButtonView.SetTextSize(ComplexUnitType.Dip, (float)VisualOptions.ActionButtonFont.Size);

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

@ -4,7 +4,7 @@ using Android.OS;
using Android.Views;
using Android.Views.Accessibility;
using CommunityToolkit.Maui.Core;
using Microsoft.Maui.Controls.Compatibility.Platform.Android;
using Microsoft.Maui.Platform;
using static System.OperatingSystem;
using AView = Android.Views.View;
using MColor = Microsoft.Maui.Graphics.Color;
@ -113,7 +113,7 @@ public partial class TouchBehavior
var animationColor = color;
animationColor ??= defaultNativeAnimationColor;
return new ColorStateList([[]], [animationColor.ToAndroid()]);
return new ColorStateList([[]], [animationColor.ToPlatform()]);
}
void UpdateClickHandler()

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

@ -1,8 +1,6 @@
using CommunityToolkit.Maui.Core;
using CoreGraphics;
using Foundation;
using Microsoft.Maui.Controls.Compatibility.Platform.iOS;
using Microsoft.Maui.Platform;
using UIKit;
namespace CommunityToolkit.Maui.Behaviors;
@ -25,12 +23,6 @@ public partial class TouchBehavior
touchGesture = new TouchUITapGestureRecognizer(this);
if (((platformView as IVisualNativeElementRenderer)?.Control ?? platformView) is UIButton button)
{
button.AllTouchEvents += HandleAllTouchEvents;
((TouchUITapGestureRecognizer)touchGesture).IsButton = true;
}
platformView.AddGestureRecognizer(touchGesture);
if (OperatingSystem.IsIOSVersionAtLeast(13))
@ -51,11 +43,6 @@ public partial class TouchBehavior
{
base.OnDetachedFrom(bindable, platformView);
if (((platformView as IVisualNativeElementRenderer)?.Control ?? platformView) is UIButton button)
{
button.AllTouchEvents -= HandleAllTouchEvents;
}
if (touchGesture is not null)
{
platformView.RemoveGestureRecognizer(touchGesture);
@ -73,17 +60,6 @@ public partial class TouchBehavior
Element = null;
}
static void HandleAllTouchEvents(object? sender, EventArgs args)
{
if (sender is not UIButton button)
{
throw new ArgumentException($"{nameof(sender)} must be Type {nameof(UIButton)}", nameof(sender));
}
// Prevent Button Highlight
button.Highlighted = false;
}
void OnHover()
{
if (!IsEnabled)

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

@ -4,7 +4,6 @@
<TargetFrameworks>$(NetVersion);$(NetVersion)-android;$(NetVersion)-ios;$(NetVersion)-maccatalyst</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);$(NetVersion)-windows10.0.19041.0</TargetFrameworks>
<TargetFrameworks Condition="'$(IncludeTizenTargetFrameworks)' == 'true'">$(TargetFrameworks);$(NetVersion)-tizen</TargetFrameworks>
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
@ -64,7 +63,6 @@
<ItemGroup>
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiPackageVersion)"/>
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiPackageVersion)"/>
</ItemGroup>
</Project>