From 965c918a1c893d63381bf6efc3bd0634be37978f Mon Sep 17 00:00:00 2001 From: Shane Neuville Date: Tue, 12 Jul 2022 12:28:33 -0500 Subject: [PATCH 1/2] Add tests to verify DisconnectHandler --- .../DeviceTests/Handlers/HandlerTestBaseOfT.Tests.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Core/tests/DeviceTests/Handlers/HandlerTestBaseOfT.Tests.cs b/src/Core/tests/DeviceTests/Handlers/HandlerTestBaseOfT.Tests.cs index 98055786dff3..909dc19d91d0 100644 --- a/src/Core/tests/DeviceTests/Handlers/HandlerTestBaseOfT.Tests.cs +++ b/src/Core/tests/DeviceTests/Handlers/HandlerTestBaseOfT.Tests.cs @@ -57,6 +57,16 @@ await AssertionExtensions.Wait(() => } #endif + [Fact] + public async Task DisconnectHandlerDoesntCrash() + { + var handler = await CreateHandlerAsync(new TStub()) as IPlatformViewHandler; + await InvokeOnMainThreadAsync(() => + { + handler.DisconnectHandler(); + }); + } + [Fact(DisplayName = "Automation Id is set correctly")] public async Task SetAutomationId() { From b68f80ab84a3106c535c9ba2c58b6f1370351048 Mon Sep 17 00:00:00 2001 From: Shane Neuville Date: Tue, 12 Jul 2022 14:19:51 -0500 Subject: [PATCH 2/2] - fix disconnects founds --- src/Core/src/Handlers/Image/ImageHandler.iOS.cs | 2 +- .../src/Handlers/RadioButton/RadioButtonHandler.Android.cs | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Core/src/Handlers/Image/ImageHandler.iOS.cs b/src/Core/src/Handlers/Image/ImageHandler.iOS.cs index 4cccb3083505..5159b75814fa 100644 --- a/src/Core/src/Handlers/Image/ImageHandler.iOS.cs +++ b/src/Core/src/Handlers/Image/ImageHandler.iOS.cs @@ -23,7 +23,7 @@ protected override void DisconnectHandler(UIImageView platformView) { base.DisconnectHandler(platformView); - if (PlatformView is MauiImageView imageView) + if (platformView is MauiImageView imageView) imageView.WindowChanged -= OnWindowChanged; SourceLoader.Reset(); diff --git a/src/Core/src/Handlers/RadioButton/RadioButtonHandler.Android.cs b/src/Core/src/Handlers/RadioButton/RadioButtonHandler.Android.cs index 900efa7ebe2e..425e6b806187 100644 --- a/src/Core/src/Handlers/RadioButton/RadioButtonHandler.Android.cs +++ b/src/Core/src/Handlers/RadioButton/RadioButtonHandler.Android.cs @@ -25,8 +25,7 @@ protected override void ConnectHandler(View platformView) protected override void DisconnectHandler(View platformView) { - AppCompatRadioButton? platformRadioButton = GetPlatformRadioButton(this); - if (platformRadioButton != null) + if (platformView is AppCompatRadioButton platformRadioButton) platformRadioButton.CheckedChange -= OnCheckChanged; }