Skip to content

Commit d5f71a4

Browse files
committed
fix(view-controller): dismiss does not crash when called more than once
fixes #8395
1 parent 2bc4df8 commit d5f71a4

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/navigation/test/view-controller.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,26 @@ describe('ViewController', () => {
117117

118118
viewController.dismiss('didDismiss data');
119119
}, 10000);
120+
121+
it('should not crash when calling dismiss() twice', (done) => {
122+
// arrange
123+
let viewController = mockView();
124+
let navControllerBase = mockNavController();
125+
mockViews(navControllerBase, [viewController]);
126+
127+
viewController.onDidDismiss((data: any) => {
128+
expect(data).toEqual('didDismiss data');
129+
setTimeout(() => {
130+
viewController.dismiss(); // it should not crash
131+
done();
132+
}, 100);
133+
});
134+
135+
viewController.dismiss('didDismiss data');
136+
}, 10000);
120137
});
121138

139+
122140
afterEach(() => {
123141
if (subscription) {
124142
subscription.unsubscribe();

src/navigation/view-controller.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,10 @@ export class ViewController {
180180
*
181181
*/
182182
dismiss(data?: any, role?: any, navOptions: NavOptions = {}) {
183+
if (!this._nav) {
184+
return Promise.resolve(false);
185+
}
186+
183187
let options = merge({}, this._leavingOpts, navOptions);
184188
this._onWillDismiss && this._onWillDismiss(data, role);
185189
return this._nav.remove(this._nav.indexOf(this), 1, options).then(() => {

0 commit comments

Comments
 (0)