diff options
author | Paul DiPietro <pauldipietro@users.noreply.github.com> | 2016-06-16 13:51:16 -0400 |
---|---|---|
committer | Rui Marinho <me@ruimarinho.net> | 2016-06-16 18:51:16 +0100 |
commit | d44396a4534b1e2bc81143c809e4adaee656ab15 (patch) | |
tree | 7e98b02e4052b32e4a12d153a973131aa6918053 | |
parent | af6ac9649f71d1557dffa3dc3357868016ebc1e7 (diff) | |
download | xamarin-forms-d44396a4534b1e2bc81143c809e4adaee656ab15.tar.gz xamarin-forms-d44396a4534b1e2bc81143c809e4adaee656ab15.tar.bz2 xamarin-forms-d44396a4534b1e2bc81143c809e4adaee656ab15.zip |
[Android] DatePicker unfocuses on cancel (#204)
The DatePicker in Android would remain focused when being closed via the
cancel button, and a subsequent re-focus via something such as button
would not function as expected.
3 files changed, 73 insertions, 0 deletions
diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla41424.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla41424.cs new file mode 100644 index 00000000..87386965 --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla41424.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 +{ + [Preserve(AllMembers = true)] + [Issue(IssueTracker.Bugzilla, 41424, "[Android] Clicking cancel on a DatePicker does not cause it to unfocus", PlatformAffected.Android)] + public class Bugzilla41424 : TestContentPage + { + const string DatePicker = "DatePicker"; + + protected override void Init() + { + var datePicker = new DatePicker + { + AutomationId = DatePicker + }; + var datePickerFocusButton = new Button + { + Text = "Click to focus DatePicker", + Command = new Command(() => datePicker.Focus()) + }; + Content = new StackLayout + { + Children = + { + datePicker, + datePickerFocusButton + } + }; + } + +#if UITEST + +#if __ANDROID__ + [Test] + public void DatePickerCancelShouldUnfocus() + { + RunningApp.Tap(q => q.Marked(DatePicker)); + RunningApp.WaitForElement(q => q.Marked("Cancel")); + + RunningApp.Tap(q => q.Marked("Cancel")); + RunningApp.WaitForElement(q => q.Marked("Click to focus DatePicker")); + + RunningApp.Tap(q => q.Marked("Click to focus DatePicker")); + 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 1e9d1ea0..c857bbb9 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 @@ -106,6 +106,7 @@ <Compile Include="$(MSBuildThisFileDirectory)Bugzilla31806.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Bugzilla41078.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Bugzilla40998.cs" /> + <Compile Include="$(MSBuildThisFileDirectory)Bugzilla41424.cs" /> <Compile Include="$(MSBuildThisFileDirectory)CarouselAsync.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Bugzilla34561.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Bugzilla34727.cs" /> diff --git a/Xamarin.Forms.Platform.Android/Renderers/DatePickerRenderer.cs b/Xamarin.Forms.Platform.Android/Renderers/DatePickerRenderer.cs index 5b0e0994..328336ff 100644 --- a/Xamarin.Forms.Platform.Android/Renderers/DatePickerRenderer.cs +++ b/Xamarin.Forms.Platform.Android/Renderers/DatePickerRenderer.cs @@ -31,6 +31,7 @@ namespace Xamarin.Forms.Platform.Android _disposed = true; if (_dialog != null) { + _dialog.CancelEvent -= OnCancelButtonClicked; _dialog.Hide(); _dialog.Dispose(); _dialog = null; @@ -84,6 +85,7 @@ namespace Xamarin.Forms.Platform.Android _dialog.Hide(); ((IElementController)Element).SetValueFromRenderer(VisualElement.IsFocusedPropertyKey, false); Control.ClearFocus(); + _dialog.CancelEvent -= OnCancelButtonClicked; _dialog = null; } } @@ -96,6 +98,8 @@ namespace Xamarin.Forms.Platform.Android view.Date = e.Date; ((IElementController)view).SetValueFromRenderer(VisualElement.IsFocusedPropertyKey, false); Control.ClearFocus(); + + _dialog.CancelEvent -= OnCancelButtonClicked; _dialog = null; }, year, month, day); } @@ -123,9 +127,16 @@ namespace Xamarin.Forms.Platform.Android UpdateMinimumDate(); UpdateMaximumDate(); + + _dialog.CancelEvent += OnCancelButtonClicked; _dialog.Show(); } + void OnCancelButtonClicked(object sender, EventArgs e) + { + Element.Unfocus(); + } + void SetDate(DateTime date) { Control.Text = date.ToString(Element.Format); |