Skip to content

Commit af204c6

Browse files
authored
[iOS] Flyout Menu CollectionView First Item Misaligned - fix (#30501)
<!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Description of Change The regression is caused by this PR: #28670, but I think that the changes introduced by @albyrock87 let us simplify the code and easily fix the regression ### Issues Fixed Fixes #30483 |Before|After| |--|--| |<video src="https://github.com/user-attachments/assets/fdc507b6-a156-4175-944d-efdf8d22340e" width="300px"></video>|<video src="https://github.com/user-attachments/assets/a8dcddae-65b7-4047-82f7-c876907720e4" width="300px"></video>|
2 parents aeea1ff + 572e1c7 commit af204c6

9 files changed

Lines changed: 99 additions & 46 deletions

File tree

src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellFlyoutLayoutManager.cs

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -199,43 +199,10 @@ internal void UpdateHeaderSize()
199199
HeaderView.SizeThatFits(new CGSize(ContentView.Superview.Frame.Width, double.PositiveInfinity));
200200
}
201201

202-
SetHeaderContentInset();
203202
UpdateHeaderMaximumSize(ScrollView?.ContentOffset.Y);
204203
LayoutParallax();
205204
}
206205

207-
208-
internal void SetHeaderContentInset()
209-
{
210-
if (ScrollView is null)
211-
return;
212-
213-
var offset = ScrollView.ContentInset.Top;
214-
215-
if (HeaderView is not null)
216-
{
217-
if (double.IsNaN(MeasuredHeaderViewHeightWithNoMargin))
218-
{
219-
return;
220-
}
221-
222-
// We take the measured header height without margin, since the margin is already accounted for in the positioning of the scroll view itself.
223-
ScrollView.ContentInset = new UIEdgeInsets((nfloat)Math.Max(HeaderMinimumHeight, MeasuredHeaderViewHeightWithNoMargin), 0, 0, 0);
224-
}
225-
else
226-
{
227-
ScrollView.ContentInset = new UIEdgeInsets(UIApplication.SharedApplication.GetSafeAreaInsetsForWindow().Top, 0, 0, 0);
228-
}
229-
230-
offset -= ScrollView.ContentInset.Top;
231-
232-
var yContentOffset = ScrollView.ContentOffset.Y;
233-
ScrollView.ContentOffset =
234-
new CGPoint(ScrollView.ContentOffset.X, yContentOffset + offset);
235-
236-
UpdateVerticalScrollMode();
237-
}
238-
239206
public void UpdateVerticalScrollMode()
240207
{
241208
if (ScrollView is null)
@@ -319,17 +286,7 @@ void LayoutContent(CGRect parentBounds, nfloat footerHeight)
319286

320287
if (HeaderView is not null)
321288
{
322-
if (ScrollView is null)
323-
{
324-
// 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.
325-
contentYOffset += HeaderView.Frame.Height;
326-
}
327-
else
328-
{
329-
// For ScrollView, we need to consider the margin, but we should not consider the header height, since it should overlap with the scroll view.
330-
// The content inset is already managed by SetHeaderContentInset.
331-
contentYOffset += HeaderView.View.Margin.VerticalThickness;
332-
}
289+
contentYOffset += HeaderView.Frame.Height;
333290
}
334291

335292
var contentFrame = new Rect(parentBounds.X, contentYOffset, parentBounds.Width, parentBounds.Height - contentYOffset - footerHeight);
@@ -356,7 +313,6 @@ void OnShellPropertyChanged(object sender, PropertyChangedEventArgs e)
356313
{
357314
if (e.Is(Shell.FlyoutHeaderBehaviorProperty))
358315
{
359-
SetHeaderContentInset();
360316
LayoutParallax();
361317
}
362318
else if (e.Is(Shell.FlyoutVerticalScrollModeProperty))

src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellTableViewController.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ public override void ViewDidLoad()
9494
[System.Runtime.Versioning.SupportedOSPlatform("tvos11.0")]
9595
public override void ViewSafeAreaInsetsDidChange()
9696
{
97-
ShellFlyoutContentManager.SetHeaderContentInset();
9897
base.ViewSafeAreaInsetsDidChange();
9998
}
10099

265 KB
Loading
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<Shell 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.Issue30483">
5+
<Shell.FlyoutHeader>
6+
<Grid Padding="10">
7+
<Image Background="Red"
8+
Aspect="AspectFit"
9+
Source="dotnet_bot.png">
10+
</Image>
11+
</Grid>
12+
</Shell.FlyoutHeader>
13+
14+
<Shell.FlyoutContent>
15+
<CollectionView x:Name="CollectionView"
16+
AutomationId="CollectionView"
17+
Margin="10"
18+
BackgroundColor="Green">
19+
<CollectionView.ItemTemplate>
20+
<DataTemplate>
21+
<HorizontalStackLayout Padding="10">
22+
<Label Text="{Binding .}"
23+
FontSize="20"
24+
HorizontalOptions="Center"/>
25+
<Image Source="dotnet_bot.png"
26+
Aspect="AspectFit"
27+
HorizontalOptions="Center"
28+
VerticalOptions="CenterAndExpand"/>
29+
</HorizontalStackLayout>
30+
</DataTemplate>
31+
</CollectionView.ItemTemplate>
32+
<CollectionView.ItemsSource>
33+
<x:Array Type="{x:Type x:String}">
34+
<x:String>Item 1</x:String>
35+
<x:String>Item 2</x:String>
36+
<x:String>Item 3</x:String>
37+
<x:String>Item 4</x:String>
38+
<x:String>Item 5</x:String>
39+
<x:String>Item 6</x:String>
40+
<x:String>Item 7</x:String>
41+
</x:Array>
42+
</CollectionView.ItemsSource>
43+
</CollectionView>
44+
</Shell.FlyoutContent>
45+
46+
<Shell.FlyoutFooter>
47+
<Button Margin="10"
48+
Text="User Settings"
49+
Background="CornflowerBlue"
50+
HorizontalOptions="Fill"
51+
VerticalOptions="Fill"/>
52+
</Shell.FlyoutFooter>
53+
54+
<FlyoutItem Route="MainPage"
55+
Title="Main Page"
56+
Icon="dotnet_bot.png">
57+
<ShellContent>
58+
<ContentPage Title="Main Page">
59+
<Label Text="Welcome to the Main Page!"
60+
HorizontalOptions="Center"
61+
VerticalOptions="Center"/>
62+
</ContentPage>
63+
</ShellContent>
64+
</FlyoutItem>
65+
</Shell>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace Maui.Controls.Sample.Issues
2+
{
3+
[Issue(IssueTracker.Github, 30483, "Flyout Menu CollectionView First Item Misaligned", PlatformAffected.iOS)]
4+
public partial class Issue30483 : Shell
5+
{
6+
public Issue30483()
7+
{
8+
InitializeComponent();
9+
FlyoutIsPresented = true;
10+
}
11+
}
12+
}
80 KB
Loading
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using NUnit.Framework;
2+
using UITest.Appium;
3+
using UITest.Core;
4+
5+
namespace Microsoft.Maui.TestCases.Tests.Issues;
6+
7+
public class Issue30483 : _IssuesUITest
8+
{
9+
public Issue30483(TestDevice device) : base(device) { }
10+
11+
public override string Issue => "Flyout Menu CollectionView First Item Misaligned";
12+
13+
[Test]
14+
[Category(UITestCategories.CollectionView)]
15+
public void FlyoutMenuCollectionViewFirstItemMisaligned()
16+
{
17+
App.WaitForElement("CollectionView");
18+
App.ScrollDown("CollectionView");
19+
VerifyScreenshot();
20+
}
21+
}
99.8 KB
Loading
255 KB
Loading

0 commit comments

Comments
 (0)