Merge branch 'main' into pr/2012

This commit is contained in:
Brandon Minnick 2024-07-24 09:16:26 -07:00
Родитель 9c9784073c f9519ba45b
Коммит c7030870c9
15 изменённых файлов: 161 добавлений и 90 удалений

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

@ -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" />

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

@ -13,7 +13,7 @@
<Grid
Padding="20"
ColumnDefinitions="*, *, *"
RowDefinitions="Auto, Auto, 60, Auto, 60, Auto, Auto, 60"
RowDefinitions="Auto, Auto, 60, Auto, 60, Auto, Auto, 60, 40, 112, Auto"
RowSpacing="20">
<Label
@ -149,6 +149,40 @@
<mct:IconTintColorBehavior TintColor="Purple" />
</Image.Behaviors>
</Image>
<Label
Grid.Row="8"
Grid.ColumnSpan="3"
Padding="0,20,0,0"
FontAttributes="Bold"
FontSize="18"
HorizontalTextAlignment="Center"
Text="Button with Image" />
<Button
Grid.Row="9"
Grid.ColumnSpan="3"
Clicked="HandleButtonClicked"
HeightRequest="110"
WidthRequest="350"
HorizontalOptions="Center"
VerticalOptions="Center"
Text="Button with Image"
ImageSource="https://api.nuget.org/v3-flatcontainer/communitytoolkit.maui/9.0.1/icon">
</Button>
<Label
Grid.Row="10"
Grid.ColumnSpan="3"
Margin="0"
Padding="0"
FontSize="Micro"
FontAttributes="Italic"
HorizontalOptions="Center"
VerticalOptions="Start"
VerticalTextAlignment="Center"
HorizontalTextAlignment="Center"
Text="Clicking this Button adds/removes the TintColorBehavior for its icon. Click it!"/>
</Grid>
</ScrollView>
</pages:BasePage>

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

@ -1,3 +1,4 @@
using CommunityToolkit.Maui.Behaviors;
using CommunityToolkit.Maui.Sample.ViewModels.Behaviors;
namespace CommunityToolkit.Maui.Sample.Pages.Behaviors;
@ -9,4 +10,23 @@ public partial class IconTintColorBehaviorPage : BasePage<IconTintColorBehaviorV
{
InitializeComponent();
}
void HandleButtonClicked(object? sender, EventArgs e)
{
ArgumentNullException.ThrowIfNull(sender);
var button = (Button)sender;
if (button.Behaviors.OfType<IconTintColorBehavior>().SingleOrDefault() is IconTintColorBehavior iconTintColorBehavior)
{
button.Behaviors.Remove(iconTintColorBehavior);
}
else
{
button.Behaviors.Add(new IconTintColorBehavior
{
TintColor = Colors.Green
});
}
}
}

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

@ -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);

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

@ -2,8 +2,9 @@
using Android.Graphics;
using Android.Widget;
using Microsoft.Maui.Platform;
using AButton = Android.Widget.Button;
using AView = Android.Views.View;
using AndroidMaterialButton = Google.Android.Material.Button.MaterialButton;
using AndroidView = Android.Views.View;
using AndroidWidgetButton = Android.Widget.Button;
using Color = Microsoft.Maui.Graphics.Color;
using ImageButton = Microsoft.Maui.Controls.ImageButton;
@ -11,42 +12,36 @@ namespace CommunityToolkit.Maui.Behaviors;
public partial class IconTintColorBehavior
{
AView? nativeView;
AndroidView? nativeView;
/// <inheritdoc/>
protected override void OnAttachedTo(View bindable, AView platformView)
protected override void OnAttachedTo(View bindable, AndroidView platformView)
{
base.OnAttachedTo(bindable, platformView);
nativeView = platformView;
ApplyTintColor();
ApplyTintColor(nativeView, TintColor);
bindable.PropertyChanged += OnElementPropertyChanged;
PropertyChanged += OnTintedImagePropertyChanged;
}
void OnTintedImagePropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == TintColorProperty.PropertyName)
{
ApplyTintColor();
}
}
/// <inheritdoc/>
protected override void OnDetachedFrom(View bindable, AView platformView)
protected override void OnDetachedFrom(View bindable, AndroidView platformView)
{
base.OnDetachedFrom(bindable, platformView);
ClearTintColor();
if(nativeView is not null)
{
ClearTintColor(bindable, platformView);
}
bindable.PropertyChanged -= OnElementPropertyChanged;
PropertyChanged -= OnTintedImagePropertyChanged;
}
void ApplyTintColor()
static void ApplyTintColor(AndroidView? nativeView, Color? tintColor)
{
var color = TintColor;
if (nativeView is null)
{
return;
@ -55,11 +50,17 @@ public partial class IconTintColorBehavior
switch (nativeView)
{
case ImageView image:
SetImageViewTintColor(image, color);
SetImageViewTintColor(image, tintColor);
break;
case AButton button:
SetButtonTintColor(button, color);
case AndroidMaterialButton materialButton when tintColor is not null:
SetMaterialButtonTintColor(materialButton, tintColor);
break;
case AndroidWidgetButton widgetButton:
SetWidgetButtonTintColor(widgetButton, tintColor);
break;
default:
throw new NotSupportedException($"{nameof(IconTintColorBehavior)} only currently supports Android.Widget.Button and {nameof(ImageView)}.");
}
@ -76,9 +77,18 @@ public partial class IconTintColorBehavior
image.SetColorFilter(new PorterDuffColorFilter(color.ToPlatform(), PorterDuff.Mode.SrcIn ?? throw new InvalidOperationException("PorterDuff.Mode.SrcIn should not be null at runtime.")));
}
static void SetButtonTintColor(AButton button, Color? color)
static void SetMaterialButtonTintColor(AndroidMaterialButton button, Color color)
{
var drawables = button.GetCompoundDrawables().Where(d => d is not null);
button.IconTintMode = PorterDuff.Mode.SrcIn;
button.IconTint = new Android.Content.Res.ColorStateList(new int[][]
{
[]
}, [color.ToPlatform()]);
}
static void SetWidgetButtonTintColor(AndroidWidgetButton button, Color? color)
{
var drawables = button.GetCompoundDrawables().ToList();
if (color is null)
{
@ -96,11 +106,33 @@ public partial class IconTintColorBehavior
}
}
static void ClearTintColor(View element, AndroidView control)
{
switch (control)
{
case ImageView image:
image.ClearColorFilter();
break;
case AndroidMaterialButton mButton:
mButton.IconTint = null;
break;
case AndroidWidgetButton button:
foreach (var drawable in button.GetCompoundDrawables())
{
drawable.ClearColorFilter();
}
break;
}
}
void OnElementPropertyChanged(object? sender, PropertyChangedEventArgs args)
{
if (args.PropertyName is not string propertyName
|| sender is not View bindable
|| bindable.Handler?.PlatformView is not AView platformView)
|| bindable.Handler?.PlatformView is not AndroidView)
{
return;
}
@ -111,27 +143,14 @@ public partial class IconTintColorBehavior
return;
}
ApplyTintColor();
ApplyTintColor(nativeView, TintColor);
}
void ClearTintColor()
void OnTintedImagePropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (nativeView is null)
if (e.PropertyName == TintColorProperty.PropertyName)
{
return;
}
switch (nativeView)
{
case ImageView image:
image.ClearColorFilter();
break;
case AButton button:
foreach (var drawable in button.GetCompoundDrawables())
{
drawable?.ClearColorFilter();
}
break;
ApplyTintColor(nativeView, TintColor);
}
}
}

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

@ -55,7 +55,13 @@ public partial class IconTintColorBehavior
static bool TryGetButtonImage(WButton button, [NotNullWhen(true)] out WImage? image)
{
image = button.Content as WImage;
image = button.Content switch
{
WImage windowsImage => windowsImage,
Microsoft.UI.Xaml.Controls.Panel panel => panel.Children?.OfType<WImage>().FirstOrDefault(),
_ => null
};
return image is not null;
}

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

@ -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>