I’m running into an issue with a ListView Unbinding more frequently than it probably needs to. So I was wondering when exactly binding/unbinding happens to see if I can control it more precisely.
For some context, I have a list of ~40 data objects that are in a list view in a couple of spots in my game. In the first place, I have a list view that is predefined on a UXML file, and queried and set with code. This list view binds all of the data and the list view calls all of the “makeItem” calls right as its set, and never unbinds any elements, even if you scroll to the top or bottom of the list multiple times/quickly/etc. This listview covers from the bottom of the screen to ~ 80% from the top of the screen.
In a second section, I have the same data that needs to be in a LIst View. Visually, each element of the list is the same as in the previous list. The second list, however, is loaded into a much more demanding part of the UI, is created fully through code (vs the UXML of the first list), and the element’s “OnClick” is a little more complex. This list is also created with an async “bindItem” action (this doesn’t seem to be the issue though; I rewrote the first list to have an asynchronous bind to check, and it behaved the same way it did without it). This listview is smaller, and is contained in a modal window, so it takes up ~70% of the middle of the screen.
This second list only binds ~5-10 elements at a time, and unbinds them pretty quickly as you scroll. The problem with this is that each element is not the same size, so there’s a pretty significant pop as you scroll back up if a larger element higher up in the list than the current “view” is bound.
I was hoping to pre bind items if possible, or enforce a number to stay bound. Or if anyone knows what would be causing it to fully bind/vs partially bind the elements at least, so I can work around the expected behaviors. I know I could make my own “ListView” with a scroll area etc, pretty easily, but I hope there’s something simpler I can do with the default List View. Thanks in advance for any help!
Hi, I don’t fully know the strategy used by ListView to decide when it’s time to recycle items. I’d be interested to know more about this too. I’m commenting with a couple of ideas that don’t directly answer your question, but may help you anyway.
Does the second list have its virtualizationMethod set to DynamicHeight? If it doesn’t, I think that could solve the popping problem. If it does, I think that’s a bug worth reporting.
More generally, I’d suggest considering not using ListView as a workaround. If the UI handles 10 elements at a time well, and your list has ~40 objects, I’d say there’s a good possibility that it’ll handle having an element for each object well too.
EDIT
In case it helps, ListView is supposed to try to have the smallest number of elements at a time that are needed to fill the space occupied by the list. Bind and unbind are used to recycle those items as the user scrolls. I bet your first list has a much bigger height than the second, or the height of its elements is smaller.
I’d say the first list thinks the number of elements that fit inside it at the same time is very close to the total number of items, so it’s more efficient to just create one element for each item from the get go.
Yup, both have the virtualizationMethod set to DynamicHeight.
I thought it was supposed to bind/unbind as the objects left the scroll viewport, so maybe there is a bug with it. Both lists have the same height because the height is determined by the content items. And each content item is the same height in both places, just with a slightly smaller width. So that doesn’t seem to be it either.
I’ll branch my project and see if I can make a repro-able example to submit a bug report (it’s using live server connections right now so can’t isolate it quickly :() when I’ve got time. I ended up just swapping in a scrollview and populating it with the whole list. Honestly as nice as the ListView is, a scrollview and a for loop was way quicker to implement any way.