FR: Please fix TreeViewItem::createItemComponent() lifetime

Please fix TreeViewItem::createItemComponent() lifetime.

From the docs:

Also bear in mind that if the component keeps a reference to the item that created it, that item could be deleted before the component.

My use case:

  1. Create a bunch of objects
  2. Add TreeViewItems to the Tree represent these objects
  3. Sometime later, delete all the TreeViewItems and objects
  4. I now expect the TreeView to be empty
  5. TreeViewItem component crashes, because it points to a object that no longer exists

This limits the TreeViewItem Component to be fairly dumb and contain all the data it needs to operate. It can’t point back to some source object.

When you delete a TreeViewItem, it should immediately delete any components it created.

Alternative but now as good, please add a way to delete these dangling Components.

The accessibility work required a lot of refactoring in the TreeView and TreeViewItem classes and this was one of the issues that was addressed. The item owns the custom component and is guaranteed to outlive it so you can keep a reference in your component. This will go onto develop when we merge the branch in the next couple of weeks.

3 Likes

Great to hear. Looking forward to that merge, because I have similar issues with the TreeViewItem and its custom components. :slight_smile: