Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

Commit 5774423

Browse files
mike-rowleypictos
andauthored
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>
1 parent 5859251 commit 5774423

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ protected override void OnElementPropertyChanged(PropertyChangedEventArgs args)
2323
base.OnElementPropertyChanged(args);
2424

2525
if (!args.PropertyName.Equals(IconTintColorEffect.TintColorProperty.PropertyName) &&
26-
!args.PropertyName.Equals(Image.SourceProperty.PropertyName) &&
27-
!args.PropertyName.Equals(ImageButton.SourceProperty.PropertyName))
26+
!args.PropertyName.Equals(Image.SourceProperty.PropertyName) &&
27+
!args.PropertyName.Equals(ImageButton.SourceProperty.PropertyName))
2828
return;
2929

3030
ApplyTintColor();
@@ -53,17 +53,17 @@ void ClearTintColor()
5353
switch (Control)
5454
{
5555
case UIImageView imageView:
56+
Element.PropertyChanged -= ImageViewTintColorPropertyChanged;
5657
if (imageView.Image != null)
5758
{
58-
Element.PropertyChanged -= ImageViewTintColorPropertyChanged;
5959
imageView.Image = imageView.Image.ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal);
6060
}
6161

6262
break;
6363
case UIButton button:
64-
if (button.ImageView.Image != null)
64+
Element.PropertyChanged -= ButtonTintColorPropertyChanged;
65+
if (button.ImageView?.Image != null)
6566
{
66-
Element.PropertyChanged -= ButtonTintColorPropertyChanged;
6767
var originalImage = button.CurrentImage.ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal);
6868
button.SetImage(originalImage, UIControlState.Normal);
6969
}

0 commit comments

Comments
 (0)