Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions samples/XCT.Sample/Pages/Effects/IconTintColorEffectPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@
HorizontalTextAlignment="Center" />

<Image
Source="https://image.flaticon.com/icons/png/512/48/48639.png"
Source="https://raw.githubusercontent.com/xamarin/XamarinCommunityToolkit/main/samples/XCT.Sample.iOS/Resources/circle.png"
Grid.Row="1" />

<Image
Source="https://image.flaticon.com/icons/png/512/48/48639.png"
Source="https://raw.githubusercontent.com/xamarin/XamarinCommunityToolkit/main/samples/XCT.Sample.iOS/Resources/circle.png"
xct:IconTintColorEffect.TintColor="Red"
Grid.Row="2" />

<Image
Source="https://image.flaticon.com/icons/png/512/48/48639.png"
Source="https://raw.githubusercontent.com/xamarin/XamarinCommunityToolkit/main/samples/XCT.Sample.iOS/Resources/circle.png"
xct:IconTintColorEffect.TintColor="Green"
Grid.Row="3" />

Expand All @@ -59,18 +59,18 @@
Grid.Column="1"/>

<ImageButton
Source="https://image.flaticon.com/icons/png/512/48/48639.png"
Source="https://raw.githubusercontent.com/xamarin/XamarinCommunityToolkit/main/samples/XCT.Sample.iOS/Resources/circle.png"
Grid.Row="1"
Grid.Column="1" />

<ImageButton
Source="https://image.flaticon.com/icons/png/512/48/48639.png"
Source="https://raw.githubusercontent.com/xamarin/XamarinCommunityToolkit/main/samples/XCT.Sample.iOS/Resources/circle.png"
xct:IconTintColorEffect.TintColor="Red"
Grid.Row="2"
Grid.Column="1" />

<ImageButton
Source="https://image.flaticon.com/icons/png/512/48/48639.png"
Source="https://raw.githubusercontent.com/xamarin/XamarinCommunityToolkit/main/samples/XCT.Sample.iOS/Resources/circle.png"
xct:IconTintColorEffect.TintColor="Green"
Grid.Row="3"
Grid.Column="1" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.ComponentModel;
using System;
using System.ComponentModel;
using UIKit;
using Xamarin.CommunityToolkit.Effects;
using Xamarin.Forms;
Expand All @@ -22,8 +23,8 @@ protected override void OnElementPropertyChanged(PropertyChangedEventArgs args)
base.OnElementPropertyChanged(args);

if (!args.PropertyName.Equals(IconTintColorEffect.TintColorProperty.PropertyName) &&
!args.PropertyName.Equals(Image.SourceProperty.PropertyName) &&
!args.PropertyName.Equals(ImageButton.SourceProperty.PropertyName))
!args.PropertyName.Equals(Image.SourceProperty.PropertyName) &&
!args.PropertyName.Equals(ImageButton.SourceProperty.PropertyName))
return;

ApplyTintColor();
Expand Down Expand Up @@ -53,39 +54,78 @@ void ClearTintColor()
{
case UIImageView imageView:
if (imageView.Image != null)
{
Element.PropertyChanged -= ImageViewTintColorPropertyChanged;
imageView.Image = imageView.Image.ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal);
}

break;
case UIButton button:
if (button.CurrentImage != null)
if (button.ImageView.Image != null)
{
Element.PropertyChanged -= ButtonTintColorPropertyChanged;
var originalImage = button.CurrentImage.ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal);
button.SetImage(originalImage, UIControlState.Normal);
}

break;
}
}

void SetUIImageViewTintColor(UIImageView imageView, Color color)
{
if (imageView.Image == null)
return;
{
Element.PropertyChanged += ImageViewTintColorPropertyChanged;
}
else
{
imageView.Image = imageView.Image.ImageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate);
imageView.TintColor = color.ToUIColor();
}
}

imageView.Image = imageView.Image.ImageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate);
imageView.TintColor = color.ToUIColor();
void ImageViewTintColorPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == Image.IsLoadingProperty.PropertyName)
{
var element = (Image)Element;

if (!element.IsLoading)
{
ApplyTintColor();
}
}
}

void SetUIButtonTintColor(UIButton button, Color color)
{
if (button.CurrentImage == null)
return;
if (button.ImageView.Image == null)
{
Element.PropertyChanged += ButtonTintColorPropertyChanged;
}
else
{
var templatedImage = button.CurrentImage.ImageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate);

var templatedImage = button.CurrentImage.ImageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate);
button.SetImage(null, UIControlState.Normal);

button.SetImage(null, UIControlState.Normal);
button.TintColor = color.ToUIColor();
button.ImageView.TintColor = color.ToUIColor();
button.SetImage(templatedImage, UIControlState.Normal);
}
}

button.TintColor = color.ToUIColor();
button.ImageView.TintColor = color.ToUIColor();
button.SetImage(templatedImage, UIControlState.Normal);
void ButtonTintColorPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == ImageButton.IsLoadingProperty.PropertyName)
{
var element = (ImageButton)Element;
if (!element.IsLoading)
{
ApplyTintColor();
}
}
}
}
}