tidev / titanium-sdk

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

feat(ios): add direction to ListView scrolling #14130

Closed m1ga closed 1 month ago

m1ga commented 1 month ago

iOS currently only adds direction in the scrolling event when you release the finger. This PR adds it to the continuous scrolling (old PR)

var toggle = false;
var sections = [];
const win = Ti.UI.createWindow();
const btn = Ti.UI.createButton({
    title: "change",
    bottom: 20
});
const lbl = Ti.UI.createLabel({
    top: 10,
    right: 10,
    width: Ti.UI.SIZE,
    height: Ti.UI.SIZE
})
const listView = Ti.UI.createListView({
    height: Ti.UI.FILL,
    width: Ti.UI.FILL,
    continuousUpdate: true,
  forceUpdates: false
});

btn.addEventListener("click", function() {
    toggle = !toggle;
    listView.forceUpdates = toggle
    console.log(listView.forceUpdates);
})

for (var s = 0; s < 5; s++) {
    var section = Ti.UI.createListSection({
        headerTitle: 'Section ' + s
    });
    var set = [];
    for (var i = 0; i < 20; ++i) {
        set.push({
            properties: {
                title: 'Item 0 ' + i
            }
        })
    }
    section.setItems(set);
    sections.push(section);
}

listView.sections = sections;
win.add([listView, btn, lbl]);

listView.addEventListener("scrolling", function(e) {
    lbl.text = "Item: " + e.firstVisibleItemIndex + " section:" + e.firstVisibleSectionIndex;
    console.log("Item", e.direction, e.firstVisibleItemIndex, e.firstVisibleSectionIndex, e.top);
})
win.open();

https://github.com/user-attachments/assets/f5c36153-0ef1-4e90-a21c-f4a1d121b75b

hansemannn commented 1 month ago

Are there API docs for this already?

m1ga commented 1 month ago

yes, since 5.4.0 https://github.com/tidev/titanium-sdk/blob/master/apidoc/Titanium/UI/ListView.yml#L648-L652 With a note On iOS no event is fired when the finger is not released. With continuousUpdate event you've got it more often but the direction was not yet in there. That was still only fired after touching the screen.

hansemannn commented 1 month ago

@m1ga The recent changes should fix that - are you okay with these?

m1ga commented 1 month ago

Looking good, code still works fine, thanks :+1: