Coder Social home page Coder Social logo

ListView: when adding/removing items, app immediately crashes on Windows, raise 'ItemTemplate count has exceeded the limit of 23' Exception on Android about fabulous.mauicontrols HOT 2 OPEN

heldap avatar heldap commented on May 27, 2024
ListView: when adding/removing items, app immediately crashes on Windows, raise 'ItemTemplate count has exceeded the limit of 23' Exception on Android

from fabulous.mauicontrols.

Comments (2)

TimLariviere avatar TimLariviere commented on May 27, 2024

Thanks for the report!
I managed to reproduce with the example given 👍

What's happening in your case is that Fabulous expects your items to be a stable reference value (aka mutable list) instead of a non-mutable one (like F# list type where a new list instance is created with each mutation).

If the reference changes, Fabulous will consider the whole list needs to be reloaded and will lose the DataTemplates that were created previously -- causing the crash on Android after reaching the limit of .NET MAUI.

A workaround would be to change the Model type:

type Model = { Items: ObservableCollection<Item> }

Note: I'm using ObservableCollection instead of any System.Collections.IList type, because .NET MAUI expects the collection to raise events when adding/removing items which ObservableCollection do

Then, you can still add and remove items like usual.

let init () =
    let items = ObservableCollection<Item>()
    items.Add(Item.create())
    { Items = items }, Cmd.none

let update msg model =
    match msg with
    | Add ->
        model.Items.Add(Item.create())
        model, Cmd.none
    | RemoveLast ->
        if model.Items.Count > 0 then
            model.Items.RemoveAt(model.Items.Count - 1)
        
        model, Cmd.none

This approach will work, though it has some drawbacks because of the mutated collection (especially if you want clean separation between states).

Virtualized collection widgets like ListView are very tricky to work with in Fabulous, and can easily crash.
I'm not really satisfied with our implementation.

from fabulous.mauicontrols.

heldap avatar heldap commented on May 27, 2024

Thanks you for the quick reply :)
This workaround is fine for my needs.

May I close this issue ?
It could be interesting to keep it opened though, as someone else might encounter this issue (since using F# list is instinctive): keeping it opened makes the workaround visible.

from fabulous.mauicontrols.

Related Issues (12)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.