From b58b36bf3cc2b0e4b60c2d7eba287b1bf5b4d8fc Mon Sep 17 00:00:00 2001 From: rigor789 Date: Sat, 21 Mar 2020 14:25:48 +0100 Subject: [PATCH 1/3] fix: defaultPath per navigator instance --- components/Navigator.js | 3 ++- index.js | 32 ++++++++++++++++++++++---------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/components/Navigator.js b/components/Navigator.js index b186b66..1c0ea74 100644 --- a/components/Navigator.js +++ b/components/Navigator.js @@ -29,7 +29,8 @@ export default { }, created() { this.defaultRouteComponent = this.$navigator._resolveComponent( - this.$props.defaultRoute + this.$props.defaultRoute, + this.$props.id ) }, methods: { diff --git a/index.js b/index.js index 529aa0c..df75220 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,12 @@ import Navigator from './components/Navigator' export default function install(Vue, {routes}) { + let appRoot; + const start = Vue.prototype.$start + Vue.prototype.$start = function () { + appRoot = this + start.call(this) + } Vue.component('Navigator', Navigator) Object.keys(routes).map(path => { @@ -20,24 +26,29 @@ export default function install(Vue, {routes}) { data: { path: false, paths: {}, - defaultPath: '/' + defaultPaths: {}, }, computed: { route() { - return routes[this.path || this.defaultPath] + return this.routes('navigator') + }, + routes() { + return id => routes[this.paths[id] || this.defaultPaths[id]] }, }, methods: { - _resolveComponent(defaultPath) { - if(defaultPath) this.defaultPath = defaultPath + _resolveComponent(defaultPath, id) { + if (defaultPath) { + this.$set(this.defaultPaths, id, defaultPath) + } - if (this.route) { - return this.route.component + if (this.routes(id)) { + return this.routes(id).component } return false }, _updatePath(path, id = 'navigator') { - if(id === 'navigator') { + if (id === 'navigator') { this.path = path } this.$set(this.paths, id, path) @@ -48,17 +59,18 @@ export default function install(Vue, {routes}) { if (!matchedRoute) { if (TNS_ENV === 'development') { - throw new Error(`Navigating to a route that does not exist: ${to}`) + throw new Error(`[Navigator] Navigating to a route that does not exist: ${to}`) } return false } - options = Object.assign({ frame: 'navigator' }, options) + options = Object.assign({frame: 'navigator'}, options) return this.$navigateTo(matchedRoute.component, options) + .catch(err => console.log(`[Navigator] Failed to navigate: ${err}`)) }, back(options, ...args) { - options = Object.assign({ frame: 'navigator' }, options) + options = Object.assign({frame: 'navigator'}, options) return this.$navigateBack.call(this, options, ...args) } }, From 3eb77c581bee850d0c3ed2845bd1eca0c18ea0c3 Mon Sep 17 00:00:00 2001 From: rigor789 Date: Sat, 21 Mar 2020 14:26:04 +0100 Subject: [PATCH 2/3] feat: allow opening a navigator modal --- index.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/index.js b/index.js index df75220..70a974c 100644 --- a/index.js +++ b/index.js @@ -72,6 +72,16 @@ export default function install(Vue, {routes}) { back(options, ...args) { options = Object.assign({frame: 'navigator'}, options) return this.$navigateBack.call(this, options, ...args) + }, + modal(to, options) { + return appRoot.$showModal({ + render: h => h(Navigator, { + props: { + id: options.id || 'navigatorModal', + defaultRoute: to + } + }) + }, options).catch(err => console.log(`[Navigator] Failed to show modal: ${err}`)) } }, }) From b19adc2d73aaebdcbfc0e8e927b8e59c4b2c4eca Mon Sep 17 00:00:00 2001 From: rigor789 Date: Sat, 21 Mar 2020 14:33:32 +0100 Subject: [PATCH 3/3] docs: document navigator modals --- README.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/README.md b/README.md index 98191c7..ae135a1 100644 --- a/README.md +++ b/README.md @@ -143,3 +143,24 @@ It is possible to use multiple `` elements by providing each new Navi } ``` + +# Navigator Modals + +```ts +type ModalOptions = { id: string } & ShowModalOptions +this.$navigator.modal(path: string, options: ModalOptions); +``` + +The default id for modal navigators is `modalNavigator` but can be changed by passing an `id` inside the ModalOptions. + +```js +// use the default id for the modal +this.$navigator.modal('/path', { fullscreen: true }) +// to navigate the modal to '/other' +this.$navigator.navigate('/other', { frame: 'modalNavigator' }) + +// use a different id for the modal +this.$navigator.modal('/path', { fullscreen: true, id: 'myModal' }) +// to navigate the myModal modal to '/other' +this.$navigator.navigate('/other', { frame: 'myModal' }) +```