Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[iOS] Fixes carouselview layout on iOS #20001

Merged
merged 8 commits into from
Feb 9, 2024
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
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Maui.Controls.Sample.Issues.Issue19657"
xmlns:ns="clr-namespace:Maui.Controls.Sample.Issues">
<ScrollView>
<Grid x:Name="contentGrid">
<Grid.RowDefinitions>
<RowDefinition Height="20" />
<RowDefinition Height="220" />
</Grid.RowDefinitions>
<Grid.Resources>
<DataTemplate x:Key="SampleItemTemplate">
<VerticalStackLayout Spacing="4">
<Label Text="{Binding Title, Mode=OneWay}" FontAttributes="Bold" />
<Label Text="{Binding Description, Mode=OneWay}" />
</VerticalStackLayout>
</DataTemplate>
</Grid.Resources>

<Label HorizontalOptions="Center" x:Name="WaitHere" Text="Check if the Carousel items all show up" AutomationId="WaitHere" Background="Red"/>

<CarouselView x:Name="carousel"
ItemTemplate="{StaticResource SampleItemTemplate}"
Loop="False"
HeightRequest="220"
Grid.Row="1"
BackgroundColor="LightBlue" />
</Grid>
</ScrollView>
</ContentPage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using System.ComponentModel;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.Xaml;
using Microsoft.Maui.Graphics;
using System.Collections.Generic;

namespace Maui.Controls.Sample.Issues
{
[XamlCompilation(XamlCompilationOptions.Compile)]
[Issue(IssueTracker.Github, 19657, "CarouselView Content disappears when 'Loop' is false and inside ScrollView", PlatformAffected.iOS)]
public partial class Issue19657 : ContentPage
{

public Issue19657()
{
InitializeComponent();
var exampleItems = new List<SampleCarouselItem1>
{
new SampleCarouselItem1( "First", "First CarouselView item" ),
new SampleCarouselItem1( "Second", "Second CarouselView item" ),
new SampleCarouselItem1( "Third", "Third CarouselView item" ),
new SampleCarouselItem1( "Fourth", "Fourth CarouselView item" ),
new SampleCarouselItem1( "Fifth", "Fifth CarouselView item" ),
};

carousel.ItemsSource = exampleItems;
}

class SampleCarouselItem1
{
public SampleCarouselItem1(string title, string description )
{
Title = title;
Description = description;
}

public string Title { get; set; }
public string Description { get; set; }
public Color Color { get; set; }
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#nullable disable
using System;
using Microsoft.Maui.Graphics;

namespace Microsoft.Maui.Controls.Handlers.Items
{
Expand Down Expand Up @@ -64,5 +65,8 @@ public static void MapLoop(CarouselViewHandler handler, CarouselView carouselVie
{
(handler.Controller as CarouselViewController)?.UpdateLoop();
}

public override Size GetDesiredSize(double widthConstraint, double heightConstraint) =>
this.GetDesiredSizeFromHandler(widthConstraint, heightConstraint);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ Microsoft.Maui.Controls.IValueConverter.ConvertBack(object? value, System.Type!
*REMOVED*override Microsoft.Maui.Controls.Handlers.Compatibility.PhoneFlyoutPageRenderer.WillRotate(UIKit.UIInterfaceOrientation toInterfaceOrientation, double duration) -> void
~virtual Microsoft.Maui.Controls.Handlers.Items.ItemsViewController<TItemsView>.DetermineCellReuseId(Foundation.NSIndexPath indexPath) -> string
override Microsoft.Maui.Controls.Handlers.Items.ItemsViewHandler<TItemsView>.GetDesiredSize(double widthConstraint, double heightConstraint) -> Microsoft.Maui.Graphics.Size
override Microsoft.Maui.Controls.Handlers.Items.CarouselViewHandler.GetDesiredSize(double widthConstraint, double heightConstraint) -> Microsoft.Maui.Graphics.Size
~Microsoft.Maui.Controls.Element.AddLogicalChild(Microsoft.Maui.Controls.Element element) -> void
~Microsoft.Maui.Controls.Element.InsertLogicalChild(int index, Microsoft.Maui.Controls.Element element) -> void
~Microsoft.Maui.Controls.Element.RemoveLogicalChild(Microsoft.Maui.Controls.Element element) -> bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ Microsoft.Maui.Controls.IValueConverter.ConvertBack(object? value, System.Type!
*REMOVED*override Microsoft.Maui.Controls.Handlers.Compatibility.PhoneFlyoutPageRenderer.WillRotate(UIKit.UIInterfaceOrientation toInterfaceOrientation, double duration) -> void
~virtual Microsoft.Maui.Controls.Handlers.Items.ItemsViewController<TItemsView>.DetermineCellReuseId(Foundation.NSIndexPath indexPath) -> string
override Microsoft.Maui.Controls.Handlers.Items.ItemsViewHandler<TItemsView>.GetDesiredSize(double widthConstraint, double heightConstraint) -> Microsoft.Maui.Graphics.Size
override Microsoft.Maui.Controls.Handlers.Items.CarouselViewHandler.GetDesiredSize(double widthConstraint, double heightConstraint) -> Microsoft.Maui.Graphics.Size
~Microsoft.Maui.Controls.Element.AddLogicalChild(Microsoft.Maui.Controls.Element element) -> void
~Microsoft.Maui.Controls.Element.InsertLogicalChild(int index, Microsoft.Maui.Controls.Element element) -> void
~Microsoft.Maui.Controls.Element.RemoveLogicalChild(Microsoft.Maui.Controls.Element element) -> bool
Expand Down
27 changes: 27 additions & 0 deletions src/Controls/tests/UITests/Tests/Issues/Issue19657.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.Drawing;
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.AppiumTests.Issues
{
public class Issue19657 : _IssuesUITest
{
public Issue19657(TestDevice device) : base(device) { }

public override string Issue => "CarouselView Content disappears when 'Loop' is false and inside ScrollView";

[Test]
public void CarouselItemLoadsInCorrectPosition()
{
_ = App.WaitForElement("WaitHere");

var element = App.WaitForElement("First");

this.IgnoreIfPlatforms(new TestDevice[] { TestDevice.Android, TestDevice.Mac, TestDevice.Windows },
"The bug only happens on iOS; see https://github.com/dotnet/maui/issues/19657");

VerifyScreenshot();
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading