Fix for ClearTintColor NullReferenceException on ImageButton related to PR #1836 (#1857)

* Fix for Bug #934 (IconTintColorEffect does not work when the image is in Shared project as EmbeddeResource)

* Revised Fix for #934

* Update src/CommunityToolkit/Xamarin.CommunityToolkit/Effects/IconTintColor/IconTintColorEffectRouter.ios.cs

Co-authored-by: Pedro Jesus <pedrojesus.cefet@gmail.com>

* Update src/CommunityToolkit/Xamarin.CommunityToolkit/Effects/IconTintColor/IconTintColorEffectRouter.ios.cs

Co-authored-by: Pedro Jesus <pedrojesus.cefet@gmail.com>

* Revised Fix #2 for Bug #934

* updated the sample

* improved variable name

* changed the null check object

* Update IconTintColorEffectRouter.ios.cs To Fix ClearTintColor Crash

I have added a null check on button.ImageView in ClearTintColor to prevent a crash when OnDetach is called.  This NullReferenceException occured when changing Application.MainPage.

* Update IconTintColorEffectRouter.ios.cs To Fix ClearTintColor Crash

Co-authored-by: Pedro Jesus <pedrojesus.cefet@gmail.com>
This commit is contained in:
Mike Rowley 2022-05-18 03:11:27 -06:00 коммит произвёл GitHub
Родитель 5859251e81
Коммит 57744235cc
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 5 добавлений и 5 удалений

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

@ -23,8 +23,8 @@ namespace Xamarin.CommunityToolkit.iOS.Effects
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();
@ -53,17 +53,17 @@ namespace Xamarin.CommunityToolkit.iOS.Effects
switch (Control)
{
case UIImageView imageView:
Element.PropertyChanged -= ImageViewTintColorPropertyChanged;
if (imageView.Image != null)
{
Element.PropertyChanged -= ImageViewTintColorPropertyChanged;
imageView.Image = imageView.Image.ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal);
}
break;
case UIButton button:
if (button.ImageView.Image != null)
Element.PropertyChanged -= ButtonTintColorPropertyChanged;
if (button.ImageView?.Image != null)
{
Element.PropertyChanged -= ButtonTintColorPropertyChanged;
var originalImage = button.CurrentImage.ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal);
button.SetImage(originalImage, UIControlState.Normal);
}