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

chore: refator 'popover' modal closed callback implementation · NativeScript/NativeScript@719e118 · GitHub

Commit 719e118

Browse files
VladimirAmiorkov
committed
chore: refator 'popover' modal closed callback implementation
1 parent 02d35ab commit 719e118

3 files changed

Lines changed: 9 additions & 28 deletions

File tree

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition {
6767
public static layoutChangedEvent = "layoutChanged";
6868
public static shownModallyEvent = "shownModally";
6969
public static showingModallyEvent = "showingModally";
70-
public static popoverClosedEvent = "popoverClosed";
7170

7271
protected _closeModalCallback: Function;
7372

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,6 @@ export abstract class View extends ViewBase {
113113
*/
114114
public static showingModallyEvent: string;
115115

116-
/**
117-
* String value used when hooking to popoverClosed event.
118-
*/
119-
public static popoverClosedEvent: string;
120-
121116
/**
122117
* String value used when hooking to shownModally event.
123118
*/

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

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Definitions.
22
import { Point, View as ViewDefinition, dip } from ".";
3-
import { ViewBase, EventData } from "../view-base";
3+
import { ViewBase } from "../view-base";
44

55
import {
66
ViewCommon, layout, isEnabledProperty, originXProperty, originYProperty, automationTextProperty, isUserInteractionEnabledProperty,
@@ -44,11 +44,6 @@ export class View extends ViewCommon {
4444
*/
4545
_nativeBackgroundState: "unset" | "invalid" | "drawn";
4646

47-
constructor() {
48-
super();
49-
this.on(ViewCommon.popoverClosedEvent, this.closeModal.bind(this));
50-
}
51-
5247
get isLayoutRequired(): boolean {
5348
return (this._privateFlags & PFLAG_LAYOUT_REQUIRED) === PFLAG_LAYOUT_REQUIRED;
5449
}
@@ -422,7 +417,7 @@ export class View extends ViewCommon {
422417

423418
if (presentationStyle === UIModalPresentationStyle.Popover) {
424419
const popoverPresentationController = controller.popoverPresentationController;
425-
this._popoverPresentationDelegate = ios.UIPopoverPresentationControllerDelegateImp.initWithOwner(new WeakRef(this));
420+
this._popoverPresentationDelegate = ios.UIPopoverPresentationControllerDelegateImp.initWithOwner(new WeakRef(this), options.closeCallback);
426421
popoverPresentationController.delegate = this._popoverPresentationDelegate;
427422
const view = parent.nativeViewProtected;
428423
// Note: sourceView and sourceRect are needed to specify the anchor location for the popover.
@@ -457,19 +452,10 @@ export class View extends ViewCommon {
457452
return;
458453
}
459454

460-
if (!this.viewController) {
461-
return;
462-
}
463-
464455
const parentController = parent.viewController;
465456
const animated = (<any>this.viewController).animated;
466457

467-
if (this.viewController.popoverPresentationController && this.viewController.popoverPresentationController instanceof UIPopoverPresentationController) {
468-
whenClosedCallback();
469-
parentController.dismissViewControllerAnimatedCompletion(animated, null);
470-
} else {
471-
parentController.dismissViewControllerAnimatedCompletion(animated, whenClosedCallback);
472-
}
458+
parentController.dismissViewControllerAnimatedCompletion(animated, whenClosedCallback);
473459
}
474460

475461
[isEnabledProperty.getDefault](): boolean {
@@ -1004,21 +990,22 @@ export namespace ios {
1004990
public static ObjCProtocols = [UIPopoverPresentationControllerDelegate];
1005991

1006992
private owner: WeakRef<View>;
993+
private whenClosedCallback: Function;
1007994

1008-
public static initWithOwner(owner: WeakRef<View>): UIPopoverPresentationControllerDelegateImp {
995+
public static initWithOwner(owner: WeakRef<View>, whenClosedCallback: Function): UIPopoverPresentationControllerDelegateImp {
1009996
const instance = <UIPopoverPresentationControllerDelegateImp>super.new();
1010997
instance.owner = owner;
998+
instance.whenClosedCallback = whenClosedCallback;
1011999

10121000
return instance;
10131001
}
10141002

10151003
public popoverPresentationControllerDidDismissPopover(popoverPresentationController: UIPopoverPresentationController) {
10161004
const owner = this.owner.get();
10171005
if (owner) {
1018-
let modalClosingArgs: EventData = <EventData>{
1019-
eventName: ViewCommon.popoverClosedEvent,
1020-
};
1021-
owner.notify(modalClosingArgs);
1006+
if (typeof this.whenClosedCallback === "function") {
1007+
this.whenClosedCallback();
1008+
}
10221009
}
10231010
}
10241011
}

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL