Skip to content
Permalink
Newer
Older
100644 127 lines (118 sloc) 3.54 KB
Aug 29, 2018
1
import React from 'react'
2
import anime from 'animejs'
3
import animationTimings from './common/animationTimings'
4
import Transition from 'react-transition-group/Transition'
5
import TransitionGroup from 'react-transition-group/TransitionGroup'
6
7
// we will trigger an event on the actual grid node after the exit animation completes
8
// to let the transitiongroup know that it can be removed from the DOM
May 3, 2018
9
// this is the only way to let react-transition-group delegate timing
Aug 29, 2018
10
// to the JavaScript animation, as far as I can tell
11
const ANIMATION_DONE_EVENT = 'animation::done'
12
const triggerAnimationDoneEvent = node =>
13
node . dispatchEvent ( new Event ( ANIMATION_DONE_EVENT ) )
14
15
// cache current animation so that it can be interrupted if necessary
16
let currentAnimation = null
17
const clearCurrentAnimation = ( ) => currentAnimation && currentAnimation . pause ( )
18
May 5, 2018
19
const getOpacity = animatingIn => ( {
20
value : animatingIn ? [ , 1 ] : [ 1 , ] ,
Aug 29, 2018
21
easing : 'linear' ,
May 6, 2018
22
duration : 300
May 5, 2018
23
} )
24
Aug 29, 2018
25
const animateGridIn = gridContainer => {
26
clearCurrentAnimation ( )
Aug 29, 2018
27
const cards = gridContainer . querySelectorAll ( '.card' )
28
currentAnimation = anime
29
. timeline ( )
30
. add ( {
31
targets : cards ,
32
opacity : ,
33
duration : 1
34
} )
35
. add ( {
36
targets : gridContainer ,
37
translateX : [ - 1000 , ] ,
May 5, 2018
38
opacity : getOpacity ( true ) ,
39
duration : animationTimings . gridEnter
40
} )
41
. add ( {
42
targets : cards ,
43
duration : 800 ,
May 5, 2018
44
opacity : getOpacity ( true ) ,
45
translateY : [ - 30 , ] ,
46
complete : ( ) => triggerAnimationDoneEvent ( gridContainer ) ,
Aug 29, 2018
47
delay : ( el , i ) => i * 100
48
} )
49
}
50
Aug 29, 2018
51
const animateGridOut = gridContainer => {
52
clearCurrentAnimation ( )
Aug 29, 2018
53
const cards = gridContainer . querySelectorAll ( '.card' )
54
gridContainer . style . height = gridContainer . offsetHeight + 'px'
55
currentAnimation = anime
56
. timeline ( )
57
. add ( {
58
targets : cards ,
59
duration : 700 ,
May 5, 2018
60
opacity : getOpacity ( false ) ,
61
translateY : - 30 ,
62
delay : ( el , i ) => i * 100
63
} )
64
. add ( {
65
targets : gridContainer ,
66
translateX : 1000 ,
May 5, 2018
67
opacity : getOpacity ( false ) ,
68
duration : animationTimings . gridLeave ,
69
complete : ( ) => triggerAnimationDoneEvent ( gridContainer ) ,
Aug 29, 2018
70
offset : '-=300'
71
} )
72
}
73
74
const animateCardIn = card =>
75
anime ( {
76
targets : card ,
May 5, 2018
77
opacity : getOpacity ( true ) ,
78
translateY : [ 50 , ] ,
79
complete : ( ) => triggerAnimationDoneEvent ( card ) ,
80
duration : animationTimings . cardEnter
81
} )
82
83
const animateCardOut = card =>
84
anime ( {
85
targets : card ,
86
translateY : - 10 ,
May 5, 2018
87
opacity : getOpacity ( false ) ,
88
complete : ( ) => triggerAnimationDoneEvent ( card ) ,
89
duration : animationTimings . cardLeave
90
} )
91
92
const TransitionGrid = props => {
93
return (
94
< Transition
95
unmountOnExit
96
appear
Aug 29, 2018
97
addEndListener = { ( node , done ) =>
98
node . addEventListener ( ANIMATION_DONE_EVENT , done )
99
}
100
onEnter = { animateGridIn }
101
onExit = { animateGridOut }
May 3, 2018
102
in = { props . visible }
103
>
104
< ul className = "grid animated-grid" >
105
< TransitionGroup component = { null } >
Aug 29, 2018
106
{ props . items . map ( item => (
107
< Transition
108
key = { item }
109
onEnter = { animateCardIn }
110
onExit = { animateCardOut }
Aug 29, 2018
111
addEndListener = { ( node , done ) =>
May 5, 2018
112
node . addEventListener ( ANIMATION_DONE_EVENT , done )
Aug 29, 2018
113
}
114
>
115
< li className = "card" onClick = { ( ) => props . removeItem ( item ) } >
116
< div className = "close-card" > < / div >
Aug 29, 2018
117
< div > { item } < / div >
118
< / li >
119
< / Transition >
120
) ) }
121
< / TransitionGroup >
122
< / ul >
123
< / Transition >
124
)
125
}
126
127
export default TransitionGrid

友情链: IM·体育网上直播_IM·体育赛事最新版_im体育官网在线官网在线 | im体育app平台下载|IM体育v2.3 安卓版|IM体育今天官网赛表 | im体育推荐官网_im体育今晚高清_im体育买软件 | 2022im体育网网址_分析观看比赛_2022im体育在线软件 | IM体育开户网址-Im体育官方网站-IM体育期胜负彩专家分析 | im电竞体育登录入口_IM·体育比分分析在线_IM·体育v8.5 IOS版 | im体育app官网下载|IM体育最新今天观看|IM体育赛事注册 |