Skip to content

Commit

Permalink
Invoke Clicked from SwipeItems (xamarin#11298)
Browse files Browse the repository at this point in the history
Co-authored-by: Samantha Houts <samhouts@users.noreply.github.com>
fixes xamarin#11286
  • Loading branch information
jsuarezruiz authored and sung-su committed Aug 20, 2020
1 parent 7e978f9 commit 5c88172
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
using Xamarin.Forms.Internals;
using Xamarin.Forms.CustomAttributes;
using System.Collections.Generic;

#if UITEST
using Xamarin.UITest;
using NUnit.Framework;
using Xamarin.Forms.Core.UITests;
#endif

namespace Xamarin.Forms.Controls.Issues
{
#if UITEST
[Category(UITestCategories.SwipeView)]
#endif
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Github, 11286,
"[Bug] SwipeItem clicked event not working",
PlatformAffected.Android)]
public class Issue11286 : TestContentPage
{
public Issue11286()
{
#if APP
Device.SetFlags(new List<string> { ExperimentalFlags.SwipeViewExperimental });
#endif
}

protected override void Init()
{
Title = "Issue 11286";

var layout = new StackLayout();

var instructions = new Label
{
Padding = 12,
BackgroundColor = Color.Black,
TextColor = Color.White,
Text = "Swipe to the right and tap the SwipeItem. If the text below the SwipeView is updated, the test has passed."
};

var swipeView = new SwipeView();

var swipeItem = new SwipeItem
{
BackgroundColor = Color.Red,
Text = "Text"
};

swipeView.LeftItems = new SwipeItems
{
swipeItem
};

var swipeContent = new Grid
{
HeightRequest = 80,
BackgroundColor = Color.LightGray
};

var label = new Label
{
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center,
Text = "Swipe to Right"
};

swipeContent.Children.Add(label);

swipeView.Content = swipeContent;

var result = new Label();

layout.Children.Add(instructions);
layout.Children.Add(swipeView);
layout.Children.Add(result);

Content = layout;

swipeItem.Clicked += (sender, args) =>
{
result.TextColor = Color.Green;
result.Text = "The test has passed";
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1458,6 +1458,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Issue11113.xaml.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue10182.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue11107.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue11286.cs" />
<Compile Include="$(MSBuildThisFileDirectory)RectTest.xaml.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue11224.xaml.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue11262.xaml.cs" />
Expand Down
1 change: 1 addition & 0 deletions Xamarin.Forms.Core/SwipeItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public void OnInvoked()
if (Command != null && Command.CanExecute(CommandParameter))
Command.Execute(CommandParameter);

OnClicked();
Invoked?.Invoke(this, EventArgs.Empty);
}
}
Expand Down

0 comments on commit 5c88172

Please sign in to comment.