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

Ignore ScrollRectToVisible if KeyboardAutoManagerScroll is enabled in ItemsViewController #19875

@@ -0,0 +1,41 @@
<?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.Issue10947"
xmlns:ios="clr-namespace:Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific;assembly=Microsoft.Maui.Controls"
ios:NavigationPage.PrefersLargeTitles="false"
Title="Issue10947">

<ContentPage.Resources>
<x:Array x:Key="stringArray" Type="{x:Type x:String}">
<x:String>First Item</x:String>
<x:String>Second Item</x:String>
<x:String>Third Item</x:String>
<x:String>Fourth Item</x:String>
<x:String>Fifth Item</x:String>
<x:String>Sixth Item</x:String>
</x:Array>
</ContentPage.Resources>

<CollectionView x:Name="CollectionView1" ItemsSource="{StaticResource stringArray}" Background="aliceblue">
<CollectionView.Header>
<StackLayout Background="Pink">
<Entry AutomationId="HeaderEntry"
Background="LightGray"
Placeholder="Header Entry"/>
</StackLayout>
</CollectionView.Header>
<CollectionView.Footer>
<StackLayout Background="Pink">
<Entry AutomationId="FooterEntry"
Background="LightGray"
Placeholder="Footer Entry" />
</StackLayout>
</CollectionView.Footer>
<CollectionView.ItemTemplate>
<DataTemplate>
<Entry Text="{Binding .}"/>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</ContentPage>
@@ -0,0 +1,19 @@
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.Xaml;
using Microsoft.Maui.Platform;
using Microsoft.Maui.Controls.PlatformConfiguration;
using Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific;
using System;

namespace Maui.Controls.Sample.Issues;

[XamlCompilation(XamlCompilationOptions.Compile)]
[Issue(IssueTracker.Github, 10947, "CollectionView Header and Footer Scrolling", PlatformAffected.iOS)]

public partial class Issue10947 : ContentPage
{
public Issue10947()
{
InitializeComponent();
}
}
Expand Up @@ -174,6 +174,13 @@ public override void ViewDidLoad()
EnsureLayoutInitialized();
}

public override void LoadView()
{
base.LoadView();

CollectionView = new MauiCollectionView(CGRect.Empty, ItemsViewLayout);
mattleibow marked this conversation as resolved.
Show resolved Hide resolved
}

public override void ViewWillAppear(bool animated)
{
base.ViewWillAppear(animated);
Expand Down
17 changes: 17 additions & 0 deletions src/Controls/src/Core/Handlers/Items/iOS/MauiCollectionView.cs
@@ -0,0 +1,17 @@
using CoreGraphics;
using UIKit;

namespace Microsoft.Maui.Controls.Handlers.Items;

internal class MauiCollectionView : UICollectionView
{
public MauiCollectionView(CGRect frame, UICollectionViewLayout layout) : base(frame, layout)
{
}

public override void ScrollRectToVisible(CGRect rect, bool animated)
{
if (!KeyboardAutoManagerScroll.IsKeyboardAutoScrollHandling)
base.ScrollRectToVisible(rect, animated);
}
}
Expand Up @@ -73,6 +73,7 @@ Microsoft.Maui.Controls.PointerGestureRecognizer.PointerReleasedCommand.get -> S
Microsoft.Maui.Controls.PointerGestureRecognizer.PointerReleasedCommand.set -> void
Microsoft.Maui.Controls.PointerGestureRecognizer.PointerReleasedCommandParameter.get -> object!
Microsoft.Maui.Controls.PointerGestureRecognizer.PointerReleasedCommandParameter.set -> void
override Microsoft.Maui.Controls.Handlers.Items.ItemsViewController<TItemsView>.LoadView() -> void
static readonly Microsoft.Maui.Controls.KeyboardAccelerator.KeyProperty -> Microsoft.Maui.Controls.BindableProperty!
static readonly Microsoft.Maui.Controls.KeyboardAccelerator.ModifiersProperty -> Microsoft.Maui.Controls.BindableProperty!
static readonly Microsoft.Maui.Controls.DragGestureRecognizer.CanDragProperty -> Microsoft.Maui.Controls.BindableProperty!
Expand Down
Expand Up @@ -72,6 +72,7 @@ Microsoft.Maui.Controls.PointerGestureRecognizer.PointerReleasedCommand.get -> S
Microsoft.Maui.Controls.PointerGestureRecognizer.PointerReleasedCommand.set -> void
Microsoft.Maui.Controls.PointerGestureRecognizer.PointerReleasedCommandParameter.get -> object!
Microsoft.Maui.Controls.PointerGestureRecognizer.PointerReleasedCommandParameter.set -> void
override Microsoft.Maui.Controls.Handlers.Items.ItemsViewController<TItemsView>.LoadView() -> void
static readonly Microsoft.Maui.Controls.KeyboardAccelerator.KeyProperty -> Microsoft.Maui.Controls.BindableProperty!
static readonly Microsoft.Maui.Controls.KeyboardAccelerator.ModifiersProperty -> Microsoft.Maui.Controls.BindableProperty!
static readonly Microsoft.Maui.Controls.DragGestureRecognizer.CanDragProperty -> Microsoft.Maui.Controls.BindableProperty!
Expand Down
38 changes: 38 additions & 0 deletions src/Controls/tests/UITests/Tests/Issues/Issue10947.cs
@@ -0,0 +1,38 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.AppiumTests.Issues;

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

public override string Issue => "CollectionView Header and Footer Scrolling";
string HeaderEntry => "HeaderEntry";
string FooterEntry => "FooterEntry";

[Test]
public void CollectionViewHeaderShouldNotScroll()
{
var headerEntry = App.WaitForElement(HeaderEntry);
var headerLocation = headerEntry.GetRect();
var footerEntry = App.WaitForElement(FooterEntry);
var footerLocation = headerEntry.GetRect();

App.Click(HeaderEntry);

var newHeaderEntry = App.WaitForElement(HeaderEntry);
var newHeaderLocation = headerEntry.GetRect();
Assert.AreEqual(headerLocation, newHeaderLocation);

App.Click(FooterEntry);

var newFooterEntry = App.WaitForElement(FooterEntry);
var newFooterLocation = headerEntry.GetRect();

Assert.AreEqual(footerLocation, newFooterLocation);
}
}
2 changes: 1 addition & 1 deletion src/Core/src/Platform/iOS/KeyboardAutoManagerScroll.cs
Expand Up @@ -317,7 +317,7 @@ internal static void AdjustPosition()
nfloat statusBarHeight;
nfloat navigationBarAreaHeight;

if (ContainerView.FindResponder<UINavigationController>() is UINavigationController navigationController)
if (View.FindResponder<UINavigationController>() is UINavigationController navigationController)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small change in my scrolling code here to use the current UINavigationController instead of the top-most one in case there are multiple UINavigationControllers. This presented an issue from building the UITest for this PR!

{
navigationBarAreaHeight = navigationController.NavigationBar.Frame.GetMaxY();
}
Expand Down