@@ -4,6 +4,8 @@ import { X } from 'react-feather'
4
4
import { useTransition } from 'react-spring'
5
5
import { Main , Container , Message , Button , Content , Life } from './styles.js'
6
6
7
+ const DEBUG = false
8
+
7
9
let id = 0
8
10
9
11
function MessageHub ( {
@@ -17,24 +19,30 @@ function MessageHub({
17
19
18
20
const transitions = useTransition ( items , item => item . key , {
19
21
from : { opacity : 0 , height : 0 , life : '100%' } ,
20
- enter : item => async next =>
21
- await next ( { opacity : 1 , height : refMap . get ( item ) . offsetHeight } ) ,
22
- leave : item => async ( next , cancel ) => {
23
- console . log ( ' one' )
24
- cancelMap . set ( item , cancel )
25
- await next ( { life : '0%' } )
26
- console . log ( ' two' )
27
- await next ( { opacity : 0 } )
28
- console . log ( ' three' )
29
- await next ( { height : 0 } )
30
- console . log ( ' done!' )
22
+ enter : item => async ( next , stop ) => {
23
+ cancelMap . set ( item , ( ) => {
24
+ stop ( )
25
+ setItems ( state => state . filter ( i => i . key !== item . key ) )
26
+ } )
27
+ if ( DEBUG ) console . log ( ` Entering:` , item . key )
28
+ await next ( {
29
+ opacity : 1 ,
30
+ height : refMap . get ( item ) . offsetHeight ,
31
+ config,
32
+ } )
33
+ if ( DEBUG )
34
+ console . log ( ` Animating "life" to zero over ${ timeout } ms:` , item . key )
35
+ await next ( { life : '0%' , config : { duration : timeout } } )
36
+ if ( DEBUG ) console . log ( ` End of sequence:` , item . key )
37
+ cancelMap . get ( item ) ( )
31
38
} ,
32
- onRest : item => {
33
- console . log ( 'onRest' , item )
34
- setItems ( state => state . filter ( i => i . key !== item . key ) )
39
+ leave : item => async next => {
40
+ if ( DEBUG ) console . log ( ` Animating "opacity" to zero:` , item . key )
41
+ await next ( { opacity : 0 , config } )
42
+ if ( DEBUG ) console . log ( ` Animating "height" to zero:` , item . key )
43
+ await next ( { height : 0 , config } )
44
+ if ( DEBUG ) console . log ( ` End of sequence:` , item . key )
35
45
} ,
36
- config : ( item , state ) =>
37
- state === 'leave' ? [ { duration : timeout } , config , config ] : config ,
38
46
} )
39
47
40
48
useEffect (
@@ -53,7 +61,10 @@ function MessageHub({
53
61
< Button
54
62
onClick = { e => {
55
63
e . stopPropagation ( )
56
- cancelMap . has ( item ) && cancelMap . get ( item ) ( )
64
+ if ( cancelMap . has ( item ) ) {
65
+ if ( DEBUG ) console . log ( ` Cancelled item:` , item )
66
+ cancelMap . get ( item ) ( )
67
+ }
57
68
} } >
58
69
< X size = { 18 } />
59
70
</ Button >
0 commit comments