xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.62k stars 1.87k forks source link

[Bug] When expanding the last tile in a Grouped Accordion ListView, the content is not visible #10030

Open doriangh opened 4 years ago

doriangh commented 4 years ago

Description

When having a Grouped ListView with accordions, when there are enough groups so it can fill the whole screen and even more, when going straight to the bottom group, it does not come into view. It expands under the screen.

Steps to Reproduce

  1. Create a Grouped Accordion ListView
  2. Bind enough data as to be able to scroll
  3. Expand the last group

Expected Behavior

The list view slightly scrolls up as to place into view the content of the group

Actual Behavior

The group expands but the data is underneath, and the user has to scroll to be able to see the data

Basic Information

jfversluis commented 4 years ago

Hi @doriangh thanks for the report.

When you talk about "Grouped Accordion ListView" is that something custom you have created or a third-party control or something?

It would be great if you could provide a little reproduction project that shows the issue. Same goes for the other issue you just opened.

doriangh commented 4 years ago

Hello! Here's a reproduction link. https://github.com/doriangh/AccordionListViewProblem As I can see the groups don't have the children data inside, but it doesn't matter as the group expands.

The reproduction link works for both issues as closing the group calls Clear() method.

Thank you!

jfversluis commented 4 years ago

So, I'm not really sure if this is a bug. While this is clearly possible with a ListView, I don't think this was an intended use-case. I have however managed to come up with (some kind of) workaround.

Depending on how you want to reference your ListView you can do something like this.

public ICommand ExpandGroup => new Command<TestItemGroupModel>(group =>
{
       if (!group.Expanded && GroupItems.Any(x => x.Expanded))
           GroupItems.FirstOrDefault(x => x.Expanded).Expanded = false;
      group.Expanded = !group.Expanded;

      // This was added
      MessagingCenter.Send(this, "scrollit");
});
        public ItemsPage()
        {
            InitializeComponent();

            BindingContext = viewModel = new ItemsViewModel();

            // This was added
            MessagingCenter.Subscribe<ItemsViewModel>(this, "scrollit", m => ItemsListView.ScrollTo(m.GroupItems.FirstOrDefault(i => i.Expanded)?[0], ScrollToPosition.Start, false));
        }

You can do it a bit differently and definitely add error handling, but this way the opened group will scroll into view.

You might have better luck with using the CollectionView where you have more fine-grained control over scrolling and such, or maybe keep your eye on #9044

doriangh commented 4 years ago

Thank you very much for your reply. I have tested the workaround and can confirm it is working. I have tried using a CollectionView, but I had no success in converting from ListView to CollectionView with my approach of an accordion ListView. Maybe if anyone can figure out a way, I'd be thankful. So far, with Xamarin.Forms 4.5 the app crashes on Clear() method. And with Forms 4.4 the header layout I am using does not render well, and the header trigger is not firing.

But thanks anyway!

PureWeen commented 4 years ago

So far, with Xamarin.Forms 4.5 the app crashes on Clear() method. And with Forms 4.4 the header layout I am using does not render well, and the header trigger is not firing.

@doriangh can you log a bug? It'll be quicker to get this all working and fixed in CollectionView then it will be with ListView