Skip to content

Commit cdaf1f1

Browse files
kubafloPureWeen
authored andcommitted
[iOS] Changing carousel view orientation with disabled loop - fix (#28545)
* [iOS] Changing carousel view orientation with disabled loop - fix * Added snapshots
1 parent 9e60136 commit cdaf1f1

File tree

8 files changed

+80
-0
lines changed

8 files changed

+80
-0
lines changed

src/Controls/src/Core/Handlers/Items/iOS/CarouselViewController.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,20 @@ public class CarouselViewController : ItemsViewController<CarouselView>
3232

3333
bool _isRotating;
3434

35+
public override void TraitCollectionDidChange(UITraitCollection previousTraitCollection)
36+
{
37+
if (previousTraitCollection.VerticalSizeClass == TraitCollection.VerticalSizeClass)
38+
{
39+
return;
40+
}
41+
42+
if (ItemsView?.Loop == false || _carouselViewLoopManager is null)
43+
{
44+
CollectionView.ReloadData();
45+
InitialPositionSet = false;
46+
}
47+
}
48+
3549
public CarouselViewController(CarouselView itemsView, ItemsViewLayout layout) : base(itemsView, layout)
3650
{
3751
CollectionView.AllowsSelection = false;

src/Controls/src/Core/PublicAPI/net-ios/PublicAPI.Unshipped.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ Microsoft.Maui.Controls.HybridWebView.SetInvokeJavaScriptTarget<T>(T! target) ->
7171
~Microsoft.Maui.Controls.Xaml.IXamlTypeResolver.Resolve(string qualifiedTypeName, System.IServiceProvider serviceProvider = null, bool expandToExtension = true) -> System.Type
7272
~Microsoft.Maui.Controls.Xaml.RequireServiceAttribute.RequireServiceAttribute(System.Type[] serviceTypes) -> void
7373
~Microsoft.Maui.Controls.Xaml.RequireServiceAttribute.ServiceTypes.get -> System.Type[]
74+
~override Microsoft.Maui.Controls.Handlers.Items.CarouselViewController.TraitCollectionDidChange(UIKit.UITraitCollection previousTraitCollection) -> void
7475
~override Microsoft.Maui.Controls.Handlers.Items2.CarouselViewController2.CreateDelegator() -> UIKit.UICollectionViewDelegateFlowLayout
7576
~override Microsoft.Maui.Controls.Handlers.Items2.CarouselViewController2.CreateItemsViewSource() -> Microsoft.Maui.Controls.Handlers.Items.IItemsViewSource
7677
~override Microsoft.Maui.Controls.Handlers.Items2.CarouselViewController2.DetermineCellReuseId(Foundation.NSIndexPath indexPath) -> string

src/Controls/src/Core/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ Microsoft.Maui.Controls.HybridWebView.SetInvokeJavaScriptTarget<T>(T! target) ->
7171
~Microsoft.Maui.Controls.Xaml.IXamlTypeResolver.Resolve(string qualifiedTypeName, System.IServiceProvider serviceProvider = null, bool expandToExtension = true) -> System.Type
7272
~Microsoft.Maui.Controls.WebViewProcessTerminatedEventArgs.PlatformArgs.get -> Microsoft.Maui.Controls.PlatformWebViewProcessTerminatedEventArgs
7373
~Microsoft.Maui.Controls.Xaml.RequireServiceAttribute.RequireServiceAttribute(System.Type[] serviceTypes) -> void
74+
~override Microsoft.Maui.Controls.Handlers.Items.CarouselViewController.TraitCollectionDidChange(UIKit.UITraitCollection previousTraitCollection) -> void
7475
~Microsoft.Maui.Controls.Xaml.RequireServiceAttribute.ServiceTypes.get -> System.Type[]
7576
~override Microsoft.Maui.Controls.Handlers.Items2.CarouselViewController2.CreateDelegator() -> UIKit.UICollectionViewDelegateFlowLayout
7677
~override Microsoft.Maui.Controls.Handlers.Items2.CarouselViewController2.CreateItemsViewSource() -> Microsoft.Maui.Controls.Handlers.Items.IItemsViewSource
15.1 KB
Loading
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
x:Class="Maui.Controls.Sample.Issues.Issue28523">
5+
<CarouselView Loop="False">
6+
<CarouselView.ItemTemplate>
7+
<DataTemplate>
8+
<Border StrokeShape="RoundRectangle 20"
9+
BackgroundColor="Red">
10+
<Label HorizontalOptions="Center"
11+
VerticalOptions="Center"
12+
AutomationId="{Binding}"
13+
Text="{Binding}"/>
14+
</Border>
15+
</DataTemplate>
16+
</CarouselView.ItemTemplate>
17+
<CarouselView.ItemsSource>
18+
<x:Array Type="{x:Type x:String}">
19+
<x:String>Baboon</x:String>
20+
<x:String>Capuchin Monkey</x:String>
21+
<x:String>Blue Monkey</x:String>
22+
<x:String>Squirrel Monkey</x:String>
23+
<x:String>Golden Lion Tamarin</x:String>
24+
<x:String>Howler Monkey</x:String>
25+
</x:Array>
26+
</CarouselView.ItemsSource>
27+
</CarouselView>
28+
</ContentPage>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace Maui.Controls.Sample.Issues
2+
{
3+
[Issue(IssueTracker.Github, 28523, "Different behavior on iOS and Android when Loop = False", PlatformAffected.iOS)]
4+
public partial class Issue28523 : ContentPage
5+
{
6+
public Issue28523()
7+
{
8+
InitializeComponent();
9+
}
10+
}
11+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#if ANDROID || IOS
2+
using NUnit.Framework;
3+
using UITest.Appium;
4+
using UITest.Core;
5+
6+
namespace Microsoft.Maui.TestCases.Tests.Issues;
7+
public class Issue28523 : _IssuesUITest
8+
{
9+
public Issue28523(TestDevice testDevice) : base(testDevice)
10+
{
11+
}
12+
13+
public override string Issue => "Different behavior on iOS and Android when Loop = False";
14+
15+
[Test]
16+
[Category(UITestCategories.CarouselView)]
17+
public void CarouselViewItemShouldScaleProperly()
18+
{
19+
App.WaitForElement("Baboon");
20+
App.SetOrientationLandscape();
21+
App.WaitForElement("Baboon");
22+
VerifyScreenshot();
23+
}
24+
}
25+
#endif
15.2 KB
Loading

0 commit comments

Comments
 (0)