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

fix: add delegate implementation for `popoverPresentationController` … · NativeScript/NativeScript@c5f5bd6 · GitHub

Commit c5f5bd6

Browse files
VladimirAmiorkov
committed
fix: add delegate implementation for popoverPresentationController and handle calling modal closeCallback #7050
chore: add example that shows "popover" mode for modal views
1 parent 4e56c89 commit c5f5bd6

7 files changed

Lines changed: 48 additions & 4 deletions

File tree

‎e2e/modal-navigation/app/home/home-page.ts‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as application from "tns-core-modules/application";
22
import { StackLayout } from "tns-core-modules/ui/layouts/stack-layout";
33
import { NavigatedData, Page } from "tns-core-modules/ui/page";
4-
import { View, EventData } from "tns-core-modules/ui/core/view";
4+
import { View, EventData, ShowModalOptions } from "tns-core-modules/ui/core/view";
55
import { Frame } from "tns-core-modules/ui/frame";
66

77
export function onNavigatingTo(args: NavigatedData) {
@@ -29,6 +29,20 @@ export function onModalNoPage(args: EventData) {
2929
false);
3030
}
3131

32+
export function onPopoverModal(args: EventData) {
33+
const view = args.object as View;
34+
let options: ShowModalOptions = {
35+
context: "context",
36+
closeCallback: () => console.log("home-page modal popover frame closed"),
37+
animated: false,
38+
ios: {
39+
presentationStyle: UIModalPresentationStyle.Popover
40+
}
41+
}
42+
43+
view.showModal("modal-no-page/modal-no-page", options);
44+
}
45+
3246
export function onModalFrame(args: EventData) {
3347
const view = args.object as View;
3448

‎e2e/modal-navigation/app/home/home-page.xml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<Button text="Show Modal Without Page" tap="onModalNoPage" textAlignment="left" />
2121
<Button text="Show Modal Page With Frame" tap="onModalFrame" textAlignment="left" />
2222
<Button text="Show Modal Page" tap="onModalPage" textAlignment="left" />
23+
<Button text="Show 'popover' modal" tap="onPopoverModal" textAlignment="left" />
2324
<Button text="Show Modal Layout" tap="onModalLayout" textAlignment="left" />
2425
<Button text="Show Modal TabView" tap="onModalTabView" textAlignment="left" />
2526
<Button text="Android Back Btn Events" tap="onAndroidBackEvents" textAlignment="left" />

‎e2e/modal-navigation/app/modal-no-page/modal-no-page.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { NavigatedData, Page } from "tns-core-modules/ui/page";
33
import { View, EventData } from "tns-core-modules/ui/core/view";
44
import { Frame, ShownModallyData } from "tns-core-modules/ui/frame";
55
import { fromObject } from "tns-core-modules/data/observable";
6-
import { confirm } from "ui/dialogs";
6+
import { confirm } from "tns-core-modules/ui/dialogs";
77

88
export function onLoaded(args) {
99
console.log("modal-no-page loaded");

‎e2e/modal-navigation/app/modal/modal-page.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { NavigatedData, Page } from "tns-core-modules/ui/page";
33
import { View, EventData } from "tns-core-modules/ui/core/view";
44
import { Frame, ShownModallyData } from "tns-core-modules/ui/frame";
55
import { fromObject } from "tns-core-modules/data/observable";
6-
import { confirm } from "ui/dialogs";
6+
import { confirm } from "tns-core-modules/ui/dialogs";
77

88
export function onShowingModally(args: ShownModallyData) {
99
console.log("modal-page showingModally");

‎e2e/modal-navigation/package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"nativescript-dev-appium": "next",
2727
"nativescript-dev-typescript": "next",
2828
"nativescript-dev-webpack": "next",
29+
"tns-platform-declarations": "next",
2930
"rimraf": "^2.6.2",
3031
"typescript": "^3.1.6"
3132
},
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/// <reference path="./node_modules/tns-platform-declarations/ios.d.ts" />

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

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const majorVersion = iosUtils.MajorVersion;
2929
export class View extends ViewCommon {
3030
nativeViewProtected: UIView;
3131
viewController: UIViewController;
32+
private _popoverPresentationDelegate: ios.UIPopoverPresentationControllerDelegateImp;
3233

3334
private _isLaidOut = false;
3435
private _hasTransfrom = false;
@@ -416,6 +417,8 @@ export class View extends ViewCommon {
416417

417418
if (presentationStyle === UIModalPresentationStyle.Popover) {
418419
const popoverPresentationController = controller.popoverPresentationController;
420+
this._popoverPresentationDelegate = ios.UIPopoverPresentationControllerDelegateImp.initWithOwner(new WeakRef(this), options.closeCallback);
421+
popoverPresentationController.delegate = this._popoverPresentationDelegate;
419422
const view = parent.nativeViewProtected;
420423
// Note: sourceView and sourceRect are needed to specify the anchor location for the popover.
421424
// Note: sourceView should be the button triggering the modal. If it the Page the popover might appear "behind" the page content
@@ -906,7 +909,7 @@ export namespace ios {
906909

907910
public viewDidLoad(): void {
908911
super.viewDidLoad();
909-
912+
910913
// Unify translucent and opaque bars layout
911914
// this.edgesForExtendedLayout = UIRectEdgeBottom;
912915
this.extendedLayoutIncludesOpaqueBars = true;
@@ -982,4 +985,28 @@ export namespace ios {
982985
}
983986
}
984987
}
988+
989+
export class UIPopoverPresentationControllerDelegateImp extends NSObject implements UIPopoverPresentationControllerDelegate {
990+
public static ObjCProtocols = [UIPopoverPresentationControllerDelegate];
991+
992+
private owner: WeakRef<View>;
993+
private whenClosedCallback: Function;
994+
995+
public static initWithOwner(owner: WeakRef<View>, whenClosedCallback: Function): UIPopoverPresentationControllerDelegateImp {
996+
const instance = <UIPopoverPresentationControllerDelegateImp>super.new();
997+
instance.owner = owner;
998+
instance.whenClosedCallback = whenClosedCallback;
999+
1000+
return instance;
1001+
}
1002+
1003+
public popoverPresentationControllerDidDismissPopover(popoverPresentationController: UIPopoverPresentationController) {
1004+
const owner = this.owner.get();
1005+
if (owner) {
1006+
if (typeof this.whenClosedCallback === "function") {
1007+
this.whenClosedCallback();
1008+
}
1009+
}
1010+
}
1011+
}
9851012
}

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL