Skip to content
106 changes: 106 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue23.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 23, "Horizontal swipes not working when SwipeItems are set in all directions", PlatformAffected.Windows)]
public partial class Issue23 : ContentPage
{
public Issue23()
{
Title = "Issue 23 - SwipeView All Directions";

var layout = new StackLayout
{
Margin = new Thickness(20),
Spacing = 20
};

// Create SwipeItems for all four directions
var leftSwipeItem = new SwipeItem
{
BackgroundColor = Colors.Blue,
Text = "Left",
AutomationId = "LeftSwipeItem"
};

var rightSwipeItem = new SwipeItem
{
BackgroundColor = Colors.Red,
Text = "Right",
AutomationId = "RightSwipeItem"
};

var topSwipeItem = new SwipeItem
{
BackgroundColor = Colors.Green,
Text = "Top",
AutomationId = "TopSwipeItem"
};

var bottomSwipeItem = new SwipeItem
{
BackgroundColor = Colors.Orange,
Text = "Bottom",
AutomationId = "BottomSwipeItem"
};

// Add event handlers to track which swipe was triggered
var resultLabel = new Label
{
AutomationId = "ResultLabel",
Text = "No swipe detected",
HorizontalOptions = LayoutOptions.Center,
FontSize = 16
};

leftSwipeItem.Invoked += (s, e) => resultLabel.Text = "Left swipe triggered";
rightSwipeItem.Invoked += (s, e) => resultLabel.Text = "Right swipe triggered";
topSwipeItem.Invoked += (s, e) => resultLabel.Text = "Top swipe triggered";
bottomSwipeItem.Invoked += (s, e) => resultLabel.Text = "Bottom swipe triggered";

// Create SwipeView with items in all four directions
var swipeView = new SwipeView
{
AutomationId = "SwipeViewAllDirections",
HeightRequest = 120,
WidthRequest = 300,
HorizontalOptions = LayoutOptions.Center,
LeftItems = new SwipeItems { leftSwipeItem },
RightItems = new SwipeItems { rightSwipeItem },
TopItems = new SwipeItems { topSwipeItem },
BottomItems = new SwipeItems { bottomSwipeItem }
};

// Create content for the SwipeView
var swipeContent = new Grid
{
BackgroundColor = Colors.LightGray
};

var contentLabel = new Label
{
Text = "Swipe in any direction\n(Left/Right should work with Top/Bottom)",
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center,
TextColor = Colors.Black,
HorizontalTextAlignment = TextAlignment.Center
};

swipeContent.Children.Add(contentLabel);
swipeView.Content = swipeContent;

// Instructions
var instructionsLabel = new Label
{
Text = "Test: Swipe LEFT and RIGHT when all four directions are configured.\nBoth horizontal swipes should work correctly.",
FontSize = 14,
HorizontalOptions = LayoutOptions.Center,
HorizontalTextAlignment = TextAlignment.Center,
Margin = new Thickness(0, 10)
};

layout.Children.Add(instructionsLabel);
layout.Children.Add(swipeView);
layout.Children.Add(resultLabel);

Content = layout;
}
}
111 changes: 111 additions & 0 deletions src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue23.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues
{
public class Issue23 : _IssuesUITest
{
public override string Issue => "Horizontal swipes not working when SwipeItems are set in all directions";

public Issue23(TestDevice device)
: base(device)
{
}

[Test]
[Category(UITestCategories.SwipeView)]
public void HorizontalSwipesShouldWorkWhenAllDirectionsConfigured()
{
var swipeView = App.WaitForElement("SwipeViewAllDirections");
var resultLabel = App.WaitForElement("ResultLabel");

// Verify initial state
Assert.AreEqual("No swipe detected", resultLabel.GetText());

// Test left swipe (swipe from right to left to reveal left items)
var rect = swipeView.GetRect();
var centerX = rect.X + rect.Width / 2;
var centerY = rect.Y + rect.Height / 2;
var leftX = rect.X + 50;

App.DragCoordinates(centerX, centerY, leftX, centerY);
App.WaitForElement("LeftSwipeItem");

// Tap the left swipe item to trigger it
App.Tap("LeftSwipeItem");

// Wait a bit for the action to complete
System.Threading.Thread.Sleep(500);

// Verify left swipe was triggered
var leftResult = resultLabel.GetText();
Assert.AreEqual("Left swipe triggered", leftResult, "Left swipe should be triggered when swiping from right to left");

// Close the swipe view by tapping the center
App.Tap("SwipeViewAllDirections");
System.Threading.Thread.Sleep(500);

// Test right swipe (swipe from left to right to reveal right items)
var rightX = rect.X + rect.Width - 50;
App.DragCoordinates(centerX, centerY, rightX, centerY);
App.WaitForElement("RightSwipeItem");

// Tap the right swipe item to trigger it
App.Tap("RightSwipeItem");

// Wait a bit for the action to complete
System.Threading.Thread.Sleep(500);

// Verify right swipe was triggered
var rightResult = resultLabel.GetText();
Assert.AreEqual("Right swipe triggered", rightResult, "Right swipe should be triggered when swiping from left to right");
}

[Test]
[Category(UITestCategories.SwipeView)]
public void VerticalSwipesShouldAlsoWorkWhenAllDirectionsConfigured()
{
var swipeView = App.WaitForElement("SwipeViewAllDirections");
var resultLabel = App.WaitForElement("ResultLabel");

// Test top swipe (swipe from bottom to top to reveal top items)
var rect = swipeView.GetRect();
var centerX = rect.X + rect.Width / 2;
var centerY = rect.Y + rect.Height / 2;
var topY = rect.Y + 20;

App.DragCoordinates(centerX, centerY, centerX, topY);
App.WaitForElement("TopSwipeItem");

// Tap the top swipe item to trigger it
App.Tap("TopSwipeItem");

// Wait a bit for the action to complete
System.Threading.Thread.Sleep(500);

// Verify top swipe was triggered
var topResult = resultLabel.GetText();
Assert.AreEqual("Top swipe triggered", topResult, "Top swipe should be triggered when swiping from bottom to top");

// Close the swipe view by tapping the center
App.Tap("SwipeViewAllDirections");
System.Threading.Thread.Sleep(500);

// Test bottom swipe (swipe from top to bottom to reveal bottom items)
var bottomY = rect.Y + rect.Height - 20;
App.DragCoordinates(centerX, centerY, centerX, bottomY);
App.WaitForElement("BottomSwipeItem");

// Tap the bottom swipe item to trigger it
App.Tap("BottomSwipeItem");

// Wait a bit for the action to complete
System.Threading.Thread.Sleep(500);

// Verify bottom swipe was triggered
var bottomResult = resultLabel.GetText();
Assert.AreEqual("Bottom swipe triggered", bottomResult, "Bottom swipe should be triggered when swiping from top to bottom");
}
}
}
12 changes: 10 additions & 2 deletions src/Core/src/Handlers/SwipeView/SwipeViewHandler.Windows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,13 @@ void OnLoaded(object sender, UI.Xaml.RoutedEventArgs e)
if (!PlatformView.IsLoaded)
return;

// Setting the Left/Right Items before the view has loaded causes the Swipe Control
// Setting the SwipeItems before the view has loaded causes the Swipe Control
// to crash on the first layout pass. So we wait until the control has been loaded
// before propagating our Left/Right Items
// before propagating all SwipeItems to ensure consistent timing
UpdateValue(nameof(ISwipeView.LeftItems));
UpdateValue(nameof(ISwipeView.RightItems));
UpdateValue(nameof(ISwipeView.TopItems));
UpdateValue(nameof(ISwipeView.BottomItems));
PlatformView.Loaded -= OnLoaded;
}

Expand All @@ -88,6 +90,9 @@ public static void MapLeftItems(ISwipeViewHandler handler, ISwipeView view)

public static void MapTopItems(ISwipeViewHandler handler, ISwipeView view)
{
if (!handler.PlatformView.IsLoaded)
return;

UpdateSwipeItems(SwipeDirection.Up, handler, view, (items) => handler.PlatformView.TopItems = items, view.TopItems, handler.PlatformView.TopItems);
}

Expand All @@ -101,6 +106,9 @@ public static void MapRightItems(ISwipeViewHandler handler, ISwipeView view)

public static void MapBottomItems(ISwipeViewHandler handler, ISwipeView view)
{
if (!handler.PlatformView.IsLoaded)
return;

UpdateSwipeItems(SwipeDirection.Down, handler, view, (items) => handler.PlatformView.BottomItems = items, view.BottomItems, handler.PlatformView.BottomItems);
}

Expand Down