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

[Android] Fixed the CarouselView Items overlap issue with PeekAreaInsets #27499

Merged
merged 7 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from 6 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 @@ -603,8 +603,15 @@ protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
var viewHolder = (ViewHolder)ItemsViewAdapter.CreateViewHolder(this, viewType);
ItemsViewAdapter.BindViewHolder(viewHolder, 0);
viewHolder.ItemView.Measure(widthMeasureSpec, heightMeasureSpec);
widthMeasureSpec = MeasureSpecMode.Exactly.MakeMeasureSpec(viewHolder.ItemView.MeasuredWidth);
heightMeasureSpec = MeasureSpecMode.Exactly.MakeMeasureSpec(viewHolder.ItemView.MeasuredHeight);

if (widthMeasureSpec == 0)
PureWeen marked this conversation as resolved.
Show resolved Hide resolved
{
widthMeasureSpec = MeasureSpecMode.Exactly.MakeMeasureSpec(viewHolder.ItemView.MeasuredWidth);
}
if (heightMeasureSpec == 0)
{
heightMeasureSpec = MeasureSpecMode.Exactly.MakeMeasureSpec(viewHolder.ItemView.MeasuredHeight);
}
}
}
base.OnMeasure(widthMeasureSpec, heightMeasureSpec);
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue27418.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?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.Issue27418">

<VerticalStackLayout>
<CarouselView AutomationId="CarouselView"
PeekAreaInsets="50"
Loop="false"
ItemsSource="{Binding CarouselItems}"
HorizontalScrollBarVisibility="Never">
<CarouselView.ItemTemplate>
<DataTemplate>
<VerticalStackLayout
Spacing="25">
<Label Text="{Binding LabelText}"
FontSize="Large"/>
<Image HeightRequest="200"
WidthRequest="200"
Source="dotnet_bot.png"/>
<Button
Text="{Binding ButtonText}"
FontSize="Large"
HorizontalOptions="Fill"/>
</VerticalStackLayout>
</DataTemplate>
</CarouselView.ItemTemplate>
</CarouselView>
</VerticalStackLayout>

</ContentPage>
38 changes: 38 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue27418.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System.Collections.ObjectModel;

namespace Maui.Controls.Sample.Issues
{
[Issue(IssueTracker.Github, 27418, "CarouselView Rendering Issue with PeekAreaInsets on Android Starting from .NET MAUI 9.0.21", PlatformAffected.Android)]
public partial class Issue27418 : ContentPage
{
public Issue27418()
{
InitializeComponent();
BindingContext = new Issue27418ViewModel();
}
}

public class Issue27418Model
{
public string LabelText { get; set; }
public string ButtonText { get; set; }
}

public class Issue27418ViewModel
{
public ObservableCollection<Issue27418Model> CarouselItems { get; set; }

public Issue27418ViewModel()
{
CarouselItems = new ObservableCollection<Issue27418Model>
{
new Issue27418Model { LabelText = "Page1",ButtonText = "Button1" },
new Issue27418Model { LabelText = "Page2",ButtonText = "Button2" },
new Issue27418Model { LabelText = "Page3",ButtonText = "Button3" },
new Issue27418Model { LabelText = "Page4",ButtonText = "Button4" },
new Issue27418Model { LabelText = "Page5",ButtonText = "Button5" },
new Issue27418Model { LabelText = "Page6",ButtonText = "Button6" },
};
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#if TEST_FAILS_ON_CATALYST
// When maximizing the window to verify the screenshot on Mac, resizing did not occur properly on cv1. Therefore, I have restricted Catalyst for now.
PureWeen marked this conversation as resolved.
Show resolved Hide resolved
// for more information , see https://github.com/dotnet/maui/issues/26969
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues
{
public class Issue27418 : _IssuesUITest
{
public Issue27418(TestDevice device) : base(device) { }

public override string Issue => "CarouselView Rendering Issue with PeekAreaInsets on Android Starting from .NET MAUI 9.0.21";

[Test]
[Category(UITestCategories.CarouselView)]
public void CarouselItemsShouldRenderProperly()
{
App.WaitForElement("CarouselView");
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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading