diff --git a/src/Controls/src/Core/Handlers/Items/CarouselViewHandler.Android.cs b/src/Controls/src/Core/Handlers/Items/CarouselViewHandler.Android.cs index abe5e4b40480..6fa39583b485 100644 --- a/src/Controls/src/Core/Handlers/Items/CarouselViewHandler.Android.cs +++ b/src/Controls/src/Core/Handlers/Items/CarouselViewHandler.Android.cs @@ -95,7 +95,7 @@ double GetItemWidth() if (double.IsInfinity(width)) return width; - itemWidth = (int)(width - Context?.ToPixels(VirtualView.PeekAreaInsets.Left) - Context?.ToPixels(VirtualView.PeekAreaInsets.Right) - Context?.ToPixels(listItemsLayout.ItemSpacing)); + itemWidth = (int)(width - Context?.ToPixels(VirtualView.PeekAreaInsets.Left) - Context?.ToPixels(VirtualView.PeekAreaInsets.Right)); } return itemWidth; @@ -112,7 +112,7 @@ double GetItemHeight() if (double.IsInfinity(height)) return height; - itemHeight = (int)(height - Context?.ToPixels(VirtualView.PeekAreaInsets.Top) - Context?.ToPixels(VirtualView.PeekAreaInsets.Bottom) - Context?.ToPixels(listItemsLayout.ItemSpacing)); + itemHeight = (int)(height - Context?.ToPixels(VirtualView.PeekAreaInsets.Top) - Context?.ToPixels(VirtualView.PeekAreaInsets.Bottom)); } return itemHeight; diff --git a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/CarouselViewShouldRenderCorrectly.png b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/CarouselViewShouldRenderCorrectly.png index bf3e23f5eedd..38d36f30bb96 100644 Binary files a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/CarouselViewShouldRenderCorrectly.png and b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/CarouselViewShouldRenderCorrectly.png differ diff --git a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/VerifySpacingAffectsItemSize.png b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/VerifySpacingAffectsItemSize.png new file mode 100644 index 000000000000..3939d43e4e45 Binary files /dev/null and b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/VerifySpacingAffectsItemSize.png differ diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue29609.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue29609.cs new file mode 100644 index 000000000000..7e4fade76612 --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue29609.cs @@ -0,0 +1,72 @@ +using System.Collections.ObjectModel; + +namespace Maui.Controls.Sample.Issues; + +[Issue(IssueTracker.Github, 29609, "ItemSpacing on CarouselView resizes items", PlatformAffected.Android)] +public class Issue29609 : ContentPage +{ + Issue29609_ViewModel ViewModel; + public Issue29609() + { + ViewModel = new Issue29609_ViewModel(); + BindingContext = ViewModel; + var stack = new StackLayout + { + VerticalOptions = LayoutOptions.Center, + HorizontalOptions = LayoutOptions.Center + }; + var label = new Label + { + Text = "ItemSpacing on CarouselView resizes items", + AutomationId = "29609DescriptionLabel" + }; + var carouselView = new CarouselView + { + BackgroundColor = Colors.Red, + AutomationId = "29609CarouselView", + HeightRequest = 400, + WidthRequest = 300, + ItemsSource = ViewModel.Items, + Loop = false, + ItemsLayout = new LinearItemsLayout(ItemsLayoutOrientation.Horizontal) + { + ItemSpacing = 50, + SnapPointsAlignment = SnapPointsAlignment.Center, + SnapPointsType = SnapPointsType.MandatorySingle + }, + ItemTemplate = new DataTemplate(() => + { + var grid = new Grid + { + BackgroundColor = Colors.Yellow + }; + + var label = new Label + { + HorizontalOptions = LayoutOptions.Center, + VerticalOptions = LayoutOptions.Center + }; + label.SetBinding(Label.TextProperty, "."); + + grid.Children.Add(label); + return grid; + }) + }; + stack.Children.Add(label); + stack.Children.Add(carouselView); + Content = stack; + } +} + +public class Issue29609_ViewModel +{ + public ObservableCollection Items = new(); + + public Issue29609_ViewModel() + { + for (var i = 0; i < 5; i++) + { + Items.Add($"Item {i}"); + } + } +} \ No newline at end of file diff --git a/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/VerifySpacingAffectsItemSize.png b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/VerifySpacingAffectsItemSize.png new file mode 100644 index 000000000000..582ec068f328 Binary files /dev/null and b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/VerifySpacingAffectsItemSize.png differ diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue29609.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue29609.cs new file mode 100644 index 000000000000..8b5d75f10f29 --- /dev/null +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue29609.cs @@ -0,0 +1,24 @@ +# if TEST_FAILS_ON_WINDOWS // ItemSpacing on CarouselView is not applied on Windows https://github.com/dotnet/maui/issues/29772 +using NUnit.Framework; +using UITest.Appium; +using UITest.Core; + +namespace Microsoft.Maui.TestCases.Tests.Issues; + +public class Issue29609 : _IssuesUITest +{ + public Issue29609(TestDevice testDevice) : base(testDevice) + { + } + + public override string Issue => "ItemSpacing on CarouselView resizes items"; + + [Test] + [Category(UITestCategories.CarouselView)] + public void VerifySpacingAffectsItemSize() + { + App.WaitForElement("29609DescriptionLabel"); + VerifyScreenshot(); + } +} +#endif \ No newline at end of file diff --git a/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/VerifySpacingAffectsItemSize.png b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/VerifySpacingAffectsItemSize.png new file mode 100644 index 000000000000..53557ac910b6 Binary files /dev/null and b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/VerifySpacingAffectsItemSize.png differ