1iveowl / Plugin.SegmentedControl

MIT License
171 stars 29 forks source link

Android SegmentedControlOption.IsEnabled does not work #96

Closed mjrichards91 closed 4 years ago

mjrichards91 commented 4 years ago

I am using the SegmentedControl and SegmentedControlOption controls via XAML. At the most basic level, setting IsEnabled to False on an option does not disable it on Android (it works for iOS, unsure about UWP).

<segment:SegmentedControl>
    <segment:SegmentedControl.Children>
        <segment:SegmentedControlOption Text="Option A" IsEnabled="True" />
        <segment:SegmentedControlOption Text="Option B" IsEnabled="False" />
    </segment:SegmentedControl.Children>
</segment:SegmentedControl>

In this example, I am able to select both Option A and Option B.

I simplified this example to showcase that it does not work. My real world application sets the IsEnabled property through binding, so I am not sure if both issues are one in the same.

mjrichards91 commented 4 years ago

As an FYI, my workaround right now is this:

public class CustomSegmentedControlRenderer : SegmentedControlRenderer
{
    protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
    {
        base.OnElementPropertyChanged(sender, e);

        if (e.PropertyName == "Renderer" && this.Control != null)
        {
            this.ConfigureIsEnabledForSegments();
        }
    }

    private void ConfigureIsEnabledForSegments()
    {
        for (int i = 0; i < this.Control.ChildCount; i++)
        {
            var nativeButton = (RadioButton)this.Control.GetChildAt(i);

            var segmentedControlOption = this.Element.Children[i];

            nativeButton.Enabled = segmentedControlOption.IsEnabled;
        }
    }
}
1iveowl commented 4 years ago

Thank you.

I can confirm that iOS works and that UWP has the same issue as Android.

Will try and fix this.

1iveowl commented 4 years ago

I found the bug. It works now and will be fixed in the next version.

The color of the Disabled segment does not change on iOS, UWP or Android but if you try to choose the segment, you can't when IsEnabled=False.