tidev / titanium-sdk

🚀 Native iOS and Android Apps with JavaScript
https://titaniumsdk.com/
Other
2.76k stars 1.21k forks source link

fix(android): append ListView events while scrolling #13958

Open m1ga opened 11 months ago

m1ga commented 11 months ago

Before this PR the template events only worked for visible items. Items that were generated during scrolling didn't have the events.

Test

var win = Ti.UI.createWindow({
    backgroundColor: 'white'
});

function playout() {
    console.log("Post")
    this.removeEventListener("postlayout", playout);
    this.animate({
        opacity: 1,
        duration: 150,
        curve: Titanium.UI.ANIMATION_CURVE_EASE_IN
    });
}

var myTemplate = {
    events: {
        postlayout: playout
    },
    properties: {
        height: 100,
        opacity: 0.1
    },
    childTemplates: [{
            type: 'Ti.UI.Label',
            bindId: 'info',
            properties: {
                color: 'black',
                font: {
                    fontFamily: 'Arial',
                    fontSize: '20dp',
                    fontWeight: 'bold'
                },
                left: '60dp',
                top: 0,
            }
        },
        {
            type: 'Ti.UI.Label',
            bindId: 'es_info',
            properties: {
                color: 'gray',
                font: {
                    fontFamily: 'Arial',
                    fontSize: '14dp'
                },
                left: '60dp',
                top: '25dp',
            }
        }
    ]
};

var listView = Ti.UI.createListView({

    templates: {
        'template': myTemplate
    },
    defaultItemTemplate: 'template'
});
var sections = [];

var fruitDataSet = [
    {
        info: {
            text: 'Apple'
        },
        es_info: {
            text: 'Manzana'
        }
    },
    {
        info: {
            text: 'Banana'
        },
        es_info: {
            text: 'Banana'
        }
    }
];
var fruitSection = Ti.UI.createListSection({
    headerTitle: 'Fruits / Frutas',
    items: fruitDataSet
});
sections.push(fruitSection);

var vegDataSet = [{
        info: {
            text: 'Carrot'
        },
        es_info: {
            text: 'Zanahoria'
        }
    },
    {
        info: {
            text: 'Potato'
        },
        es_info: {
            text: 'Patata'
        }
    }
];
var vegSection = Ti.UI.createListSection({
    headerTitle: 'Vegetables / Verduras',
    items: vegDataSet
});
sections.push(vegSection);
var grainDataSet = [];
for (var i = 0; i < 100; ++i) {
    grainDataSet.push({
        info: {
            text: 'Corn'
        },
        es_info: {
            text: 'Maiz'
        },
        pic: {
            image: 'corn.png'
        }
    }, {
        info: {
            text: 'Rice'
        },
        es_info: {
            text: 'Arroz'
        }
    });
}
var grainSection = Ti.UI.createListSection({
    headerTitle: 'Grains / Granos',
    items: grainDataSet
});
sections.push(grainSection);

listView.sections = sections;
win.add(listView);
win.open();