Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Microsoft.Maui.Controls.Compatibility Dependency #2006

Merged
merged 9 commits into from
Jul 23, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<PropertyGroup>
<TargetFramework>$(NetVersion)</TargetFramework>
<IsPackable>false</IsPackable>
<UseMaui>true</UseMaui>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GF</CompilerGeneratedFilesOutputPath>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
Expand All @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down Expand Up @@ -72,7 +71,6 @@

<ItemGroup>
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiPackageVersion)"/>
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiPackageVersion)"/>

</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down Expand Up @@ -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>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down Expand Up @@ -66,7 +65,6 @@

<ItemGroup>
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiPackageVersion)"/>
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiPackageVersion)"/>
</ItemGroup>

</Project>
34 changes: 32 additions & 2 deletions src/CommunityToolkit.Maui.MediaElement/Views/MediaManager.tizen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -181,7 +181,7 @@ protected virtual partial void PlatformUpdateSource()
var path = resourceMediaSource.Path;
if (!string.IsNullOrWhiteSpace(path))
{
Player.SetSource(new MediaUriSource(ResourcePath.GetPath(path)));
Player.SetSource(new MediaUriSource(GetResourcePath(path)));
IsUriStreaming = false;
}
}
Expand Down Expand Up @@ -387,6 +387,36 @@ void UpdateCurrentState()
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

<PropertyGroup>
<TargetFramework>$(NetVersion)</TargetFramework>
<UseMaui>true</UseMaui>
<IsPackable>false</IsPackable>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GF</CompilerGeneratedFilesOutputPath>
Expand All @@ -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>
Expand Down
8 changes: 4 additions & 4 deletions src/CommunityToolkit.Maui/Alerts/Snackbar/Snackbar.android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
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;

Expand Down Expand Up @@ -119,7 +119,7 @@ void SetContainerForView(in View snackbarView)
{
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(
Expand Down Expand Up @@ -149,7 +149,7 @@ void SetMessageForView(in View snackbarView, IFontManager fontManager)
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);
Expand All @@ -165,7 +165,7 @@ void SetActionForSnackbar(in Google.Android.Material.Snackbar.Snackbar platformS
{
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
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;
Expand Down Expand Up @@ -113,7 +113,7 @@ static ColorStateList GetColorStateList(MColor? color)
var animationColor = color;
animationColor ??= defaultNativeAnimationColor;

return new ColorStateList([[]], [animationColor.ToAndroid()]);
return new ColorStateList([[]], [animationColor.ToPlatform()]);
}

void UpdateClickHandler()
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -25,12 +23,6 @@ protected override void OnAttachedTo(VisualElement bindable, UIView platformView

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))
Expand All @@ -51,11 +43,6 @@ protected override void OnDetachedFrom(VisualElement bindable, UIView platformVi
{
base.OnDetachedFrom(bindable, platformView);

if (((platformView as IVisualNativeElementRenderer)?.Control ?? platformView) is UIButton button)
{
button.AllTouchEvents -= HandleAllTouchEvents;
}

if (touchGesture is not null)
{
platformView.RemoveGestureRecognizer(touchGesture);
Expand All @@ -73,17 +60,6 @@ protected override void OnDetachedFrom(VisualElement bindable, UIView platformVi
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)
Expand Down
2 changes: 0 additions & 2 deletions src/CommunityToolkit.Maui/CommunityToolkit.Maui.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down Expand Up @@ -64,7 +63,6 @@

<ItemGroup>
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiPackageVersion)"/>
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiPackageVersion)"/>
</ItemGroup>

</Project>