xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.62k stars 1.87k forks source link

Toggled event not raise for Forms Switch. Only native view switch, Toggled event only raised and Forms switch background not mapped to native view switch. #3956

Open AjitKRuin opened 6 years ago

AjitKRuin commented 6 years ago

Description

Our requirement is to use native view switch, to achieve this we have get the native switch using Forms Switch renderer concept. We have faced the problem in android such as Forms Switch Toggled event not raise, only native view switch Toggled event only raised and Forms switch background not mapped to native view switch.

Note: The reported scenario working fine in ios and UWP renderer , Both Forms and native switch view Toggled evet raised properly and Bakground color also working fine.

Here, we have customized a switch inside a grid in pcl. From native, we have initialized the forms switch and hooked the Toggled event and also we set the Background Color for it. The native switch is got through renderer and similarly the Toggle event hooked and background color is set for it. The toggle event and background color of native view updated but for Forms switch is not updated for Xamarin Forms Android platform. In iOS and UWP platforms it works correctly.

The android native view for Xamarin Forms switch is created through the method given in screenshot. The toggle event of forms switch is not risen in this scenario and the native switch toggle event only rises. And also the background color is not updated for forms switch when we set from renderer. But for native switch background color updates fine.

Also check the IsVisible property for switch in all the three platforms.

Steps to Reproduce

1.In the given sample 's code level ,keep the break-point in Toggled event of forms switch and in CheckedChange event of native switch in android renderer. 2.Run the sample.

Expected Behavior

The forms switch's Toggled event should rise first and then the native switch's CheckedChange event rises The background color set for forms switch updated in view. It should works similarly as like in iOS and UWP

Actual Behavior

The native switch's CheckedChange event only rises The background color for forms switch is not updated.

Basic Information

Screenshots

image

Reproduction Link

Kindly find the sample. DataForm_SwitchRenderer.zip

AjitKRuin commented 6 years ago

May I know when will be the fix available?

AjitKRuin commented 6 years ago

I have tried the same flow for entry too, but the background color is not updated.Check this too if possible

kingces95 commented 6 years ago

I'm afraid we don't generally debug custom renderers. That said, I do believe the problem is with the custom renderer not raising the event on the forms element.

Instead, we recast bugs involving cutom renderders as feature requests to implement whatever feature is missing in the existing renderers that motivated the creation of a custom renderer.

Can you elaborate on the deficiency in the existing renderer that cause you to create a custom renderer?

AjitKRuin commented 6 years ago

We have tested the background color and toggled event only and our requirement is to update the background color and toggled event for switch when renderer is used. The forms switch's toggled event and background is not affected when raised and native switch event alone rises. Consider this issue alone. I'm expecting in android as like working in the iOS and UWP.

ArunSivaR commented 5 years ago

Hi Team,

We are facing issue on same scenario, while using Entry renderer view for rendering, the Entry background color doesn’t update on the view while update in Forms, and it works fine as expected in iOS and UWP. the sample for the same is following by.

Sample: EntryRenderer.