[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.
This commit is contained in:
Paul DiPietro 2016-06-16 13:51:16 -04:00 коммит произвёл Rui Marinho
Родитель af6ac9649f
Коммит d44396a453
3 изменённых файлов: 73 добавлений и 0 удалений

Просмотреть файл

@ -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
}
}

Просмотреть файл

@ -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" />

Просмотреть файл

@ -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);