Skip to content

Commit c5351a9

Browse files
Dhivya-SF4094PureWeen
authored andcommitted
Fixed ItemSpacing on CarouselView resizes items [Android] (#29796)
* Fixed ItemSpacing on CarouselView * Added snapshot for Android and Mac * Resaved image for CarouselViewShouldRenderCorrectly
1 parent 26d4fe3 commit c5351a9

File tree

7 files changed

+98
-2
lines changed

7 files changed

+98
-2
lines changed

src/Controls/src/Core/Handlers/Items/CarouselViewHandler.Android.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ double GetItemWidth()
9595
if (double.IsInfinity(width))
9696
return width;
9797

98-
itemWidth = (int)(width - Context?.ToPixels(VirtualView.PeekAreaInsets.Left) - Context?.ToPixels(VirtualView.PeekAreaInsets.Right) - Context?.ToPixels(listItemsLayout.ItemSpacing));
98+
itemWidth = (int)(width - Context?.ToPixels(VirtualView.PeekAreaInsets.Left) - Context?.ToPixels(VirtualView.PeekAreaInsets.Right));
9999
}
100100

101101
return itemWidth;
@@ -112,7 +112,7 @@ double GetItemHeight()
112112
if (double.IsInfinity(height))
113113
return height;
114114

115-
itemHeight = (int)(height - Context?.ToPixels(VirtualView.PeekAreaInsets.Top) - Context?.ToPixels(VirtualView.PeekAreaInsets.Bottom) - Context?.ToPixels(listItemsLayout.ItemSpacing));
115+
itemHeight = (int)(height - Context?.ToPixels(VirtualView.PeekAreaInsets.Top) - Context?.ToPixels(VirtualView.PeekAreaInsets.Bottom));
116116
}
117117

118118
return itemHeight;
-27 Bytes
Loading
15.7 KB
Loading
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
using System.Collections.ObjectModel;
2+
3+
namespace Maui.Controls.Sample.Issues;
4+
5+
[Issue(IssueTracker.Github, 29609, "ItemSpacing on CarouselView resizes items", PlatformAffected.Android)]
6+
public class Issue29609 : ContentPage
7+
{
8+
Issue29609_ViewModel ViewModel;
9+
public Issue29609()
10+
{
11+
ViewModel = new Issue29609_ViewModel();
12+
BindingContext = ViewModel;
13+
var stack = new StackLayout
14+
{
15+
VerticalOptions = LayoutOptions.Center,
16+
HorizontalOptions = LayoutOptions.Center
17+
};
18+
var label = new Label
19+
{
20+
Text = "ItemSpacing on CarouselView resizes items",
21+
AutomationId = "29609DescriptionLabel"
22+
};
23+
var carouselView = new CarouselView
24+
{
25+
BackgroundColor = Colors.Red,
26+
AutomationId = "29609CarouselView",
27+
HeightRequest = 400,
28+
WidthRequest = 300,
29+
ItemsSource = ViewModel.Items,
30+
Loop = false,
31+
ItemsLayout = new LinearItemsLayout(ItemsLayoutOrientation.Horizontal)
32+
{
33+
ItemSpacing = 50,
34+
SnapPointsAlignment = SnapPointsAlignment.Center,
35+
SnapPointsType = SnapPointsType.MandatorySingle
36+
},
37+
ItemTemplate = new DataTemplate(() =>
38+
{
39+
var grid = new Grid
40+
{
41+
BackgroundColor = Colors.Yellow
42+
};
43+
44+
var label = new Label
45+
{
46+
HorizontalOptions = LayoutOptions.Center,
47+
VerticalOptions = LayoutOptions.Center
48+
};
49+
label.SetBinding(Label.TextProperty, ".");
50+
51+
grid.Children.Add(label);
52+
return grid;
53+
})
54+
};
55+
stack.Children.Add(label);
56+
stack.Children.Add(carouselView);
57+
Content = stack;
58+
}
59+
}
60+
61+
public class Issue29609_ViewModel
62+
{
63+
public ObservableCollection<string> Items = new();
64+
65+
public Issue29609_ViewModel()
66+
{
67+
for (var i = 0; i < 5; i++)
68+
{
69+
Items.Add($"Item {i}");
70+
}
71+
}
72+
}
12.2 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 // ItemSpacing on CarouselView is not applied on Windows https://github.com/dotnet/maui/issues/29772
2+
using NUnit.Framework;
3+
using UITest.Appium;
4+
using UITest.Core;
5+
6+
namespace Microsoft.Maui.TestCases.Tests.Issues;
7+
8+
public class Issue29609 : _IssuesUITest
9+
{
10+
public Issue29609(TestDevice testDevice) : base(testDevice)
11+
{
12+
}
13+
14+
public override string Issue => "ItemSpacing on CarouselView resizes items";
15+
16+
[Test]
17+
[Category(UITestCategories.CarouselView)]
18+
public void VerifySpacingAffectsItemSize()
19+
{
20+
App.WaitForElement("29609DescriptionLabel");
21+
VerifyScreenshot();
22+
}
23+
}
24+
#endif
32.3 KB
Loading

0 commit comments

Comments
 (0)