Skip to content

Commit b4d9baa

Browse files
committed
fix: notification-hub demo
So it works with: pmndrs/react-spring#615
1 parent 2759448 commit b4d9baa

File tree

1 file changed

+28
-17
lines changed

1 file changed

+28
-17
lines changed

demos/hooks/notification-hub/index.js

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { X } from 'react-feather'
44
import { useTransition } from 'react-spring'
55
import { Main, Container, Message, Button, Content, Life } from './styles.js'
66

7+
const DEBUG = false
8+
79
let id = 0
810

911
function MessageHub({
@@ -17,24 +19,30 @@ function MessageHub({
1719

1820
const transitions = useTransition(items, item => item.key, {
1921
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)()
3138
},
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)
3545
},
36-
config: (item, state) =>
37-
state === 'leave' ? [{ duration: timeout }, config, config] : config,
3846
})
3947

4048
useEffect(
@@ -53,7 +61,10 @@ function MessageHub({
5361
<Button
5462
onClick={e => {
5563
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+
}
5768
}}>
5869
<X size={18} />
5970
</Button>

0 commit comments

Comments
 (0)