tidev / titanium-sdk

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

feat(android): expose contentOffset getter in TableView/ListView #14058

Closed m1ga closed 5 months ago

m1ga commented 5 months ago

Method was already but not exposed as a getter.

const win = Ti.UI.createWindow();

var tableData = [];
for (var i = 0; i < 100; ++i) {
    tableData.push({
        title: "id" + i
    })
}

const tbl = Ti.UI.createTableView({
    data: tableData
});
win.add(tbl)
win.open();

win.addEventListener("open", function() {
    console.log(tbl.contentOffset);

    tbl.setContentOffset({
        x: 0,
        y: 200
    }, {
        animated: false
    })

    setTimeout(function() {
        console.log(tbl.contentOffset);
    }, 500)
})

ListView

var win = Ti.UI.createWindow({backgroundColor: 'gray'});
var listView = Ti.UI.createListView();
var sections = [];

var fruitDataSet = []
for (var i=0;i<100;++i){
    fruitDataSet.push({properties: { title: 'Apple'}})
}
var fruitSection = Ti.UI.createListSection({ headerTitle: 'Fruits', items: fruitDataSet});
sections.push(fruitSection);

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

win.addEventListener("open", function() {
    console.log(listView.contentOffset);

    listView.setContentOffset({
        x: 0,
        y: 200
    }, {
        animated: false
    })

    setTimeout(function() {
        console.log(listView.contentOffset);
    }, 500)
})