From 39b12a48647bc528fadf423af591658a893d0b9a Mon Sep 17 00:00:00 2001 From: Paul DiPietro Date: Tue, 12 Jul 2016 09:59:32 -0500 Subject: [Android] TimePicker unfocuses on cancel (#238) Related to the prior fix of the DatePicker not unfocusing on the cancel button being pressed, the TimePicker was not unfocusing, as well. A similar fix has been applied. --- .../Renderers/TimePickerRenderer.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'Xamarin.Forms.Platform.Android') diff --git a/Xamarin.Forms.Platform.Android/Renderers/TimePickerRenderer.cs b/Xamarin.Forms.Platform.Android/Renderers/TimePickerRenderer.cs index 4cb5d2d4..2b33acc6 100644 --- a/Xamarin.Forms.Platform.Android/Renderers/TimePickerRenderer.cs +++ b/Xamarin.Forms.Platform.Android/Renderers/TimePickerRenderer.cs @@ -27,6 +27,10 @@ namespace Xamarin.Forms.Platform.Android ElementController.SetValueFromRenderer(TimePicker.TimeProperty, new TimeSpan(hourOfDay, minute, 0)); Control.ClearFocus(); + + if (Forms.IsLollipopOrNewer) + _dialog.CancelEvent -= OnCancelButtonClicked; + _dialog = null; } @@ -70,6 +74,10 @@ namespace Xamarin.Forms.Platform.Android _dialog.Hide(); ElementController.SetValueFromRenderer(VisualElement.IsFocusedPropertyKey, false); Control.ClearFocus(); + + if (Forms.IsLollipopOrNewer) + _dialog.CancelEvent -= OnCancelButtonClicked; + _dialog = null; } } @@ -80,9 +88,18 @@ namespace Xamarin.Forms.Platform.Android ElementController.SetValueFromRenderer(VisualElement.IsFocusedPropertyKey, true); _dialog = new TimePickerDialog(Context, this, view.Time.Hours, view.Time.Minutes, false); + + if (Forms.IsLollipopOrNewer) + _dialog.CancelEvent += OnCancelButtonClicked; + _dialog.Show(); } + void OnCancelButtonClicked(object sender, EventArgs e) + { + Element.Unfocus(); + } + void SetTime(TimeSpan time) { Control.Text = DateTime.Today.Add(time).ToString(Element.Format); -- cgit v1.2.3