Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -199,43 +199,10 @@ internal void UpdateHeaderSize()
HeaderView.SizeThatFits(new CGSize(ContentView.Superview.Frame.Width, double.PositiveInfinity));
}

SetHeaderContentInset();
UpdateHeaderMaximumSize(ScrollView?.ContentOffset.Y);
LayoutParallax();
}


internal void SetHeaderContentInset()
{
if (ScrollView is null)
return;

var offset = ScrollView.ContentInset.Top;

if (HeaderView is not null)
{
if (double.IsNaN(MeasuredHeaderViewHeightWithNoMargin))
{
return;
}

// We take the measured header height without margin, since the margin is already accounted for in the positioning of the scroll view itself.
ScrollView.ContentInset = new UIEdgeInsets((nfloat)Math.Max(HeaderMinimumHeight, MeasuredHeaderViewHeightWithNoMargin), 0, 0, 0);
}
else
{
ScrollView.ContentInset = new UIEdgeInsets(UIApplication.SharedApplication.GetSafeAreaInsetsForWindow().Top, 0, 0, 0);
}

offset -= ScrollView.ContentInset.Top;

var yContentOffset = ScrollView.ContentOffset.Y;
ScrollView.ContentOffset =
new CGPoint(ScrollView.ContentOffset.X, yContentOffset + offset);

UpdateVerticalScrollMode();
}

public void UpdateVerticalScrollMode()
{
if (ScrollView is null)
Expand Down Expand Up @@ -319,17 +286,7 @@ void LayoutContent(CGRect parentBounds, nfloat footerHeight)

if (HeaderView is not null)
{
if (ScrollView is null)
{
// The margin is already managed by MAUI's layout system, so we don't need to add it here and we just offset the content by the header's height.
contentYOffset += HeaderView.Frame.Height;
}
else
{
// For ScrollView, we need to consider the margin, but we should not consider the header height, since it should overlap with the scroll view.
// The content inset is already managed by SetHeaderContentInset.
contentYOffset += HeaderView.View.Margin.VerticalThickness;
}
contentYOffset += HeaderView.Frame.Height;
}

var contentFrame = new Rect(parentBounds.X, contentYOffset, parentBounds.Width, parentBounds.Height - contentYOffset - footerHeight);
Expand All @@ -356,7 +313,6 @@ void OnShellPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.Is(Shell.FlyoutHeaderBehaviorProperty))
{
SetHeaderContentInset();
LayoutParallax();
}
else if (e.Is(Shell.FlyoutVerticalScrollModeProperty))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ public override void ViewDidLoad()
[System.Runtime.Versioning.SupportedOSPlatform("tvos11.0")]
public override void ViewSafeAreaInsetsDidChange()
{
ShellFlyoutContentManager.SetHeaderContentInset();
base.ViewSafeAreaInsetsDidChange();
}

Expand Down
65 changes: 65 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue30483.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="utf-8" ?>
<Shell xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Maui.Controls.Sample.Issues.Issue30483">
<Shell.FlyoutHeader>
<Grid Padding="10">
<Image Background="Red"
Aspect="AspectFit"
Source="dotnet_bot.png">
</Image>
</Grid>
</Shell.FlyoutHeader>

<Shell.FlyoutContent>
<CollectionView x:Name="CollectionView"
AutomationId="CollectionView"
Margin="10"
BackgroundColor="Green">
<CollectionView.ItemTemplate>
<DataTemplate>
<HorizontalStackLayout Padding="10">
<Label Text="{Binding .}"
FontSize="20"
HorizontalOptions="Center"/>
<Image Source="dotnet_bot.png"
Aspect="AspectFit"
HorizontalOptions="Center"
VerticalOptions="CenterAndExpand"/>
</HorizontalStackLayout>
</DataTemplate>
</CollectionView.ItemTemplate>
<CollectionView.ItemsSource>
<x:Array Type="{x:Type x:String}">
<x:String>Item 1</x:String>
<x:String>Item 2</x:String>
<x:String>Item 3</x:String>
<x:String>Item 4</x:String>
<x:String>Item 5</x:String>
<x:String>Item 6</x:String>
<x:String>Item 7</x:String>
</x:Array>
</CollectionView.ItemsSource>
</CollectionView>
</Shell.FlyoutContent>

<Shell.FlyoutFooter>
<Button Margin="10"
Text="User Settings"
Background="CornflowerBlue"
HorizontalOptions="Fill"
VerticalOptions="Fill"/>
</Shell.FlyoutFooter>

<FlyoutItem Route="MainPage"
Title="Main Page"
Icon="dotnet_bot.png">
<ShellContent>
<ContentPage Title="Main Page">
<Label Text="Welcome to the Main Page!"
HorizontalOptions="Center"
VerticalOptions="Center"/>
</ContentPage>
</ShellContent>
</FlyoutItem>
</Shell>
12 changes: 12 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue30483.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Maui.Controls.Sample.Issues
{
[Issue(IssueTracker.Github, 30483, "Flyout Menu CollectionView First Item Misaligned", PlatformAffected.iOS)]
public partial class Issue30483 : Shell
{
public Issue30483()
{
InitializeComponent();
FlyoutIsPresented = true;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;

public class Issue30483 : _IssuesUITest
{
public Issue30483(TestDevice device) : base(device) { }

public override string Issue => "Flyout Menu CollectionView First Item Misaligned";

[Test]
[Category(UITestCategories.CollectionView)]
public void FlyoutMenuCollectionViewFirstItemMisaligned()
{
App.WaitForElement("CollectionView");
App.ScrollDown("CollectionView");
VerifyScreenshot();
}
}
Loading