Skip to content
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
Expand Up @@ -149,7 +149,7 @@ void OnItemsVectorChanged(global::Windows.Foundation.Collections.IObservableVect
{
var lastItem = items[itemsCount - 1];
// Adjusts the scroll offset to keep the last item in the list displayed when new items are added.
ListViewBase.ScrollIntoView(lastItem);
ListViewBase.ScrollIntoView(lastItem, ScrollIntoViewAlignment.Leading);
}
}

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
77 changes: 77 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue29207.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
using System.Collections.ObjectModel;

namespace Maui.Controls.Sample.Issues;
[Issue(IssueTracker.Github, 29207, "KeepLastItemInView Does Not Scroll to Last Item When Adding Items at Top, Instead Scrolls to SecondLast Item", PlatformAffected.UWP)]
public class Issue29207 : ContentPage
{
Issue29207_ItemsViewModel viewModel;

public Issue29207()
{
viewModel = new Issue29207_ItemsViewModel();
BindingContext = viewModel;

CollectionView collectionView = new CollectionView
{
ItemsSource = viewModel.ItemsSource,
ItemsUpdatingScrollMode = ItemsUpdatingScrollMode.KeepLastItemInView,
ItemTemplate = new DataTemplate(() =>
{
var label = new Label
{
FontSize = 20,
Padding = 10
};
label.SetBinding(Label.TextProperty, ".");
return label;
})
};

var addButton = new Button
{
Text = "Add",
WidthRequest = 120,
AutomationId = "InsertItemButton"
};
addButton.Clicked += Button_Clicked_1;

var buttonLayout = new HorizontalStackLayout
{
Padding = 40,
Spacing = 40,
Children = { addButton }
};

var grid = new Grid
{
RowDefinitions =
{
new RowDefinition { Height = GridLength.Auto },
new RowDefinition { Height = GridLength.Star }
}
};

grid.Add(buttonLayout, 0, 0);
grid.Add(collectionView, 0, 1);

Content = grid;
}

void Button_Clicked_1(object sender, EventArgs e)
{
viewModel.ItemsSource.Insert(0, $"NewItem");
}
}

public class Issue29207_ItemsViewModel
{
public ObservableCollection<string> ItemsSource = new ObservableCollection<string>();

public Issue29207_ItemsViewModel()
{
for(int i = 0; i < 20; i++)
{
ItemsSource.Add($"Item {i}");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#if TEST_FAILS_ON_IOS && TEST_FAILS_ON_CATALYST // CollectionView Fails to Keep Last Item in View on iOS and macOS https://github.com/dotnet/maui/issues/18029
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;

public class Issue29207 : _IssuesUITest
{
public Issue29207(TestDevice testDevice) : base(testDevice)
{
}
public override string Issue => "KeepLastItemInView Does Not Scroll to Last Item When Adding Items at Top, Instead Scrolls to SecondLast Item";

[Test]
[Category(UITestCategories.CollectionView)]
public void ScrollToLastItem()
{
App.WaitForElement("InsertItemButton");
App.Tap("InsertItemButton");
VerifyScreenshot();
Copy link
Contributor

Choose a reason for hiding this comment

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

Pending snapshots for Android and Windows. Running a build.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jsuarezruiz Added the Snapshots.

}
}
#endif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading