[iOS] Change Button state if the touch-up event occurs outside (#11441) fixes #11430

* Added repro sample

* Fixed the issue

* Updated the sample

Co-authored-by: Samantha Houts <samhouts@users.noreply.github.com>
This commit is contained in:
Javier Suárez 2020-07-29 13:30:10 +02:00 коммит произвёл GitHub
Родитель 4682bef762
Коммит c8ccf6089c
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 68 добавлений и 0 удалений

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

@ -0,0 +1,55 @@
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
#if UITEST
using Xamarin.UITest;
using NUnit.Framework;
using Xamarin.Forms.Core.UITests;
#endif
namespace Xamarin.Forms.Controls.Issues
{
#if UITEST
[Category(UITestCategories.Frame)]
#endif
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Github, 11430,
"[Bug] [iOS] Button stays in Pressed state if the touch-up event occurs outside",
PlatformAffected.iOS)]
public class Issue11430 : TestContentPage
{
public Issue11430()
{
}
protected override void Init()
{
Title = "Issue 11430";
var layout = new StackLayout();
var instructions = new Label
{
Padding = 12,
BackgroundColor = Color.Black,
TextColor = Color.White,
Text = "Tap a Button, drag your finger outside the Button and lift up your finger. If the Button state is Normal, the test has passed."
};
var button = new Button
{
Text = "Click Me"
};
layout.Children.Add(instructions);
layout.Children.Add(button);
Content = layout;
button.Clicked += (sender, args) =>
{
DisplayAlert("Issue 11430", "Button Clicked.", "Ok");
};
}
}
}

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

@ -1440,6 +1440,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Issue11291.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue11244.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue11272.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue11430.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue11247.cs" />
</ItemGroup>
<ItemGroup>

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

@ -85,5 +85,10 @@ namespace Xamarin.Forms.Platform.iOS
element?.SendReleased();
element?.SendClicked();
}
internal static void OnButtonTouchUpOutside(IButtonController element)
{
element?.SendReleased();
}
}
}

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

@ -62,6 +62,7 @@ namespace Xamarin.Forms.Platform.iOS
if (Control != null)
{
Control.TouchUpInside -= OnButtonTouchUpInside;
Control.TouchUpOutside -= OnButtonTouchUpOutside;
Control.TouchDown -= OnButtonTouchDown;
BorderElementManager.Dispose(this);
_buttonLayoutManager?.Dispose();
@ -93,6 +94,7 @@ namespace Xamarin.Forms.Platform.iOS
_buttonTextColorDefaultDisabled = Control.TitleColor(UIControlState.Disabled);
Control.TouchUpInside += OnButtonTouchUpInside;
Control.TouchUpOutside += OnButtonTouchUpOutside;
Control.TouchDown += OnButtonTouchDown;
}
@ -147,6 +149,11 @@ namespace Xamarin.Forms.Platform.iOS
ButtonElementManager.OnButtonTouchUpInside(this.Element);
}
void OnButtonTouchUpOutside(object sender, EventArgs eventArgs)
{
ButtonElementManager.OnButtonTouchUpOutside(this.Element);
}
void OnButtonTouchDown(object sender, EventArgs eventArgs)
{
ButtonElementManager.OnButtonTouchDown(this.Element);