[AC-6667] iOS: removeEventListener removes "any" callback
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | n/a |
Status | Open |
Resolution | Unresolved |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | Titanium SDK & CLI |
Labels | ios |
Reporter | martin |
Assignee | Rene Pot |
Created | 2021-01-26T15:00:01.000+0000 |
Updated | 2021-01-27T16:46:52.000+0000 |
Description
The removeEventListener should only remove a callback function that was previously added, but on iOS it removes any one with the same event type, see test case below.
const win=Ti.UI.createWindow({
backgroundColor:'#fff'
});
const view=Ti.UI.createButton({
title:'This button does nothing on OS...'
});
view.addEventListener('click',()=>{
alert('This alert does not open on iOS...')
});
view.removeEventListener('click',()=>{}); //This removes the callback added above, but it shouldn't!
win.add(view);
win.open();
Hi,
removeEventListener
indeed removes events of the same type, otherwise, it would be impossible to remove anonymous callbacks. It is ALWAYS recommended to use named callbacks so you can prevent this yourself.Hi Rene, Anonymous functions are not the point here. You could change my example to use named callbacks and it will give the same result:
If testing this on Android it will correctly show the alert when clicking the button. On iOS it will not.
Thanks for clarifying that, that wasn't clear from your original sample, there it actually behaved as expected. I will have a look at this one and get back to you!