Current behavior
With
listView.addEventListener('scrollstart', this.myCallback);
you can register an event listener. But there is no check if the listener is already registered.
So if you do something like this:
function attach() {
listView.addEventListener('scrollstart', this.myCallback);
}
attach();
//
// Lots of code or loop or async callback between
//
attach();
you habe a second registered callback. You have todo something like this to unregister:
listView.removeEventListener('scrollstart', this.myCallback);
listView.removeEventListener('scrollstart', this.myCallback);
Its difficult to debug problems around that if you overlooked the second call of addEventListener.
Expected
- The second listener is not registered
- (optional) Warning or notice that there is already a listener
PR pending : https://github.com/appcelerator/titanium_mobile/pull/7548. The Hello message should only be displayed ones upon scrollEnd regardless of how many eventListeners are added.
var win = Ti.UI.createWindow({ backgroundColor : 'blue', title : 'Main Window' }); var listView = Ti.UI.createListView(); function myFunction() { Ti.API.info("Hello"); } var itemsSection = Ti.UI.createListSection({ headerTitle: 'Items'}); var itemData = [ {properties: { title: 'Item 1'}}, {properties: { title: 'Item 2'}}, {properties: { title: 'Item 3'}}, {properties: { title: 'Item 4'}}, {properties: { title: 'Item 5'}}, {properties: { title: 'Item 6'}}, ]; listView.addEventListener("scrollend",myFunction); var addEventButton = Titanium.UI.createButton({ title: 'Add Event', bottom: 10, width: 100, height: 50 }); addEventButton.addEventListener("click",function(e){ listView.addEventListener("scrollend",myFunction); }); itemsSection.setItems(itemData); var sections = []; sections.push(itemsSection); listView.sections = sections; win.add(listView); win.add(addEventButton); win.open();CR and FT passed. PR Merged!
Closing ticket as fixed.