| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,4 @@ | |||
| 1 | - // >> article-require-page-module | ||
| 1 | + // >> article-require-page-module | ||
| 2 | 2 | import { Page, ShownModallyData, NavigatedData } from "tns-core-modules/ui/page"; | |
| 3 | 3 | // FrameModule is needed in order to have an option to navigate to the new page. | |
| 4 | 4 | import { topmost, NavigationEntry } from "tns-core-modules/ui/frame"; | |
@@ -556,6 +556,66 @@ export function test_WhenViewBaseCallsShowModal_WithArguments_ShouldOpenModal() | |||
| 556 | 556 | TKUnit.waitUntilReady(() => modalClosed); | |
| 557 | 557 | } | |
| 558 | 558 | ||
| 559 | + export function test_WhenViewBaseCallsShowModal_WithShowModalOptionsArguments_ShouldOpenModal() { | ||
| 560 | + let modalClosed = false; | ||
| 561 | + | ||
| 562 | + const modalCloseCallback = function (returnValue: any) { | ||
| 563 | + modalClosed = true; | ||
| 564 | + } | ||
| 565 | + | ||
| 566 | + const createTabItems = function(count: number) { | ||
| 567 | + var items = new Array<TabViewItem>(); | ||
| 568 | + | ||
| 569 | + for (var i = 0; i < count; i++) { | ||
| 570 | + var label = new Label(); | ||
| 571 | + label.text = "Tab " + i; | ||
| 572 | + var tabEntry = new TabViewItem(); | ||
| 573 | + tabEntry.title = "Tab " + i; | ||
| 574 | + tabEntry.view = label; | ||
| 575 | + | ||
| 576 | + items.push(tabEntry); | ||
| 577 | + } | ||
| 578 | + | ||
| 579 | + return items; | ||
| 580 | + } | ||
| 581 | + | ||
| 582 | + const modalPageShownModallyEventHandler = function(args: ShownModallyData) { | ||
| 583 | + const page = <Page>args.object; | ||
| 584 | + page.off(View.shownModallyEvent, modalPageShownModallyEventHandler); | ||
| 585 | + args.closeCallback(); | ||
| 586 | + } | ||
| 587 | + | ||
| 588 | + const hostNavigatedToEventHandler = function(args) { | ||
| 589 | + const page = <Page>args.object; | ||
| 590 | + page.off(Page.navigatedToEvent, hostNavigatedToEventHandler); | ||
| 591 | + | ||
| 592 | + const modalPage = new Page(); | ||
| 593 | + modalPage.id = "modalPage_test_WhenViewBaseCallsShowModal_WithShowModalOptionsArguments_ShouldOpenModal"; | ||
| 594 | + modalPage.on(View.shownModallyEvent, modalPageShownModallyEventHandler); | ||
| 595 | + const tabViewItem = (<TabView>page.content).items[0]; | ||
| 596 | + tabViewItem.showModal(modalPage, {}, modalCloseCallback, { | ||
| 597 | + fullscreen: false, | ||
| 598 | + animated: false | ||
| 599 | + }); | ||
| 600 | + } | ||
| 601 | + | ||
| 602 | + const masterPageFactory = function(): Page { | ||
| 603 | + const masterPage = new Page(); | ||
| 604 | + masterPage.id = "masterPage_test_WhenViewBaseCallsShowModal_WithShowModalOptionsArguments_ShouldOpenModal"; | ||
| 605 | + masterPage.on(Page.navigatedToEvent, hostNavigatedToEventHandler) | ||
| 606 | + | ||
| 607 | + const tabView = new TabView(); | ||
| 608 | + tabView.items = createTabItems(2); | ||
| 609 | + masterPage.content = tabView; | ||
| 610 | + | ||
| 611 | + return masterPage; | ||
| 612 | + }; | ||
| 613 | + | ||
| 614 | + helper.navigate(masterPageFactory); | ||
| 615 | + | ||
| 616 | + TKUnit.waitUntilReady(() => modalClosed); | ||
| 617 | + } | ||
| 618 | + | ||
| 559 | 619 | export function test_WhenViewBaseCallsShowModal_WithoutArguments_ShouldThrow() { | |
| 560 | 620 | let navigatedTo = false; | |
| 561 | 621 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -46,6 +46,30 @@ export function isEventOrGesture(name: string, view: ViewBase): boolean; | |||
| 46 | 46 | */ | |
| 47 | 47 | export function getViewById(view: ViewBase, id: string): ViewBase; | |
| 48 | 48 | ||
| 49 | + export interface ShowModalOptions { | ||
| 50 | + /** | ||
| 51 | + * An optional parameter specifying whether to show the modal view in full-screen mode. | ||
| 52 | + */ | ||
| 53 | + fullscreen?: boolean; | ||
| 54 | + | ||
| 55 | + /** | ||
| 56 | + * An optional parameter specifying whether to show the modal view with animation. | ||
| 57 | + */ | ||
| 58 | + animated?: boolean; | ||
| 59 | + | ||
| 60 | + /** | ||
| 61 | + * An optional parameter specifying whether to stretch the modal view when not in full-screen mode. | ||
| 62 | + */ | ||
| 63 | + stretched?: boolean; | ||
| 64 | + | ||
| 65 | + /** | ||
| 66 | + * An optional parameter that specify options specific to iOS as an object. | ||
| 67 | + * Supported properties: | ||
| 68 | + * presentationStyle - any value from the UIModalPresentationStyle | ||
| 69 | + */ | ||
| 70 | + ios?: any; | ||
| 71 | + } | ||
| 72 | + | ||
| 49 | 73 | export abstract class ViewBase extends Observable { | |
| 50 | 74 | // Dynamic properties. | |
| 51 | 75 | left: Length; | |
@@ -121,7 +145,18 @@ export abstract class ViewBase extends Observable { | |||
| 121 | 145 | * @param stretched - An optional parameter specifying whether to stretch the modal view when not in full-screen mode. | |
| 122 | 146 | * @param iOSPresentationStyle - An optional, iOS only parameter specifying the way the modal view is covering the screen. | |
| 123 | 147 | */ | |
| 124 | - showModal(moduleName: string, context: any, closeCallback: Function, fullscreen?: boolean, animated?: boolean, stretched?: boolean, iOSPresentationStyle?: UIModalPresentationStyle): ViewBase; | ||
| 148 | + showModal(moduleName: string, context: any, closeCallback: Function, fullscreen?: boolean, animated?: boolean, stretched?: boolean): ViewBase; | ||
| 149 | + | ||
| 150 | + /** | ||
| 151 | + * Shows the View contained in moduleName as a modal view. | ||
| 152 | + * @param moduleName - The name of the module to load starting from the application root. | ||
| 153 | + * @param context - Any context you want to pass to the modally shown view. | ||
| 154 | + * This same context will be available in the arguments of the shownModally event handler. | ||
| 155 | + * @param closeCallback - A function that will be called when the view is closed. | ||
| 156 | + * Any arguments provided when calling ShownModallyData.closeCallback will be available here. | ||
| 157 | + * @param modalOptions - A ShowModalOptions instance | ||
| 158 | + */ | ||
| 159 | + showModal(moduleName: string, context: any, closeCallback: Function, modalOptions: ShowModalOptions): ViewBase; | ||
| 125 | 160 | ||
| 126 | 161 | /** | |
| 127 | 162 | * Shows the view passed as parameter as a modal view. | |
@@ -133,7 +168,16 @@ export abstract class ViewBase extends Observable { | |||
| 133 | 168 | * @param stretched - An optional parameter specifying whether to stretch the modal view when not in full-screen mode. | |
| 134 | 169 | * @param iOSPresentationStyle - An optional, iOS only parameter specifying the way the modal view is covering the screen. | |
| 135 | 170 | */ | |
| 136 | - showModal(view: ViewBase, context: any, closeCallback: Function, fullscreen?: boolean, animated?: boolean, stretched?: boolean, iOSPresentationStyle?: UIModalPresentationStyle): ViewBase; | ||
| 171 | + showModal(view: ViewBase, context: any, closeCallback: Function, fullscreen?: boolean, animated?: boolean, stretched?: boolean): ViewBase; | ||
| 172 | + | ||
| 173 | + /** | ||
| 174 | + * Shows the view passed as parameter as a modal view. | ||
| 175 | + * @param view - View instance to be shown modally. | ||
| 176 | + * @param context - Any context you want to pass to the modally shown view. This same context will be available in the arguments of the shownModally event handler. | ||
| 177 | + * @param closeCallback - A function that will be called when the view is closed. Any arguments provided when calling ShownModallyData.closeCallback will be available here. | ||
| 178 | + * @param modalOptions - A ShowModalOptions instance | ||
| 179 | + */ | ||
| 180 | + showModal(view: ViewBase, context: any, closeCallback: Function, modalOptions: ShowModalOptions): ViewBase; | ||
| 137 | 181 | ||
| 138 | 182 | /** | |
| 139 | 183 | * Deprecated. Showing view as modal is deprecated. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -215,23 +215,40 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition { | |||
| 215 | 215 | } | |
| 216 | 216 | ||
| 217 | 217 | public showModal(): ViewDefinition { | |
| 218 | - if (arguments.length === 0) { | ||
| 219 | - throw new Error("showModal without parameters is deprecated. Please call showModal on a view instance instead."); | ||
| 218 | + if (arguments.length === 0) { | ||
| 219 | + throw new Error("showModal without parameters is deprecated. Please call showModal on a view instance instead."); | ||
| 220 | + } else { | ||
| 221 | + var firstAgrument; | ||
| 222 | + var context: any; | ||
| 223 | + var closeCallback: Function; | ||
| 224 | + var fullscreen: boolean; | ||
| 225 | + var animated; | ||
| 226 | + var stretched; | ||
| 227 | + var iosOpts; | ||
| 228 | + | ||
| 229 | + if (arguments.length === 4) { | ||
| 230 | + firstAgrument = arguments[0]; | ||
| 231 | + context = arguments[1]; | ||
| 232 | + closeCallback = arguments[2]; | ||
| 233 | + fullscreen = arguments[3].fullscreen; | ||
| 234 | + animated = arguments[3].animated; | ||
| 235 | + stretched = arguments[3].stretched; | ||
| 236 | + iosOpts = arguments[3].ios; | ||
| 220 | 237 | } else { | |
| 221 | - const firstAgrument = arguments[0]; | ||
| 222 | - const context: any = arguments[1]; | ||
| 223 | - const closeCallback: Function = arguments[2]; | ||
| 224 | - const fullscreen: boolean = arguments[3]; | ||
| 225 | - const animated = arguments[4]; | ||
| 226 | - const stretched = arguments[5]; | ||
| 227 | - const presentationStyle = arguments[6]; | ||
| 228 | - | ||
| 229 | - const view: ViewDefinition = firstAgrument instanceof ViewCommon | ||
| 230 | - ? firstAgrument : createViewFromEntry({ moduleName: firstAgrument }); | ||
| 231 | - | ||
| 232 | - (<ViewCommon>view)._showNativeModalView(this, context, closeCallback, fullscreen, animated, stretched, presentationStyle); | ||
| 233 | - return view; | ||
| 238 | + firstAgrument = arguments[0]; | ||
| 239 | + context = arguments[1]; | ||
| 240 | + closeCallback = arguments[2]; | ||
| 241 | + fullscreen = arguments[3]; | ||
| 242 | + animated = arguments[4]; | ||
| 243 | + stretched = arguments[5]; | ||
| 234 | 244 | } | |
| 245 | + | ||
| 246 | + const view: ViewDefinition = firstAgrument instanceof ViewCommon | ||
| 247 | + ? firstAgrument : createViewFromEntry({ moduleName: firstAgrument }); | ||
| 248 | + | ||
| 249 | + (<ViewCommon>view)._showNativeModalView(this, context, closeCallback, fullscreen, animated, stretched, iosOpts); | ||
| 250 | + return view; | ||
| 251 | + } | ||
| 235 | 252 | } | |
| 236 | 253 | ||
| 237 | 254 | public closeModal(...args) { | |
@@ -250,7 +267,7 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition { | |||
| 250 | 267 | return this._modal; | |
| 251 | 268 | } | |
| 252 | 269 | ||
| 253 | - protected _showNativeModalView(parent: ViewCommon, context: any, closeCallback: Function, fullscreen?: boolean, animated?: boolean, stretched?: boolean, presentationStyle?: UIModalPresentationStyle) { | ||
| 270 | + protected _showNativeModalView(parent: ViewCommon, context: any, closeCallback: Function, fullscreen?: boolean, animated?: boolean, stretched?: boolean, iosOpts?: any) { | ||
| 254 | 271 | _rootModalViews.push(this); | |
| 255 | 272 | ||
| 256 | 273 | parent._modal = this; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -361,7 +361,7 @@ export class View extends ViewCommon { | |||
| 361 | 361 | return this._suspendCATransaction || this._suspendNativeUpdatesCount; | |
| 362 | 362 | } | |
| 363 | 363 | ||
| 364 | - protected _showNativeModalView(parent: View, context: any, closeCallback: Function, fullscreen?: boolean, animated?: boolean, stretched?: boolean, presentationStyle?: UIModalPresentationStyle) { | ||
| 364 | + protected _showNativeModalView(parent: View, context: any, closeCallback: Function, fullscreen?: boolean, animated?: boolean, stretched?: boolean, iosOpts?: any) { | ||
| 365 | 365 | const parentWithController = ios.getParentWithViewController(parent); | |
| 366 | 366 | if (!parentWithController) { | |
| 367 | 367 | traceWrite(`Could not find parent with viewController for ${parent} while showing modal view.`, | |
@@ -397,16 +397,17 @@ export class View extends ViewCommon { | |||
| 397 | 397 | controller.modalPresentationStyle = UIModalPresentationStyle.FormSheet; | |
| 398 | 398 | } | |
| 399 | 399 | ||
| 400 | - if (presentationStyle !== undefined) { | ||
| 401 | - controller.modalPresentationStyle = presentationStyle; | ||
| 400 | + if (iosOpts && iosOpts.presentationStyle) { | ||
| 401 | + controller.modalPresentationStyle = iosOpts.presentationStyle; | ||
| 402 | 402 | ||
| 403 | - if (presentationStyle === UIModalPresentationStyle.Popover) { | ||
| 404 | - // TODO: read the width and height of the page and apply it here ? | ||
| 403 | + if (iosOpts.presentationStyle === UIModalPresentationStyle.Popover) { | ||
| 404 | + // TODO: get the width and height of the page and apply it here ? | ||
| 405 | 405 | // controller.preferredContentSize = CGSizeMake(400, 400); | |
| 406 | 406 | const popoverPresentationController = controller.popoverPresentationController; | |
| 407 | 407 | ||
| 408 | 408 | const view = parent.nativeViewProtected; | |
| 409 | 409 | popoverPresentationController.sourceView = view; | |
| 410 | + // popoverPresentationController.backgroundColor = this.ios.view.backgroundColor; | ||
| 410 | 411 | popoverPresentationController.sourceRect = CGRectMake(0, 0, view.frame.size.width, view.frame.size.height); | |
| 411 | 412 | } | |
| 412 | 413 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments