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

Commit

Permalink
[iOS] Change Button state if the touch-up event occurs outside (#11441)
Browse files Browse the repository at this point in the history
fixes #11430

* Added repro sample

* Fixed the issue

* Updated the sample

Co-authored-by: Samantha Houts <samhouts@users.noreply.github.com>
  • Loading branch information
jsuarezruiz and samhouts committed Jul 29, 2020
1 parent 4682bef commit c8ccf60
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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");
};
}
}
}
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit c8ccf60

Please sign in to comment.