зеркало из https://github.com/DeGsoft/maui-linux.git
[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.
This commit is contained in:
Родитель
c08027804e
Коммит
39b12a4864
|
@ -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
|
||||
}
|
||||
}
|
|
@ -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" />
|
||||
|
|
|
@ -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);
|
||||
|
|
Загрузка…
Ссылка в новой задаче