Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

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

Merged
merged 4 commits into from Jul 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -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");
};
}
}
}
Expand Up @@ -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>
Expand Down
5 changes: 5 additions & 0 deletions Xamarin.Forms.Platform.iOS/Renderers/ButtonElementManager.cs
Expand Up @@ -85,5 +85,10 @@ internal static void OnButtonTouchUpInside(IButtonController element)
element?.SendReleased();
element?.SendClicked();
}

internal static void OnButtonTouchUpOutside(IButtonController element)
{
element?.SendReleased();
}
}
}
7 changes: 7 additions & 0 deletions Xamarin.Forms.Platform.iOS/Renderers/ButtonRenderer.cs
Expand Up @@ -62,6 +62,7 @@ protected override void Dispose(bool disposing)
if (Control != null)
{
Control.TouchUpInside -= OnButtonTouchUpInside;
Control.TouchUpOutside -= OnButtonTouchUpOutside;
Control.TouchDown -= OnButtonTouchDown;
BorderElementManager.Dispose(this);
_buttonLayoutManager?.Dispose();
Expand Down Expand Up @@ -93,6 +94,7 @@ protected override void OnElementChanged(ElementChangedEventArgs<Button> e)
_buttonTextColorDefaultDisabled = Control.TitleColor(UIControlState.Disabled);

Control.TouchUpInside += OnButtonTouchUpInside;
Control.TouchUpOutside += OnButtonTouchUpOutside;
Control.TouchDown += OnButtonTouchDown;
}

Expand Down Expand Up @@ -147,6 +149,11 @@ void OnButtonTouchUpInside(object sender, EventArgs eventArgs)
ButtonElementManager.OnButtonTouchUpInside(this.Element);
}

void OnButtonTouchUpOutside(object sender, EventArgs eventArgs)
{
ButtonElementManager.OnButtonTouchUpOutside(this.Element);
}

void OnButtonTouchDown(object sender, EventArgs eventArgs)
{
ButtonElementManager.OnButtonTouchDown(this.Element);
Expand Down