FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

chore: refactor the way the 'closeCallback' is called if no viewContr… · NativeScript/NativeScript@1243ef6 · GitHub

Commit 1243ef6

Browse files
VladimirAmiorkov
committed
chore: refactor the way the 'closeCallback' is called if no viewControler is present
1 parent 5e744ef commit 1243ef6

2 files changed

Lines changed: 16 additions & 11 deletions

File tree

‎tns-core-modules/ui/core/view/view-common.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,11 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition {
324324
}
325325
}
326326

327-
that._hideNativeModalView(parent, whenClosedCallback);
327+
if (that.viewController) {
328+
that._hideNativeModalView(parent, whenClosedCallback);
329+
} else {
330+
whenClosedCallback();
331+
}
328332
}
329333
};
330334
}

‎tns-core-modules/ui/core/view/view.ios.ts‎

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ export class View extends ViewCommon {
417417

418418
if (presentationStyle === UIModalPresentationStyle.Popover) {
419419
const popoverPresentationController = controller.popoverPresentationController;
420-
this._popoverPresentationDelegate = ios.UIPopoverPresentationControllerDelegateImp.initWithOwner(new WeakRef(this), options.closeCallback);
420+
this._popoverPresentationDelegate = ios.UIPopoverPresentationControllerDelegateImp.initWithOwnerAndCallback(new WeakRef(this), this._closeModalCallback);
421421
popoverPresentationController.delegate = this._popoverPresentationDelegate;
422422
const view = parent.nativeViewProtected;
423423
// Note: sourceView and sourceRect are needed to specify the anchor location for the popover.
@@ -452,14 +452,15 @@ export class View extends ViewCommon {
452452
return;
453453
}
454454

455-
if (!this.viewController) {
456-
return;
457-
}
458-
459455
const parentController = parent.viewController;
460456
const animated = (<any>this.viewController).animated;
461457

462458
parentController.dismissViewControllerAnimatedCompletion(animated, whenClosedCallback);
459+
460+
// We are manually calling the callback because 'UIModalPresentationStyle.Popover' case
461+
if (this.viewController.popoverPresentationController) {
462+
whenClosedCallback();
463+
}
463464
}
464465

465466
[isEnabledProperty.getDefault](): boolean {
@@ -994,21 +995,21 @@ export namespace ios {
994995
public static ObjCProtocols = [UIPopoverPresentationControllerDelegate];
995996

996997
private owner: WeakRef<View>;
997-
private whenClosedCallback: Function;
998+
private closedCallback: Function;
998999

999-
public static initWithOwner(owner: WeakRef<View>, whenClosedCallback: Function): UIPopoverPresentationControllerDelegateImp {
1000+
public static initWithOwnerAndCallback(owner: WeakRef<View>, whenClosedCallback: Function): UIPopoverPresentationControllerDelegateImp {
10001001
const instance = <UIPopoverPresentationControllerDelegateImp>super.new();
10011002
instance.owner = owner;
1002-
instance.whenClosedCallback = whenClosedCallback;
1003+
instance.closedCallback = whenClosedCallback;
10031004

10041005
return instance;
10051006
}
10061007

10071008
public popoverPresentationControllerDidDismissPopover(popoverPresentationController: UIPopoverPresentationController) {
10081009
const owner = this.owner.get();
10091010
if (owner) {
1010-
if (typeof this.whenClosedCallback === "function") {
1011-
this.whenClosedCallback();
1011+
if (typeof this.closedCallback === "function") {
1012+
this.closedCallback();
10121013
}
10131014
}
10141015
}

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL