fix(view-controller): dismiss does not crash when called more than once

fixes #8395
This commit is contained in:
Manu Mtz.-Almeida
2016-10-02 17:15:23 +02:00
parent 2bc4df8d4b
commit d5f71a448d
2 changed files with 22 additions and 0 deletions

View File

@ -117,8 +117,26 @@ describe('ViewController', () => {
viewController.dismiss('didDismiss data'); viewController.dismiss('didDismiss data');
}, 10000); }, 10000);
it('should not crash when calling dismiss() twice', (done) => {
// arrange
let viewController = mockView();
let navControllerBase = mockNavController();
mockViews(navControllerBase, [viewController]);
viewController.onDidDismiss((data: any) => {
expect(data).toEqual('didDismiss data');
setTimeout(() => {
viewController.dismiss(); // it should not crash
done();
}, 100);
}); });
viewController.dismiss('didDismiss data');
}, 10000);
});
afterEach(() => { afterEach(() => {
if (subscription) { if (subscription) {
subscription.unsubscribe(); subscription.unsubscribe();

View File

@ -180,6 +180,10 @@ export class ViewController {
* *
*/ */
dismiss(data?: any, role?: any, navOptions: NavOptions = {}) { dismiss(data?: any, role?: any, navOptions: NavOptions = {}) {
if (!this._nav) {
return Promise.resolve(false);
}
let options = merge({}, this._leavingOpts, navOptions); let options = merge({}, this._leavingOpts, navOptions);
this._onWillDismiss && this._onWillDismiss(data, role); this._onWillDismiss && this._onWillDismiss(data, role);
return this._nav.remove(this._nav.indexOf(this), 1, options).then(() => { return this._nav.remove(this._nav.indexOf(this), 1, options).then(() => {