Skip to content

Commit c0bfcfb

Browse files
committed
remove animated support from controller, fix up goo example
1 parent 4e99010 commit c0bfcfb

File tree

11 files changed

+106
-174
lines changed

11 files changed

+106
-174
lines changed

examples/components/examples.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export default [
6060
tags: ['keyframes']
6161
},
6262
{
63-
name: 'spring',
63+
name: 'simple-spring',
6464
title: 'Simple spring',
6565
link: '#',
6666
tags: ['springs']

examples/demos/hooks/goo/index.js

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useRef } from 'react'
2-
import { useSpring, animated as anim } from 'react-spring/hooks'
2+
import { useSpring, useTrail, animated as anim } from 'react-spring/hooks'
33
import './styles.css'
44

55
const fast = { tension: 1200, friction: 40 }
@@ -8,24 +8,18 @@ const trans = (x, y) => `translate3d(${x}px,${y}px,0) translate3d(-50%,-50%,0)`
88

99
export default function Goo() {
1010
const ref = useRef(null)
11-
// Here we form a natural trail, one spring following another.
12-
// You can either update springs by overwriting values when you re-render the component.
13-
// Or you can use the set function, which allows you to bypass React alltogether.
14-
// We're dealing with mouse-input here so we choose the latter in order to prevent rendering.
15-
const [{ pos1 }, set] = useSpring(() => ({ pos1: [0, 0], config: fast }))
16-
const [{ pos2 }] = useSpring(() => ({ pos2: pos1, config: slow }))
17-
const [{ pos3 }] = useSpring(() => ({ pos3: pos2, config: slow }))
11+
const [trail, set] = useTrail(3, () => ({
12+
xy: [0, 0],
13+
config: i => (i === 0 ? fast : slow),
14+
}))
1815

19-
// We render the view like always, but we're using animated.el whereever
20-
// animated values are being used. Just like with regular "native" springs this
21-
// makes elements transient.
2216
return (
2317
<div
2418
ref={ref}
2519
className="goo-main"
2620
onMouseMove={e => {
2721
const rect = ref.current.getBoundingClientRect()
28-
set({ pos1: [e.clientX - rect.left, e.clientY - rect.top] })
22+
set({ xy: [e.clientX - rect.left, e.clientY - rect.top] })
2923
}}>
3024
<svg style={{ position: 'absolute', width: 0, height: 0 }}>
3125
<filter id="goo">
@@ -38,18 +32,12 @@ export default function Goo() {
3832
</svg>
3933
<div className="hooks-main">
4034
<div className="hooks-filter">
41-
<anim.div
42-
className="b1"
43-
style={{ transform: pos3.interpolate(trans) }}
44-
/>
45-
<anim.div
46-
className="b2"
47-
style={{ transform: pos2.interpolate(trans) }}
48-
/>
49-
<anim.div
50-
className="b3"
51-
style={{ transform: pos1.interpolate(trans) }}
52-
/>
35+
{trail.map((props, index) => (
36+
<anim.div
37+
key={index}
38+
style={{ transform: props.xy.interpolate(trans) }}
39+
/>
40+
))}
5341
</div>
5442
</div>
5543
</div>

examples/demos/hooks/goo/styles.css

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,49 +17,49 @@
1717
display: none;
1818
}
1919

20-
.b1, .b2, .b3 {
20+
.hooks-filter > div {
2121
position: absolute;
2222
will-change: transform;
2323
border-radius: 50%;
2424
background: lightcoral;
25-
box-shadow: 10px 10px 5px 0px rgba(0,0,0,0.75);
25+
box-shadow: 10px 10px 5px 0px rgba(0, 0, 0, 0.75);
2626
opacity: 0.6;
2727
}
2828

29-
.b1 {
29+
.hooks-filter > div:nth-child(1) {
3030
width: 120px;
3131
height: 120px;
3232
}
3333

34-
.b2 {
34+
.hooks-filter > div:nth-child(2) {
3535
width: 250px;
3636
height: 250px;
3737
}
3838

39-
.b3 {
39+
.hooks-filter > div:nth-child(3) {
4040
width: 150px;
4141
height: 150px;
4242
}
4343

44-
.b1::after, .b2::after, .b3::after {
44+
.hooks-filter > div::after {
4545
content: '';
4646
position: absolute;
4747
top: 20px;
4848
left: 20px;
4949
width: 40px;
5050
height: 40px;
5151
border-radius: 50%;
52-
background: rgba(255,255,255,0.8);
52+
background: rgba(255, 255, 255, 0.8);
5353
}
5454

55-
.b2::after {
55+
.hooks-filter > div:nth-child(2)::after {
5656
top: 70px;
5757
left: 70px;
5858
width: 70px;
5959
height: 70px;
6060
}
6161

62-
.b3::after {
62+
.hooks-filter > div:nth-child(3)::after {
6363
top: 50px;
6464
left: 50px;
6565
width: 50px;
@@ -72,4 +72,4 @@
7272
height: 100%;
7373
filter: url('#goo');
7474
overflow: hidden;
75-
}
75+
}
File renamed without changes.

examples/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import examples from './components/examples-hooks'
66
import './styles.css'
77

88
const DEBUG = false
9-
//const DEBUG = "flag"
9+
//const DEBUG = "simple"
1010

1111
ReactDOM.render(
1212
<DemoGrid>

src/animated/AnimatedArray.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@ export default class AnimatedArray extends AnimatedArrayWithChildren {
1111
: array.map(n => new AnimatedValue(n))
1212
}
1313

14-
setValue = values =>
15-
values.length === this.payload.length &&
16-
values.forEach((v, i) => this.payload[i].setValue(v))
14+
setValue = value => {
15+
//if (Array.isArray(value)) {
16+
if (value.length === this.payload.length)
17+
value.forEach((v, i) => this.payload[i].setValue(v))
18+
//} else this.payload.forEach((v, i) => this.payload[i].setValue(value))
19+
}
1720
getValue = () => this.payload.map(v => v.getValue())
1821
interpolate = (config, arg) => new AnimatedInterpolation(this, config, arg)
1922
}

src/animated/AnimatedValue.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export default class AnimatedValue extends AnimatedWithChildren {
6767
}
6868
}
6969

70+
setValue = value => this.value = value
7071
getValue = () => this.value
7172
updateStyles = () => findAnimatedStyles(this, this.animatedStyles)
7273
updateValue = value => this.flush((this.value = value))

0 commit comments

Comments
 (0)