eclipsesource / tabris-js

Create native mobile apps in JavaScript or TypeScript.
https://tabrisjs.com
BSD 3-Clause "New" or "Revised" License
1.4k stars 170 forks source link

children() of CollectionView #1646

Closed kc853 closed 6 years ago

kc853 commented 6 years ago

Problem description

I was trying to access the children() collection of a CollectionView using the index in the select event. I got strange results. I then did a test (see code snippet) and recognized that the children() collection is not as long as expected. It grows on scrolling but stops at max. 23 on my phone. What could be the problem?

Expected behavior

The children() collection should contain one object for each cell of the CollectionView.

Environment

Code snippet

const {CollectionView, TextView, ui} = require('tabris');

let elements=[];
for (i = 0; i < 500; i++) elements[i]=i;

let tv = new TextView({
    left:10,right:10,top:0,background:'red',
    textColor:'white',font:'bold 34px',alignment:'center'
    }).appendTo(ui.contentView);

let cv= new CollectionView({
    left:10,right:10, top:'prev() 10',bottom:0,

    createCell: ()=>new TextView({left:10,right:10,top:0,alignment:'center'}),
    updateCell: (cell,index)=>cell.set('text',elements[index])

    }).on('scroll', ({target}) =>{
        tv.text=target.children().length;
    }).appendTo(ui.contentView);

cv.load(elements.length);
mpost commented 6 years ago

The children of a CollectionView are not a valid return value and should not be used. Since you are reusing the cells in the CV you can not access the widgets outside of the updateCells method.

kc853 commented 6 years ago

OK, may be it's worth to mention in the docs. Thank you.

mpost commented 6 years ago

Closing the issue as resolved.