Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 117 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue34917.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 34917, "[net 11.0][iOS,MacCatalyst] SwipeView.Open() throws ArgumentException on second programmatic call", PlatformAffected.iOS | PlatformAffected.macOS)]
public class Issue34917 : ContentPage
{
const string OpenRightButtonId = "OpenSwipeButton";
const string OpenBottomButtonId = "OpenBottomSwipeButton";
const string CloseButtonId = "CloseSwipeButton";
const string StatusLabelId = "StatusLabel";

readonly SwipeView _swipeView;

public Issue34917()
{
var openRightButton = new Button
{
Text = "Open RightItems",
AutomationId = OpenRightButtonId
};

var openBottomButton = new Button
{
Text = "Open BottomItems",
AutomationId = OpenBottomButtonId
};

var closeButton = new Button
{
Text = "Close SwipeView",
AutomationId = CloseButtonId
};

var statusLabel = new Label
{
Text = "Ready",
AutomationId = StatusLabelId,
HorizontalOptions = LayoutOptions.Center
};

var rightSwipeItem = new SwipeItem
{
Text = "Right Action",
BackgroundColor = Colors.LightBlue
};

var bottomSwipeItem = new SwipeItem
{
Text = "Bottom Action",
BackgroundColor = Colors.LightGreen
};

_swipeView = new SwipeView
{
HeightRequest = 60,
RightItems = new SwipeItems { rightSwipeItem },
BottomItems = new SwipeItems { bottomSwipeItem },
Content = new Grid
{
BackgroundColor = Colors.LightGray,
Children =
{
new Label
{
Text = "Swipe content",
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center
}
}
}
};

openRightButton.Clicked += (s, e) =>
{
try
{
_swipeView.Open(OpenSwipeItem.RightItems);
statusLabel.Text = "Success";
}
catch (Exception ex)
{
statusLabel.Text = $"Error: {ex.GetType().Name}";
}
};

openBottomButton.Clicked += (s, e) =>
{
try
{
_swipeView.Open(OpenSwipeItem.BottomItems);
statusLabel.Text = "Success";
}
catch (Exception ex)
{
statusLabel.Text = $"Error: {ex.GetType().Name}";
}
};

closeButton.Clicked += (s, e) =>
{
_swipeView.Close();
};

Content = new VerticalStackLayout
{
Spacing = 12,
Padding = new Thickness(20),
Children =
{
openRightButton,
openBottomButton,
closeButton,
_swipeView,
statusLabel
}
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;

public class Issue34917 : _IssuesUITest
{
public Issue34917(TestDevice device) : base(device) { }

public override string Issue => "[net 11.0][iOS,MacCatalyst] SwipeView.Open() throws ArgumentException on second programmatic call";

[Test]
[Category(UITestCategories.SwipeView)]
public void SwipeViewOpenRightDoesNotThrowOnSecondCall()
{
App.WaitForElement(OpenRightButtonId);

App.Tap(OpenRightButtonId);
App.WaitForElement(StatusLabelId);
App.WaitForTextToBePresentInElement(StatusLabelId, "Success");
Assert.That(App.FindElement(StatusLabelId).GetText(), Is.EqualTo("Success"),
"First Open(RightItems) call should succeed.");

App.Tap(OpenRightButtonId);
App.WaitForTextToBePresentInElement(StatusLabelId, "Success");
Assert.That(App.FindElement(StatusLabelId).GetText(), Is.EqualTo("Success"),
"Second consecutive Open(RightItems) call should not throw an exception.");
Comment thread
BagavathiPerumal marked this conversation as resolved.
}

[Test]
[Category(UITestCategories.SwipeView)]
public void SwipeViewOpenBottomDoesNotThrowOnSecondCall()
{
App.WaitForElement(OpenBottomButtonId);
App.WaitForElement(CloseButtonId);

App.Tap(CloseButtonId);

App.Tap(OpenBottomButtonId);
App.WaitForElement(StatusLabelId);
App.WaitForTextToBePresentInElement(StatusLabelId, "Success");
Assert.That(App.FindElement(StatusLabelId).GetText(), Is.EqualTo("Success"),
"First Open(BottomItems) call should succeed.");

App.Tap(OpenBottomButtonId);
App.WaitForTextToBePresentInElement(StatusLabelId, "Success");
Assert.That(App.FindElement(StatusLabelId).GetText(), Is.EqualTo("Success"),
"Second consecutive Open(BottomItems) call should not throw an exception.");
Comment thread
BagavathiPerumal marked this conversation as resolved.
}

const string OpenRightButtonId = "OpenSwipeButton";
const string OpenBottomButtonId = "OpenBottomSwipeButton";
const string CloseButtonId = "CloseSwipeButton";
const string StatusLabelId = "StatusLabel";
}
3 changes: 1 addition & 2 deletions src/Core/src/Platform/iOS/MauiSwipeView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ void UpdateSwipeItems()
return;

_swipeItemsRect = new List<CGRect>();
_swipeItems.Clear();

double swipeItemsWidth;

Expand Down Expand Up @@ -1165,8 +1166,6 @@ internal void ProgrammaticallyOpenSwipeItem(OpenSwipeItem openSwipeItem, bool an
}

Swipe(animated);

_swipeOffset = Math.Abs(_swipeOffset);
}

void UpdateOffset(double swipeOffset)
Expand Down
Loading