| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,7 +1,7 @@ | |||
| 1 | 1 | import * as application from "tns-core-modules/application"; | |
| 2 | 2 | import { StackLayout } from "tns-core-modules/ui/layouts/stack-layout"; | |
| 3 | 3 | 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"; | ||
| 5 | 5 | import { Frame } from "tns-core-modules/ui/frame"; | |
| 6 | 6 | ||
| 7 | 7 | export function onNavigatingTo(args: NavigatedData) { | |
@@ -29,6 +29,20 @@ export function onModalNoPage(args: EventData) { | |||
| 29 | 29 | false); | |
| 30 | 30 | } | |
| 31 | 31 | ||
| 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 | + | ||
| 32 | 46 | export function onModalFrame(args: EventData) { | |
| 33 | 47 | const view = args.object as View; | |
| 34 | 48 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -20,6 +20,7 @@ | |||
| 20 | 20 | <Button text="Show Modal Without Page" tap="onModalNoPage" textAlignment="left" /> | |
| 21 | 21 | <Button text="Show Modal Page With Frame" tap="onModalFrame" textAlignment="left" /> | |
| 22 | 22 | <Button text="Show Modal Page" tap="onModalPage" textAlignment="left" /> | |
| 23 | + <Button text="Show 'popover' modal" tap="onPopoverModal" textAlignment="left" /> | ||
| 23 | 24 | <Button text="Show Modal Layout" tap="onModalLayout" textAlignment="left" /> | |
| 24 | 25 | <Button text="Show Modal TabView" tap="onModalTabView" textAlignment="left" /> | |
| 25 | 26 | <Button text="Android Back Btn Events" tap="onAndroidBackEvents" textAlignment="left" /> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,7 +3,7 @@ import { NavigatedData, Page } from "tns-core-modules/ui/page"; | |||
| 3 | 3 | import { View, EventData } from "tns-core-modules/ui/core/view"; | |
| 4 | 4 | import { Frame, ShownModallyData } from "tns-core-modules/ui/frame"; | |
| 5 | 5 | import { fromObject } from "tns-core-modules/data/observable"; | |
| 6 | - import { confirm } from "ui/dialogs"; | ||
| 6 | + import { confirm } from "tns-core-modules/ui/dialogs"; | ||
| 7 | 7 | ||
| 8 | 8 | export function onLoaded(args) { | |
| 9 | 9 | console.log("modal-no-page loaded"); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,7 +3,7 @@ import { NavigatedData, Page } from "tns-core-modules/ui/page"; | |||
| 3 | 3 | import { View, EventData } from "tns-core-modules/ui/core/view"; | |
| 4 | 4 | import { Frame, ShownModallyData } from "tns-core-modules/ui/frame"; | |
| 5 | 5 | import { fromObject } from "tns-core-modules/data/observable"; | |
| 6 | - import { confirm } from "ui/dialogs"; | ||
| 6 | + import { confirm } from "tns-core-modules/ui/dialogs"; | ||
| 7 | 7 | ||
| 8 | 8 | export function onShowingModally(args: ShownModallyData) { | |
| 9 | 9 | console.log("modal-page showingModally"); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -25,6 +25,7 @@ | |||
| 25 | 25 | "nativescript-dev-appium": "next", | |
| 26 | 26 | "nativescript-dev-typescript": "next", | |
| 27 | 27 | "nativescript-dev-webpack": "next", | |
| 28 | + "tns-platform-declarations": "next", | ||
| 28 | 29 | "rimraf": "^2.6.2", | |
| 29 | 30 | "typescript": "^3.1.6" | |
| 30 | 31 | }, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1 @@ | |||
| 1 | + /// <reference path="./node_modules/tns-platform-declarations/ios.d.ts" /> | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -22,6 +22,7 @@ import { | |||
| 22 | 22 | } from "../../gestures"; | |
| 23 | 23 | ||
| 24 | 24 | import { createViewFromEntry } from "../../builder"; | |
| 25 | + import { isAndroid } from "../../../platform"; | ||
| 25 | 26 | import { StyleScope } from "../../styling/style-scope"; | |
| 26 | 27 | import { LinearGradient } from "../../styling/linear-gradient"; | |
| 27 | 28 | import { BackgroundRepeat } from "../../styling/style-properties"; | |
@@ -324,7 +325,11 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition { | |||
| 324 | 325 | } | |
| 325 | 326 | } | |
| 326 | 327 | ||
| 327 | - that._hideNativeModalView(parent, whenClosedCallback); | ||
| 328 | + if (isAndroid || (parent.viewController && parent.viewController.presentedViewController)) { | ||
| 329 | + that._hideNativeModalView(parent, whenClosedCallback); | ||
| 330 | + } else { | ||
| 331 | + whenClosedCallback(); | ||
| 332 | + } | ||
| 328 | 333 | } | |
| 329 | 334 | }; | |
| 330 | 335 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -29,6 +29,7 @@ const majorVersion = iosUtils.MajorVersion; | |||
| 29 | 29 | export class View extends ViewCommon { | |
| 30 | 30 | nativeViewProtected: UIView; | |
| 31 | 31 | viewController: UIViewController; | |
| 32 | + private _popoverPresentationDelegate: ios.UIPopoverPresentationControllerDelegateImp; | ||
| 32 | 33 | ||
| 33 | 34 | private _isLaidOut = false; | |
| 34 | 35 | private _hasTransfrom = false; | |
@@ -416,6 +417,8 @@ export class View extends ViewCommon { | |||
| 416 | 417 | ||
| 417 | 418 | if (presentationStyle === UIModalPresentationStyle.Popover) { | |
| 418 | 419 | const popoverPresentationController = controller.popoverPresentationController; | |
| 420 | + this._popoverPresentationDelegate = ios.UIPopoverPresentationControllerDelegateImp.initWithOwnerAndCallback(new WeakRef(this), this._closeModalCallback); | ||
| 421 | + popoverPresentationController.delegate = this._popoverPresentationDelegate; | ||
| 419 | 422 | const view = parent.nativeViewProtected; | |
| 420 | 423 | // Note: sourceView and sourceRect are needed to specify the anchor location for the popover. | |
| 421 | 424 | // 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 { | |||
| 906 | 909 | ||
| 907 | 910 | public viewDidLoad(): void { | |
| 908 | 911 | super.viewDidLoad(); | |
| 909 | - | ||
| 912 | + | ||
| 910 | 913 | // Unify translucent and opaque bars layout | |
| 911 | 914 | // this.edgesForExtendedLayout = UIRectEdgeBottom; | |
| 912 | 915 | this.extendedLayoutIncludesOpaqueBars = true; | |
@@ -982,4 +985,26 @@ export namespace ios { | |||
| 982 | 985 | } | |
| 983 | 986 | } | |
| 984 | 987 | } | |
| 988 | + | ||
| 989 | + export class UIPopoverPresentationControllerDelegateImp extends NSObject implements UIPopoverPresentationControllerDelegate { | ||
| 990 | + public static ObjCProtocols = [UIPopoverPresentationControllerDelegate]; | ||
| 991 | + | ||
| 992 | + private owner: WeakRef<View>; | ||
| 993 | + private closedCallback: Function; | ||
| 994 | + | ||
| 995 | + public static initWithOwnerAndCallback(owner: WeakRef<View>, whenClosedCallback: Function): UIPopoverPresentationControllerDelegateImp { | ||
| 996 | + const instance = <UIPopoverPresentationControllerDelegateImp>super.new(); | ||
| 997 | + instance.owner = owner; | ||
| 998 | + instance.closedCallback = whenClosedCallback; | ||
| 999 | + | ||
| 1000 | + return instance; | ||
| 1001 | + } | ||
| 1002 | + | ||
| 1003 | + public popoverPresentationControllerDidDismissPopover(popoverPresentationController: UIPopoverPresentationController) { | ||
| 1004 | + const owner = this.owner.get(); | ||
| 1005 | + if (owner && typeof this.closedCallback === "function") { | ||
| 1006 | + this.closedCallback(); | ||
| 1007 | + } | ||
| 1008 | + } | ||
| 1009 | + } | ||
| 985 | 1010 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments