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
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ public static void MapCurrentItem(CarouselViewHandler handler, CarouselView caro
(handler.PlatformView as IMauiCarouselRecyclerView).UpdateFromCurrentItem();
}

// TODO: Change the modifier to public in .NET 10.
internal static void MapItemsLayout(CarouselViewHandler handler, CarouselView carouselView)
{
if (handler.PlatformView is IMauiRecyclerView<CarouselView> recyclerView)
{
recyclerView.UpdateLayoutManager();
}
}

public override Size GetDesiredSize(double widthConstraint, double heightConstraint)
{
_widthConstraint = widthConstraint;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public CarouselViewHandler(PropertyMapper mapper = null) : base(mapper ?? Mapper

public static PropertyMapper<CarouselView, CarouselViewHandler> Mapper = new(ItemsViewMapper)
{
#if TIZEN
#if TIZEN || ANDROID
[Controls.CarouselView.ItemsLayoutProperty.PropertyName] = MapItemsLayout,
#endif
[Controls.CarouselView.IsSwipeEnabledProperty.PropertyName] = MapIsSwipeEnabled,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public CarouselViewHandler2(PropertyMapper mapper = null) : base(mapper ?? Mappe
[Controls.CarouselView.PeekAreaInsetsProperty.PropertyName] = MapPeekAreaInsets,
[Controls.CarouselView.IsBounceEnabledProperty.PropertyName] = MapIsBounceEnabled,
[Controls.CarouselView.PositionProperty.PropertyName] = MapPosition,
[Controls.CarouselView.CurrentItemProperty.PropertyName] = MapCurrentItem
[Controls.CarouselView.CurrentItemProperty.PropertyName] = MapCurrentItem,
[Controls.CarouselView.ItemsLayoutProperty.PropertyName] = MapItemsLayout,
};
}

Expand Down Expand Up @@ -190,6 +191,12 @@ public static void MapIsBounceEnabled(CarouselViewHandler2 handler, CarouselView
handler.Controller.CollectionView.Bounces = carouselView.IsBounceEnabled;
}

// TODO: Change the modifier to public in .NET 10.
internal static void MapItemsLayout(CarouselViewHandler2 handler, CarouselView carouselView)
{
handler?.UpdateLayout();
}

public static void MapPeekAreaInsets(CarouselViewHandler2 handler, CarouselView carouselView)
{
handler.UpdateLayout();
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
73 changes: 73 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue29372.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using System.Collections.ObjectModel;

namespace Maui.Controls.Sample.Issues;
[Issue(IssueTracker.Github, 29372, "CarouselView ItemsLayout Not Updating at Runtime", PlatformAffected.All)]
public partial class Issue29372 : ContentPage
{
public Issue29372()
{
var verticalStackLayout = new VerticalStackLayout();
var carouselItems = new ObservableCollection<string>
{
"Item 0",
"Item 1",
"Item 2",
"Item 3",
"Item 4",
};

CarouselView2 carouselView = new CarouselView2
{
ItemsSource = carouselItems,
AutomationId = "carouselview",
ItemsLayout = new LinearItemsLayout(ItemsLayoutOrientation.Horizontal),
PeekAreaInsets = new Thickness(0, 100),
HeightRequest = 300,
Loop = false,
ItemTemplate = new DataTemplate(() =>
{
var grid = new Grid
{
Padding = 10
};

var label = new Label
{
VerticalOptions = LayoutOptions.Center,
HorizontalOptions = LayoutOptions.Center,
FontSize = 18,
};
label.SetBinding(Label.TextProperty, ".");
label.SetBinding(Label.AutomationIdProperty, ".");

grid.Children.Add(label);
return grid;
}),
HorizontalOptions = LayoutOptions.Fill,
};

var button = new Button
{
Text = "Change Items Layout",
AutomationId = "ChangeItemsLayoutButton",
Margin = new Thickness(20),
};

var label = new Label
{
Text = "The test is passed if the items are displayed in a vertical orientation.",
HorizontalOptions = LayoutOptions.Center,
Padding = new Thickness(20),
};

button.Clicked += (sender, e) =>
{
carouselView.ItemsLayout = new LinearItemsLayout(ItemsLayoutOrientation.Vertical);
};

verticalStackLayout.Children.Add(label);
verticalStackLayout.Children.Add(carouselView);
verticalStackLayout.Children.Add(button);
Content = verticalStackLayout;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#if TEST_FAILS_ON_WINDOWS // Related issue for windows: https://github.com/dotnet/maui/issues/29445
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;
public class Issue29372 : _IssuesUITest
{
public override string Issue => "CarouselView ItemsLayout Not Updating at Runtime";

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

[Test]
[Category(UITestCategories.CarouselView)]
public void VerifyCarouselLayoutOrientationChange()
{
App.WaitForElement("carouselview");
App.Tap("ChangeItemsLayoutButton");
VerifyScreenshot();
}
}
#endif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading