xamarin/Xamarin.Forms

[Bug] Android TimePickerRenderer dialog positive button handler not triggered

Ouverte

#13 022 ouverte le 2 déc. 2020

 (1 commentaire) (0 réaction) (0 personne assignée)C# (1 926 forks)batch import
a/customrenderera/timepickere/2 :clock2:help wantedp/Androidt/bug :bug:up-for-grabs

Métriques du dépôt

Stars
 (5 644 étoiles)
Métriques de merge PR
 (Métriques PR en attente)

Description

Description

When implementing a custom renderer for the TimePicker in Android to intercept whether the dialogs OK button is pressed, the handler is not triggered for the DialogButtonType.Positive. Negative and Neutral button handlers are triggered.

The same code is working for DatePickerRenderer

Steps to Reproduce

    protected override TimePickerDialog CreateTimePickerDialog(int hours, int minutes)
    {
        dialog = new TimePickerDialog(Context, this, hours, minutes, true);

        dialog.SetButton((int) DialogButtonType.Negative,
            Context.Resources.GetString(global::Android.Resource.String.Cancel), OnCancel);
        dialog.SetButton((int) DialogButtonType.Positive,
            Context.Resources.GetString(global::Android.Resource.String.Ok), OnOk);
        
        return dialog;
    }

    private void OnCancel(object sender, DialogClickEventArgs e)
    {
        _element.Unfocus();
    }

    private void OnOk(object sender, EventArgs eventArgs)
    {
        _element.Unfocus();
    }

Expected Behavior

When clicking the OK button OnOk is called. When clicking the Cancel button OnCancel is called.

Actual Behavior

When clicking the OK button OnOk is NOT called. When clicking the Cancel button OnCancel is called.

Basic Information

  • Version with issue: 4.8.0.1678
  • Last known good version: -
  • Platform Target Frameworks:
    • Android: TargetSDK: 30

Workaround

Instead I need to use the following code in my control:

this.PropertyChanged += (sender, args) =>
            {
                if (Device.RuntimePlatform != Device.Android || args.PropertyName != "Time")
                {
                    return;
                }

                CallOnOk();
            };

Guide contributeur