xamarin/Xamarin.Forms

[Bug] Android TimePickerRenderer dialog positive button handler not triggered

オープン

#13,022 opened on 2020/12/02

 (1 件のコメント) (0 件のリアクション) (0 人の担当者)C# (1,926 件のフォーク)batch import
a/customrenderera/timepickere/2 :clock2:help wantedp/Androidt/bug :bug:up-for-grabs

Repository metrics

Stars
 (5,644 個のスター)
PR merge metrics
 (30d に merged PR はありません)

説明

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();
            };

コントリビューターガイド