diff options
3 files changed, 79 insertions, 0 deletions
diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla42074.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla42074.cs new file mode 100644 index 00000000..04bcdf8c --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla42074.cs @@ -0,0 +1,61 @@ +using System; + +using Xamarin.Forms.CustomAttributes; +using Xamarin.Forms.Internals; + +#if UITEST +using Xamarin.UITest; +using NUnit.Framework; +#endif + +namespace Xamarin.Forms.Controls.Issues +{ + [Preserve(AllMembers = true)] + [Issue(IssueTracker.Bugzilla, 42074, "[Android] Clicking cancel on a TimePicker does not cause it to unfocus", PlatformAffected.Android)] + public class Bugzilla42074 : TestContentPage + { + const string TimePicker = "TimePicker"; + + protected override void Init() + { + var timePicker = new TimePicker + { + AutomationId = TimePicker + }; + var timePickerFocusButton = new Button + { + Text = "Click to focus TimePicker", + Command = new Command(() => timePicker.Focus()) + }; + Content = new StackLayout + { + Children = + { + timePicker, + timePickerFocusButton + } + }; + } + +#if UITEST + +#if __ANDROID__ + [Test] + public void TimePickerCancelShouldUnfocus() + { + RunningApp.Tap(q => q.Marked(TimePicker)); + RunningApp.WaitForElement(q => q.Marked("Cancel")); + + RunningApp.Tap(q => q.Marked("Cancel")); + RunningApp.WaitForElement(q => q.Marked("Click to focus TimePicker")); + + RunningApp.Tap(q => q.Marked("Click to focus TimePicker")); + RunningApp.WaitForElement(q => q.Marked("Cancel")); + + RunningApp.Tap(q => q.Marked("Cancel")); + } +#endif + +#endif + } +} diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems index 10e0800c..7a7db40b 100644 --- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems @@ -108,6 +108,7 @@ <Compile Include="$(MSBuildThisFileDirectory)Bugzilla41078.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Bugzilla40998.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Bugzilla41424.cs" /> + <Compile Include="$(MSBuildThisFileDirectory)Bugzilla42074.cs" /> <Compile Include="$(MSBuildThisFileDirectory)CarouselAsync.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Bugzilla34561.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Bugzilla34727.cs" /> 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); |