Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-20030] iOS: Repeated call of listView.addEventListener('scrollstart') should only result in 1 listener

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2015-12-10T06:02:14.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsiOS
LabelsCommunity
ReporterChristian Waldmann
AssigneeAngel Petkov
Created2015-07-22T13:39:29.000+0000
Updated2017-03-22T22:44:24.000+0000

Description

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

Comments

  1. Angel Petkov 2015-12-04

    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();
       
       
  2. Chee Kiat Ng 2015-12-10

    CR and FT passed. PR Merged!
  3. Lee Morris 2017-03-22

    Closing ticket as fixed.

JSON Source