question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Listview does not work as expected

See original GitHub issue

I’ve build the following Component using a ListView to display some buttons with actions. If i open the menu and calling a Action for 23rd time, i will cause an Exception saying ‘system.exception: itemtemplate count has exceeded the limit of 23’. CollectionView instead will not cause any Exception. Is this a Maui bug or a Reactor-Maui bug? Even using the MauiControls.ListViewCachingStrategy.RecycleElementAndDataTemplate will not prevent this exception.

`public sealed class ActionMenuOverlay : Component { private IEnumerable<MenuAction> _menuActions = Enumerable.Range(0, 10).Select(x => new MenuAction {Text = “Im an action”});

public override VisualNode Render()
{
    var parameter = GetParameter<ActionMenuOverlayParameters>();
    return new ContentView
    {
        new Grid("2*,5*", "1*,1*")
        {
            //new CollectionView()
                //.ItemsSource(_menuActions, RenderMenuAction2)
                //.ItemsLayout(new VerticalLinearItemsLayout())
                //.BackgroundColor(Colors.White)
                //.GridColumn(1)
            
            new ListView(MauiControls.ListViewCachingStrategy.RecycleElementAndDataTemplate)
                .ItemsSource(_menuActions, RenderMenuAction)
            .BackgroundColor(Colors.White)
                .GridColumn(1)
        }
        .OnTapped(OnGridTapped)
        .BackgroundColor(Colors.Transparent)
    }
    .AbsoluteLayoutFlags(AbsoluteLayoutFlags.SizeProportional)
    .AbsoluteLayoutBounds(0,0,1,1)
    .IsVisible(parameter.Value.IsVisible)
    .ZIndex(25);
}

private ViewCell RenderMenuAction(MenuAction menuAction)
{
    return new ViewCell
    {
        new Button()
            .BackgroundColor(Colors.Transparent)
            .Text(menuAction.Text)
            .TextColor(Colors.Black)
            .OnClicked(() =>
            {
                menuAction.Action.Invoke();
                HideActionMenuOverlay();
            })
    };
}

private VisualNode RenderMenuAction2(MenuAction menuAction)
    => new Button()
    .BackgroundColor(Colors.Transparent)
    .Text(menuAction.Text)
    .TextColor(Colors.Black)
    .OnClicked(() =>
{
    menuAction.Action.Invoke();
    HideActionMenuOverlay();
});

private void OnGridTapped()
{
    System.Diagnostics.Debug.WriteLine("Grid tapped");
    HideActionMenuOverlay();
}

private void HideActionMenuOverlay()
{
    var parameter = GetParameter<ActionMenuOverlayParameters>();
    parameter.Set(x => x.IsVisible = false);
}

}`

Issue Analytics

  • State:closed
  • Created 3 months ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
adospacecommented, Jun 26, 2023

Hi, in Android there is a limit of 23 for the maximum number of DataTemplate that can be created and linked to a ListView (https://github.com/xamarin/Xamarin.Forms/issues/2931). Current implementation of the ListView in MauiReactor could easily reach that limit if you are going to pass to the list view a different items source at each render call (in you case you are re-rendering the component everytime a menu item is clicked).

So I can suggest a couple of things:

  1. Wait for the next version of MauiReactor that will reuse the datatemplate even if the ItemsSource changes.
  2. Better IMHO do not use a ListView or CollectionView at all: in your case (probably you’re implementing a ContextMenu-like UI) I think it’s better to stick with a VStack() containing the list of menu items (optionally inside a scrollview) as, I guess, the number of menu items are gereally small
0reactions
adospacecommented, Jun 26, 2023

Starting from 1.0.133, MauiReactor tries to reuse the data template as much as possible. The limit under Android could be anyway hit under certain circumstances like when the list view is hot reloaded more than 23 times.

Read more comments on GitHub >

github_iconTop Results From Across the Web

android - ListView adapter does not behave as expected
I'm having a problem that is making me crazy. Every adapters that I've made before with the same code worked perfectly, however this...
Read more >
ListView SelectionType.Multiple doesn't work as expected
Hi all, I'm trying to set up a ListViewwith multiple selections supported during runtime. Making items, binding and everything else ...
Read more >
The ItemTapped event for a grouped ListView is not ...
The ItemTapped event for a grouped ListView is not working as expected. ItemTappedEventArgs.Group is populated as expected, however ...
Read more >
Case list view not working as expected in community
I have created a list view on the case which is being used in a community. When a community user creates a record,...
Read more >
Lightning List Vew Search Not Returning Expected Results
When you search a list view, only the first 2,000 records in the list view are searched. Share.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found