8000 feat: improve v-show to support <transition> · tarunama/nativescript-vue@3e50a90 · GitHub
[go: up one dir, main page]

Skip to content 10000

Commit 3e50a90

Browse files
committed
feat: improve v-show to support <transition>
1 parent 35ec510 commit 3e50a90

File tree

1 file changed

+51
-6
lines changed
  • platform/nativescript/runtime/directives

1 file changed

+51
-6
lines changed
Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,57 @@
1-
function show(el, show) {
2-
el.setAttribute('visibility', show ? 'visible' : 'collapsed')
1+
import { enter, leave } from '../modules/transition'
2+
3+
// recursively search for possible transition defined inside the component root
4+
function locateNode(vnode) {
5+
return vnode.componentInstance && (!vnode.data || !vnode.data.transition)
6+
? locateNode(vnode.componentInstance._vnode)
7+
: vnode
38
}
49

510
export default {
6-
inserted(el, { value }) {
7-
show(el, value)
11+
bind(el, { value }, vnode) {
12+
vnode = locateNode(vnode)
13+
const transition = vnode.data && vnode.data.transition
14+
const originalVisibility = (el.__vOriginalVisibility =
15+
el.getAttribute('visibility') === 'none'
16+
? ''
17+
: el.getAttribute('visibility'))
18+
if (value && transition) {
19+
vnode.data.show = true
20+
enter(vnode, () => {
21+
el.setAttribute('visibility', originalVisibility)
22+
})
23+
} else {
24+
el.setAttribute('visibility', value ? originalVisibility : 'collapsed')
25+
}
26+
},
27+
28+
update(el, { value, oldValue }, vnode) {
29+
/* istanbul ignore if */
30+
if (!value === !oldValue) return
31+
vnode = locateNode(vnode)
32+
const transition = vnode.data && vnode.data.transition
33+
if (transition) {
34+
vnode.data.show = true
35+
if (value) {
36+
enter(vnode, () => {
37+
el.setAttribute('visibility', el.__vOriginalVisibility)
38+
})
39+
} else {
40+
leave(vnode, () => {
41+
el.setAttribute('visibility', 'collapsed')
42+
})
43+
}
44+
} else {
45+
el.setAttribute(
46+
'visibility',
47+
value ? el.__vOriginalVisibility : 'collapsed'
48+
)
49+
}
850
},
9-
update(el, { value }) {
10-
show(el, value)
51+
52+
unbind(el, binding, vnode, oldVnode, isDestroy) {
53+
if (!isDestroy) {
54+
el.setAttribute('visibility', el.__vOriginalVisibility)
55+
}
1156
}
1257
}

0 commit comments

Comments
 (0)
0