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

[Core] Invoke Clicked event tapping SwipeItems #11298

Merged
merged 4 commits into from
Aug 17, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1430,6 +1430,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)Issue11120.xaml.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue11291.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue11272.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))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while you're at it, OnInvoked could be an explicit interface implementation

Command.Execute(CommandParameter);

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