tidev / titanium-sdk

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

TableView: contentOffset improvements #14075

Open m1ga opened 4 months ago

m1ga commented 4 months ago

I have searched and made sure there are no existing issues for the issue I am filing

Description

The TableView contentOffset value is different on Android/iOS:

Android: There are getters table.contentOffset.x and table.contentOffset.y but the value is returning a native height value (you have to divide it by ldi). The value in the scroll event is already in local space

iOS: The getter is 0 and it only has the scroll event values.

Expected Behavior

Getter should be available on both platforms and it should return the same value as the scroll event contentOffset.

Actual behavior

Reproducible sample

var ldi = Ti.Platform.displayCaps.logicalDensityFactor;

var win = Ti.UI.createWindow();
var btn = Ti.UI.createButton({
    title: "click"
})
var tableData = [];
for (var i = 0; i < 100; ++i) {
    tableData.push({
        title: "Test" + i
    })
}

var table = Ti.UI.createTableView({
    data: tableData
});
win.add(table);
win.add(btn);
btn.addEventListener("click", function() {
    console.log("Current: " + table.contentOffset.x + " - " +table.contentOffset.y, "Fixed: " + Math.round(table.contentOffset.y/ldi));
})
table.addEventListener("scroll", function(e) {
    console.log(e.contentOffset.x, e.contentOffset.y);
})
win.open();

Steps to reproduce

Run the app, scroll the table and click the button. The normal contentOffset.y value should be the same in both cases.

Platform

Android & iOS

SDK version you are using

12.4.0

Alloy version you are using

No response