Skip to content

Commit 799e42f

Browse files
committed
fix(transition): use the correct transition when navigating
resolve transitions from the options passed to $navigateTo, or if none specified fall back to props on the Frame or if there are no props, use default / don't specify a transition fix nativescript-vue#342
1 parent f95140b commit 799e42f

File tree

1 file changed

+27
-46
lines changed
  • platform/nativescript/runtime/components

1 file changed

+27
-46
lines changed

platform/nativescript/runtime/components/frame.js

Lines changed: 27 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,28 @@
11
import { setFrame, getFrame, deleteFrame } from '../../util/frame'
22
import { extend } from 'shared/util'
3+
import { isAndroid } from 'tns-core-modules/platform'
34

45
let idCounter = 1
56

6-
const propMap = {
7-
transition: 'transition',
8-
'ios:transition': 'transitioniOS',
9-
'android:transition': 'transitionAndroid'
10-
}
11-
127
export default {
138
props: {
149
id: {
1510
default: 'default'
1611
},
1712
transition: {
1813
type: [String, Object],
19-
default: _ => ({ name: 'slide', duration: 200 })
14+
required: false,
15+
default: null
2016
},
2117
'ios:transition': {
2218
type: [String, Object],
23-
default: ''
19+
required: false,
20+
default: null
2421
},
2522
'android:transition': {
2623
type: [String, Object],
27-
default: ''
24+
required: false,
25+
default: null
2826
},
2927
// injected by the template compiler
3028
hasRouterView: {
@@ -60,49 +58,33 @@ export default {
6058
this.$slots.default
6159
)
6260
},
63-
// computed: {
64-
// history() {
65-
// return (this.$router && this.$router.history) || {}
66-
// },
67-
//
68-
// store() {
69-
// return this.history.store || {}
70-
// },
71-
//
72-
// replacing() {
73-
// return this.store.operation === 'replace'
74-
// },
75-
//
76-
// isGoingBack() {
77-
// return this.store && this.store.isGoingBack
78-
// ? ios
79-
// ? undefined
80-
// : true
81-
// : false
82-
// }
83-
// },
8461
methods: {
8562
_getFrame() {
8663
return this.$el.nativeView
8764
},
8865

89-
_composeTransition() {
90-
const result = {}
91-
92-
for (const prop in propMap) {
93-
if (this[prop]) {
94-
const name = propMap[prop]
95-
result[name] = {}
66+
_ensureTransitionObject(transition) {
67+
if (typeof transition === 'string') {
68+
return { name: transition }
69+
}
70+
return transition
71+
},
9672

97-
if (typeof this[prop] === 'string') {
98-
result[name].name = this[prop]
99-
} else {
100-
extend(result[name], this[prop])
101-
}
102-
}
73+
_composeTransition(entry) {
74+
const platformEntryProp = `transition${isAndroid ? 'Android' : 'iOS'}`
75+
const entryProp = entry[platformEntryProp]
76+
? platformEntryProp
77+
: 'transition'
78+
const platformProp = `${isAndroid ? 'android' : 'ios'}:transition`
79+
const prop = this[platformProp] ? platformProp : 'transition'
80+
81+
if (entry[entryProp]) {
82+
entry[entryProp] = this._ensureTransitionObject(entry[entryProp])
83+
} else if (this[prop]) {
84+
entry[entryProp] = this._ensureTransitionObject(this[prop])
10385
}
10486

105-
return result
87+
return entry
10688
},
10789

10890
notifyPageMounted(pageVm) {
@@ -138,8 +120,7 @@ export default {
138120

139121
entry.create = () => page
140122

141-
Object.assign(entry, this._composeTransition())
142-
123+
this._composeTransition(entry)
143124
frame.navigate(entry)
144125
},
145126

0 commit comments

Comments
 (0)