1
- //import { before } from '../util/index'
2
- //import { Page } from 'tns-core-modules/ui/page'
3
1
import { android } from 'tns-core-modules/application'
4
2
import { isPlainObject } from 'shared/util'
5
3
6
4
const properties = [ 'stack' , 'index' , 'current' ]
7
5
8
6
class NativeScriptHistory {
9
- constructor ( router , history , VueInstance ) {
7
+ constructor ( router , history ) {
10
8
this . router = router
11
9
this . history = history
12
10
this . isGoingBack = false
13
- this . _Vue = VueInstance
14
11
15
12
if ( android ) {
16
13
android . on ( 'activityBackPressed' , function ( args ) {
@@ -48,14 +45,14 @@ class NativeScriptHistory {
48
45
}
49
46
50
47
push ( ...args ) {
51
- ( { args, entry : this . currentEntry } = this . _buildEntry ( args ) )
48
+ ; ( { args, entry : this . currentEntry } = this . _buildEntry ( args ) )
52
49
53
50
this . isGoingBack = false
54
51
this . history . push . call ( this . history , ...args )
55
52
}
56
53
57
54
replace ( ...args ) {
58
- ( { args, entry : this . currentEntry } = this . _buildEntry ( args ) )
55
+ ; ( { args, entry : this . currentEntry } = this . _buildEntry ( args ) )
59
56
60
57
this . isGoingBack = false
61
58
this . history . replace . call ( this . history , ...args )
@@ -102,14 +99,14 @@ class NativeScriptHistory {
102
99
}
103
100
}
104
101
105
- export function patchDefaultRouter ( router , Vue ) {
102
+ export function patchDefaultRouter ( router ) {
106
103
if ( router . __patched_for_routing__ ) {
107
104
return
108
105
}
109
106
110
107
router . __patched_for_routing__ = true
111
108
112
- router . history = new NativeScriptHistory ( router , router . history , Vue )
109
+ router . history = new NativeScriptHistory ( router , router . history )
113
110
114
111
router . push = function push ( ...args ) {
115
112
this . history . push ( ...args )
@@ -132,104 +129,6 @@ export function patchDefaultRouter(router, Vue) {
132
129
}
133
130
}
134
131
135
- //export function patchRouter(router, Vue) {
136
- // if (router.__patched_for_page_routing__) {
137
- // return
138
- // }
139
- // router.__patched_for_page_routing__ = true
140
- //
141
- // // The problem: When using router.replace() to set the initial route
142
- // // the history index stays -1, which then causes an issue when visiting a route,
143
- // // going back, and then trying to visit again (the active route is not changed on nav back)
144
- // // This fixes it, since it allows the router.go logic to run
145
- // router.history.index = 0
146
- //
147
- // // initial navigation states
148
- // router.isBackNavigation = false
149
- // router.shouldNavigate = true
150
- // router.pageStack = []
151
- // router.pageTransition = null
152
- //
153
- // router.setPageTransition = (transition, duration, curve) => {
154
- // if (typeof transition === 'string') {
155
- // return (router.pageTransition = {
156
- // name: transition,
157
- // duration,
158
- // curve
159
- // })
160
- // }
161
- //
162
- // router.pageTransition = transition
163
- // }
164
- //
165
- // router._beginBackNavigation = (shouldNavigate = true) => {
166
- // if (router.isBackNavigation) {
167
- // throw new Error(
168
- // 'router._beginBackNavigation was called while already navigating back.'
169
- // )
170
- // }
171
- //
172
- // router.isBackNavigation = true
173
- // router.shouldNavigate = shouldNavigate
174
- // }
175
- //
176
- // router._finishBackNavigation = () => {
177
- // if (!router.isBackNavigation) {
178
- // throw new Error(
179
- // 'router._finishBackNavigation was called while there was no back navigation.'
180
- // )
181
- // }
182
- //
183
- // router.isBackNavigation = false
184
- // }
185
- //
186
- // router.go = before(router.go, router, n => {
187
- // if (n === -1 && !router.isBackNavigation) {
188
- // router._beginBackNavigation()
189
- // }
190
- // })
191
- //
192
- // router.afterEach(() => {
193
- // if (router.isBackNavigation) {
194
- // if (router.shouldNavigate) {
195
- // Vue.navigateBack()
196
- // }
197
- // router.pageStack.pop()
198
- // const page = router.pageStack[router.pageStack.length - 1]
199
- //
200
- // const callback = ({ isBackNavigation }) => {
201
- // if (isBackNavigation) {
202
- // router._finishBackNavigation()
203
- // }
204
- // page.off(Page.navigatedToEvent, callback)
205
- // }
206
- //
207
- // page.on(Page.navigatedToEvent, callback)
208
- //
209
- // return
210
- // }
211
- //
212
- // const component = router.getMatchedComponents()[0]
213
- //
214
- // router.app
215
- // .$navigateTo(component, {
216
- // context: { router },
217
- // transition: router.pageTransition
218
- // // Todo: add transitionAndroid and transitionIOS
219
- // })
220
- // .then(page => {
221
- // router.pageStack.push(page)
222
- //
223
- // page.on(Page.navigatedFromEvent, ({ isBackNavigation }) => {
224
- // if (isBackNavigation && !router.isBackNavigation) {
225
- // router._beginBackNavigation(false)
226
- // router.back()
227
- // }
228
- // })
229
- // })
230
- // })
231
- //}
232
-
233
132
export default {
234
133
install ( Vue ) {
235
134
Vue . mixin ( {
@@ -239,41 +138,7 @@ export default {
239
138
return
240
139
}
241
140
242
- const router = this . $options . router
243
- //const isPageRouting = router.options.pageRouting
244
- //const self = this
245
-
246
- //if (isPageRouting) {
247
- // patchRouter(router, Vue)
248
- //} else {
249
- patchDefaultRouter ( router , Vue )
250
-
251
- // return
252
- //}
253
- //
254
- //// Overwrite the default $start function
255
- //this.$start = () => {
256
- // this.__is_root__ = true
257
- // this.__started__ = true // skips the default start procedure
258
- // this.$options.render = () => {} // removes warning for no render / template
259
- //
260
- // // Mount the root component
261
- // const placeholder = Vue.$document.createComment('placeholder')
262
- // self.$mount(placeholder)
263
- //
264
- // const initial = router.getMatchedComponents()[0]
265
- //
266
- // this.$navigateTo(
267
- // initial,
268
- // {
269
- // context: { router },
270
- // clearHistory: true
271
- // },
272
- // page => {
273
- // router.pageStack.push(page)
274
- // }
275
- // )
276
- //}
141
+ patchDefaultRouter ( this . $options . router )
277
142
}
278
143
} )
279
144
}
0 commit comments