| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,15 @@ | |||
| 1 | + import { View, ShowModalOptions } from "tns-core-modules/ui/core/view"; | ||
| 2 | + const LIVESYNC_FOLDER = "livesync/"; | ||
| 3 | + const buttonPageModuleName = `${LIVESYNC_FOLDER}livesync-button-page`; | ||
| 4 | + | ||
| 5 | + export function onLoaded(args) { | ||
| 6 | + const view = args.object as View; | ||
| 7 | + | ||
| 8 | + let options: ShowModalOptions = { | ||
| 9 | + context: "context", | ||
| 10 | + closeCallback: () => console.log("modal view closeCallback raised."), | ||
| 11 | + animated: false | ||
| 12 | + }; | ||
| 13 | + | ||
| 14 | + view.showModal(buttonPageModuleName, options); | ||
| 15 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,3 @@ | |||
| 1 | + <Page loaded="onLoaded"> | ||
| 2 | + | ||
| 3 | + </Page> | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -30,6 +30,13 @@ const buttonTsPageFileName = `${LIVESYNC_FOLDER}livesync-button-page.ts`; | |||
| 30 | 30 | const buttonScssPageFileName = `${LIVESYNC_FOLDER}livesync-button-page.scss`; | |
| 31 | 31 | const labelPageModuleName = `${LIVESYNC_FOLDER}livesync-label-page`; | |
| 32 | 32 | ||
| 33 | + const modalViewPageModuleName = `${LIVESYNC_FOLDER}livesync-modal-view-page`; | ||
| 34 | + const modalViewXmlPageFileName = `${LIVESYNC_FOLDER}livesync-modal-view-page.xml`; | ||
| 35 | + const modalViewJsPageFileName = `${LIVESYNC_FOLDER}livesync-modal-view-page.js`; | ||
| 36 | + const modalViewTsPageFileName = `${LIVESYNC_FOLDER}livesync-modal-view-page.ts`; | ||
| 37 | + const modalViewScssPageFileName = `${LIVESYNC_FOLDER}livesync-modal-view-page.scss`; | ||
| 38 | + const modalViewCssFileName = `${LIVESYNC_FOLDER}livesync-modal-view-page.css`; | ||
| 39 | + | ||
| 33 | 40 | const green = new Color("green"); | |
| 34 | 41 | ||
| 35 | 42 | export function setUp() { | |
@@ -111,6 +118,26 @@ export function test_onLiveSync_ModuleContext_MarkupHtml_ScriptTs_StyleScss_File | |||
| 111 | 118 | ]); | |
| 112 | 119 | } | |
| 113 | 120 | ||
| 121 | + export function test_onLiveSync_ModalViewClosed_MarkupXml() { | ||
| 122 | + _test_onLiveSync_ModalViewClosed({ type: "markup", path: modalViewXmlPageFileName }); | ||
| 123 | + } | ||
| 124 | + | ||
| 125 | + export function test_onLiveSync_ModalViewClosed_ScriptTs() { | ||
| 126 | + _test_onLiveSync_ModalViewClosed({ type: "script", path: modalViewTsPageFileName }); | ||
| 127 | + } | ||
| 128 | + | ||
| 129 | + export function test_onLiveSync_ModalViewClosed_ScriptJs() { | ||
| 130 | + _test_onLiveSync_ModalViewClosed({ type: "script", path: modalViewJsPageFileName }); | ||
| 131 | + } | ||
| 132 | + | ||
| 133 | + export function test_onLiveSync_ModalViewClosed_StyleCss() { | ||
| 134 | + _test_onLiveSync_ModalViewClosed({ type: "style", path: modalViewCssFileName }); | ||
| 135 | + } | ||
| 136 | + | ||
| 137 | + export function test_onLiveSync_ModalViewClosed_StyleScss() { | ||
| 138 | + _test_onLiveSync_ModalViewClosed({ type: "style", path: modalViewScssPageFileName }); | ||
| 139 | + } | ||
| 140 | + | ||
| 114 | 141 | function _test_onLiveSync_ModuleContext_AppStyle(appStyleFileName: string, livesyncStyleFileName: string) { | |
| 115 | 142 | const pageBeforeNavigation = helper.getCurrentPage(); | |
| 116 | 143 | const buttonPage = <Page>createViewFromEntry(({ moduleName: buttonPageModuleName })); | |
@@ -209,6 +236,18 @@ function _test_onLiveSync_ModuleReplace_Multiple(context: ModuleContext[]) { | |||
| 209 | 236 | TKUnit.assertEqual(pageBeforeNavigation, pageAfterBackNavigation, "Pages are different!"); | |
| 210 | 237 | } | |
| 211 | 238 | ||
| 239 | + function _test_onLiveSync_ModalViewClosed(context: ModuleContext) { | ||
| 240 | + const modalViewPage = <Page>createViewFromEntry(({ moduleName: modalViewPageModuleName })); | ||
| 241 | + helper.navigateWithHistory(() => modalViewPage); | ||
| 242 | + livesync({ type: context.type, path: context.path }); | ||
| 243 | + | ||
| 244 | + TKUnit.waitUntilReady(() => !!frame.topmost()); | ||
| 245 | + const topmostFrame = frame.topmost(); | ||
| 246 | + TKUnit.waitUntilReady(() => topmostFrame.currentPage && topmostFrame.currentPage.isLoaded && topmostFrame.canGoBack()); | ||
| 247 | + | ||
| 248 | + TKUnit.assertTrue(topmostFrame._getRootModalViews().length === 0); | ||
| 249 | + } | ||
| 250 | + | ||
| 212 | 251 | function livesync(context: ModuleContext) { | |
| 213 | 252 | const ls = (<any>global).__hmrSyncBackup || global.__onLiveSync; | |
| 214 | 253 | ls(context); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -152,11 +152,31 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition { | |||
| 152 | 152 | } | |
| 153 | 153 | } | |
| 154 | 154 | ||
| 155 | + public _closeAllModalViewsInternal(): boolean { | ||
| 156 | + if (_rootModalViews && _rootModalViews.length > 0) { | ||
| 157 | + _rootModalViews.forEach(v => { | ||
| 158 | + v.closeModal(); | ||
| 159 | + }); | ||
| 160 | + | ||
| 161 | + return true; | ||
| 162 | + } | ||
| 163 | + | ||
| 164 | + return false; | ||
| 165 | + } | ||
| 166 | + | ||
| 167 | + public _getRootModalViews(): Array<ViewBase> { | ||
| 168 | + return _rootModalViews; | ||
| 169 | + } | ||
| 170 | + | ||
| 155 | 171 | public _onLivesync(context?: ModuleContext): boolean { | |
| 156 | 172 | if (traceEnabled()) { | |
| 157 | 173 | traceWrite(`${this}._onLivesync(${JSON.stringify(context)})`, traceCategories.Livesync); | |
| 158 | 174 | } | |
| 159 | 175 | ||
| 176 | + if (this._closeAllModalViewsInternal()) { | ||
| 177 | + return true; | ||
| 178 | + } | ||
| 179 | + | ||
| 160 | 180 | if (this._handleLivesync(context)) { | |
| 161 | 181 | return true; | |
| 162 | 182 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -610,6 +610,18 @@ export abstract class View extends ViewBase { | |||
| 610 | 610 | // Lifecycle events | |
| 611 | 611 | _getNativeViewsCount(): number; | |
| 612 | 612 | ||
| 613 | + /** | ||
| 614 | + * Internal method: | ||
| 615 | + * Closes all modal views. Should be used by plugins like `nativescript-angular` which implement their own `modal views` service. | ||
| 616 | + */ | ||
| 617 | + _closeAllModalViewsInternal(): boolean; | ||
| 618 | + | ||
| 619 | + /** | ||
| 620 | + * Internal method: | ||
| 621 | + * Gets all modal views of the current view. | ||
| 622 | + */ | ||
| 623 | + _getRootModalViews(): Array<ViewBase> | ||
| 624 | + | ||
| 613 | 625 | _eachLayoutView(callback: (View) => void): void; | |
| 614 | 626 | ||
| 615 | 627 | /** | |
| Back | FazBrowse Home | New Git URL |
0 commit comments