зеркало из https://github.com/DeGsoft/maui-linux.git
The Completed event should be invoked when the user presses the return key only. Using NSTextField DidEndEditing is not favorable because pressing the Tab key will cause this method as well
This commit is contained in:
Родитель
fa1df7bdcd
Коммит
a447b5b1af
|
@ -0,0 +1,69 @@
|
||||||
|
using System;
|
||||||
|
using Xamarin.Forms.CustomAttributes;
|
||||||
|
using Xamarin.Forms.Internals;
|
||||||
|
|
||||||
|
#if UITEST
|
||||||
|
using NUnit.Framework;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace Xamarin.Forms.Controls.Issues
|
||||||
|
{
|
||||||
|
[Preserve(AllMembers = true)]
|
||||||
|
[Issue(IssueTracker.Github, 1650, "[macOS] Completed event of Entry raised on Tab key", PlatformAffected.macOS)]
|
||||||
|
public class GitHub1650 : TestContentPage
|
||||||
|
{
|
||||||
|
Label _completedCountLabel = new Label
|
||||||
|
{
|
||||||
|
Text = "Completed count: 0",
|
||||||
|
AutomationId = "CompletedCountLabel"
|
||||||
|
};
|
||||||
|
|
||||||
|
int _completedCount;
|
||||||
|
public int CompletedCount
|
||||||
|
{
|
||||||
|
get { return _completedCount; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_completedCount = value;
|
||||||
|
_completedCountLabel.Text = $"Completed count: {value}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Init()
|
||||||
|
{
|
||||||
|
// Setup our completed entry
|
||||||
|
var entry = new Entry
|
||||||
|
{
|
||||||
|
Placeholder = "Press enter here!",
|
||||||
|
AutomationId = "CompletedTargetEntry"
|
||||||
|
};
|
||||||
|
entry.Completed += (sender, e) =>
|
||||||
|
{
|
||||||
|
CompletedCount++;
|
||||||
|
};
|
||||||
|
|
||||||
|
StackLayout layout = new StackLayout();
|
||||||
|
layout.Children.Add(_completedCountLabel);
|
||||||
|
layout.Children.Add(entry);
|
||||||
|
|
||||||
|
Content = layout;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if UITEST
|
||||||
|
#if __MACOS__
|
||||||
|
[Test]
|
||||||
|
public void GitHub1650Test()
|
||||||
|
{
|
||||||
|
RunningApp.WaitForElement(q => q.Marked("CompletedTargetEntry"));
|
||||||
|
RunningApp.Tap(q => q.Marked("CompletedTargetEntry"));
|
||||||
|
|
||||||
|
Assert.AreEqual(0, _completedCount, "Completed should not have been fired");
|
||||||
|
|
||||||
|
RunningApp.PressEnter();
|
||||||
|
|
||||||
|
Assert.AreEqual(1, _completedCount, "Completed should have been fired once");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
|
@ -773,6 +773,7 @@
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Issue2728.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Issue2728.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Issue1667.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Issue1667.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Issue3012.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Issue3012.cs" />
|
||||||
|
<Compile Include="$(MSBuildThisFileDirectory)GitHub1650.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)GitHub3216.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)GitHub3216.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)GitHub1776.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)GitHub1776.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
|
@ -11,6 +11,8 @@ namespace Xamarin.Forms.Platform.MacOS
|
||||||
{
|
{
|
||||||
public EventHandler<BoolEventArgs> FocusChanged;
|
public EventHandler<BoolEventArgs> FocusChanged;
|
||||||
|
|
||||||
|
public EventHandler Completed;
|
||||||
|
|
||||||
bool _windowEventsSet;
|
bool _windowEventsSet;
|
||||||
|
|
||||||
bool _disposed;
|
bool _disposed;
|
||||||
|
@ -40,10 +42,18 @@ namespace Xamarin.Forms.Platform.MacOS
|
||||||
{
|
{
|
||||||
if (CurrentEditor != Window.FirstResponder)
|
if (CurrentEditor != Window.FirstResponder)
|
||||||
FocusChanged?.Invoke(this, new BoolEventArgs(false));
|
FocusChanged?.Invoke(this, new BoolEventArgs(false));
|
||||||
|
|
||||||
base.DidEndEditing(notification);
|
base.DidEndEditing(notification);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void KeyUp(NSEvent theEvent)
|
||||||
|
{
|
||||||
|
base.KeyUp(theEvent);
|
||||||
|
|
||||||
|
if (theEvent.KeyCode == (ushort)NSKey.Return)
|
||||||
|
Completed?.Invoke(this, EventArgs.Empty);
|
||||||
|
}
|
||||||
|
|
||||||
protected override void Dispose(bool disposing)
|
protected override void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
if (disposing && !_disposed)
|
if (disposing && !_disposed)
|
||||||
|
@ -92,6 +102,7 @@ namespace Xamarin.Forms.Platform.MacOS
|
||||||
{
|
{
|
||||||
textField = new FormsNSTextField();
|
textField = new FormsNSTextField();
|
||||||
(textField as FormsNSTextField).FocusChanged += TextFieldFocusChanged;
|
(textField as FormsNSTextField).FocusChanged += TextFieldFocusChanged;
|
||||||
|
(textField as FormsNSTextField).Completed += OnCompleted;
|
||||||
}
|
}
|
||||||
|
|
||||||
SetNativeControl(textField);
|
SetNativeControl(textField);
|
||||||
|
@ -167,7 +178,10 @@ namespace Xamarin.Forms.Platform.MacOS
|
||||||
Control.EditingEnded -= OnEditingEnded;
|
Control.EditingEnded -= OnEditingEnded;
|
||||||
var formsNSTextField = (Control as FormsNSTextField);
|
var formsNSTextField = (Control as FormsNSTextField);
|
||||||
if (formsNSTextField != null)
|
if (formsNSTextField != null)
|
||||||
|
{
|
||||||
formsNSTextField.FocusChanged -= TextFieldFocusChanged;
|
formsNSTextField.FocusChanged -= TextFieldFocusChanged;
|
||||||
|
formsNSTextField.Completed -= OnCompleted;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -193,6 +207,10 @@ namespace Xamarin.Forms.Platform.MacOS
|
||||||
void OnEditingEnded(object sender, EventArgs e)
|
void OnEditingEnded(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
ElementController.SetValueFromRenderer(VisualElement.IsFocusedPropertyKey, false);
|
ElementController.SetValueFromRenderer(VisualElement.IsFocusedPropertyKey, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnCompleted(object sender, EventArgs e)
|
||||||
|
{
|
||||||
EntryController?.SendCompleted();
|
EntryController?.SendCompleted();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче