Skip to content

Commit 2137bb9

Browse files
Shalini-AshokanPureWeen
authored andcommitted
[iOS] Fix SwipeView programmatic open when background color is set. (#29765)
* Fixed the issue and added the test case * Modified the test case * Modified the fix * Committed the image
1 parent cea7172 commit 2137bb9

File tree

6 files changed

+89
-1
lines changed

6 files changed

+89
-1
lines changed
25.8 KB
Loading
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
namespace Maui.Controls.Sample.Issues;
2+
3+
[Issue(IssueTracker.Github, 17204, "SwipeView does not work correctly on iOS when opened programmatically", PlatformAffected.iOS)]
4+
public class Issue17204 : ContentPage
5+
{
6+
public Issue17204()
7+
{
8+
var verticalStack = new VerticalStackLayout
9+
{
10+
Spacing = 20,
11+
Padding = new Thickness(20)
12+
};
13+
14+
var swipeView = new SwipeView
15+
{
16+
Background = Colors.LightPink,
17+
};
18+
19+
var label = new Label
20+
{
21+
HeightRequest = 200,
22+
VerticalTextAlignment = TextAlignment.Center,
23+
Text = "Programmatic swipe works"
24+
};
25+
26+
var swipeItemView = new SwipeItemView
27+
{
28+
Background = Colors.LightGreen,
29+
Content = label,
30+
};
31+
32+
var swipeItems = new SwipeItems();
33+
swipeItems.Add(swipeItemView);
34+
swipeView.RightItems = swipeItems;
35+
36+
swipeView.Content = new Label
37+
{
38+
HeightRequest = 200,
39+
VerticalTextAlignment = TextAlignment.Center,
40+
Text = "Swipe view"
41+
};
42+
43+
var button = new Button
44+
{
45+
Text = "Open SwipeView",
46+
AutomationId = "OpenSwipeViewButton"
47+
};
48+
49+
button.Clicked += (sender, e) =>
50+
{
51+
swipeView.Open(OpenSwipeItem.RightItems, false);
52+
};
53+
54+
verticalStack.Add(swipeView);
55+
verticalStack.Add(button);
56+
Content = verticalStack;
57+
}
58+
}
11.9 KB
Loading
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#if TEST_FAILS_ON_WINDOWS // Cannot open programatically a SwipeView on Windows.
2+
using NUnit.Framework;
3+
using UITest.Appium;
4+
using UITest.Core;
5+
namespace Microsoft.Maui.TestCases.Tests.Issues;
6+
7+
public class Issue17204 : _IssuesUITest
8+
{
9+
public override string Issue => "SwipeView does not work correctly on iOS when opened programmatically";
10+
11+
public Issue17204(TestDevice device)
12+
: base(device)
13+
{ }
14+
15+
[Test]
16+
[Category(UITestCategories.SwipeView)]
17+
public void ProgrammaticallyOpenedSwipeViewShouldBeVisible()
18+
{
19+
App.WaitForElement("OpenSwipeViewButton");
20+
App.Tap("OpenSwipeViewButton");
21+
VerifyScreenshot();
22+
}
23+
}
24+
#endif
26.8 KB
Loading

src/Core/src/Platform/iOS/MauiSwipeView.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1144,11 +1144,17 @@ internal void ProgrammaticallyOpenSwipeItem(OpenSwipeItem openSwipeItem, bool an
11441144
return;
11451145

11461146
UpdateIsOpen(true);
1147+
UpdateSwipeItems();
11471148

11481149
var swipeThreshold = GetSwipeThreshold();
11491150
UpdateOffset(swipeThreshold);
11501151

1151-
UpdateSwipeItems();
1152+
// Set the background on the swipe view, we need to update the layout.
1153+
if (_contentView is WrapperView)
1154+
{
1155+
LayoutIfNeeded();
1156+
}
1157+
11521158
Swipe(animated);
11531159

11541160
_swipeOffset = Math.Abs(_swipeOffset);

0 commit comments

Comments
 (0)