diff --git a/iphone/TitaniumKit/TitaniumKit/Sources/API/TiProxy.m b/iphone/TitaniumKit/TitaniumKit/Sources/API/TiProxy.m index d43ba4f3f81..63be722dba5 100644 --- a/iphone/TitaniumKit/TitaniumKit/Sources/API/TiProxy.m +++ b/iphone/TitaniumKit/TitaniumKit/Sources/API/TiProxy.m @@ -800,10 +800,10 @@ - (void)removeEventListener:(NSArray *)args //TODO: You know, we can probably nip this in the bud and do this at a lower level, //Or make this less onerous. - int ourCallbackCount = 0; pthread_rwlock_wrlock(&listenerLock); - ourCallbackCount = [[listeners objectForKey:type] intValue] - 1; + int ourCallbackCount = [[listeners objectForKey:type] intValue]; + ourCallbackCount = MAX(0, ourCallbackCount - 1); [listeners setObject:NUMINT(ourCallbackCount) forKey:type]; pthread_rwlock_unlock(&listenerLock); diff --git a/tests/Resources/ti.ui.window.test.js b/tests/Resources/ti.ui.window.test.js index 45b6ad6727e..72ffb9434f1 100644 --- a/tests/Resources/ti.ui.window.test.js +++ b/tests/Resources/ti.ui.window.test.js @@ -1125,4 +1125,22 @@ describe('Titanium.UI.Window', function () { // ios took 1ms repeatedly // so 1 second should be enough time. }); + + it('TIMOB-28267 On removing event listener multiple times and adding once afterward, event should be fired', finish => { + const win = Ti.UI.createWindow({ + backgroundColor: '#0000ff' + }); + + win.addEventListener('open', openListener); + win.removeEventListener('open', openListener); + win.removeEventListener('open', openListener); + win.removeEventListener('open', openListener); + win.addEventListener('open', openListener); + + function openListener () { + win.removeEventListener('open', openListener); + finish(); + } + win.open(); + }); });