Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-25685] Android: TabGroup 'close' event is never fired #9758

Merged
merged 9 commits into from
May 23, 2018
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,8 @@ protected void handleClose(KrollDict options)
{
Log.d(TAG, "handleClose: " + options, Log.DEBUG_MODE);

fireEvent(TiC.EVENT_CLOSE, null);

modelListener = null;
releaseViews();
view = null;
Expand Down
3 changes: 2 additions & 1 deletion apidoc/Titanium/UI/TabGroup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ events:

- name: close
summary: Fired when the tab group is closed.
platforms: [iphone, ipad]
since: {android: "7.1.0"}
platforms: [iphone, ipad, android]

- name: focus
summary: |
Expand Down
4 changes: 4 additions & 0 deletions iphone/Classes/TiUITabGroup.m
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,10 @@ - (void)open:(id)args

- (void)close:(id)args
{
if ([self.proxy _hasListeners:@"close"]) {
[self.proxy fireEvent:@"close" withObject:event];
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be called event-driven (by delegates that actually execute the closing. Let me find a better place to put it.

EDIT: Either here or by implementing the windowDidClose selector.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this close method called by windowDidClose anyway?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is (by windowWillClose), but if you call it manually, the close event may fire before the window actually finishing closing. I'll prepare a test-case tomorrow.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, so let's do this (as the above test-case does not actually close the tab group):

var win = Ti.UI.createWindow(),
	tabGroup = Ti.UI.createTabGroup();
	tab = Ti.UI.createTab({
		title: 'Tab',
		window: win
	});
  
win.addEventListener('open', function() {
  setTimeout(function() {
    tabGroup.close();
  }, 2000);
})

tabGroup.addEventListener('close', function() {
	console.log('TabGroup.close()');
});

tabGroup.addTab(tab);
tabGroup.open();

It will wait 2 seconds after the application finished launching and close the tab-group. First, windowWillClose is called to cleanup the navigation stack. Once done, it will will invoke it's super-class that will clean up all child views (TiViewProxy instances).

Then, finally, the TiWindowProxy, which the TiUITabGroupProxy inherits from cleans up (dismisses the actual controller, fire the child close events) and sends windowDidClose to TiUITabGroupProxy.

So after all, the close event in its current state would fire before the tabgroup actually finished closing, which is different from the behavior of other root view controllers (like window or split-window on iOS).

And as you stated above, because the class inherits from TiWindowProxy, is should fire the event already (but the link you referenced was linking to the wrong method).


if (controller != nil) {
controller.viewControllers = nil;
}
Expand Down
23 changes: 23 additions & 0 deletions tests/Resources/ti.ui.tabgroup.addontest.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,27 @@ describe('Titanium.UI.TabGroup', function () {
tabGroup.addTab(tab);
tabGroup.open();
});

it('close event', function (finish) {
this.timeout(10000);

var win = Ti.UI.createWindow();

tabGroup.addEventListener('open', function () {
tabGroup.close();
});

tabGroup.addEventListener('close', function () {
finish();
});

tabGroup = Ti.UI.createTabGroup();
tab = Ti.UI.createTab({
title: 'Tab',
window: win
});

tabGroup.addTab(tab);
tabGroup.open();
});
});