Skip to content

Commit 9379722

Browse files
committed
attempting to fix pmndrs#110 and pmndrs#105
1 parent c3ffbab commit 9379722

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

rollup.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ function createConfig(entry, out, name) {
6565
}
6666

6767
export default [
68-
...createConfig('targets/web/index', 'web', 'ReactSpring'),
6968
...createConfig('addons/index', 'addons', 'ReactSpringAddons'),
69+
...createConfig('targets/web/index', 'web', 'ReactSpring'),
7070
...createConfig('targets/native/index', 'native'),
7171
...createConfig('targets/universal/index', 'universal'),
7272
...createConfig('targets/konva/index', 'konva'),

src/Keyframes.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Spring from './Spring'
44
import Trail from './Trail'
55
import Transition from './Transition'
66

7-
export default class Keyframes extends React.Component {
7+
export default class Keyframes extends React.PureComponent {
88
static propTypes = { script: PropTypes.func, state: PropTypes.string }
99

1010
guid = 0
@@ -26,10 +26,6 @@ export default class Keyframes extends React.Component {
2626
})
2727
}
2828

29-
shouldComponentUpdate(prevProps, prevState) {
30-
return prevProps.state !== this.props.state || prevState !== this.state
31-
}
32-
3329
componentDidUpdate(prevProps) {
3430
if (prevProps.state !== this.props.state) {
3531
const { states, state, primitive } = this.props

src/Spring.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ import AnimatedProps from './animated/AnimatedProps'
77
import SpringAnimation from './animated/SpringAnimation'
88
import * as Globals from './animated/Globals'
99

10+
function shallowDiff(a, b) {
11+
for (let i in a) if (!(i in b)) return true
12+
for (let i in b) if (a[i] !== b[i]) return true
13+
return false
14+
}
15+
1016
export const config = {
1117
default: { tension: 170, friction: 26 },
1218
gentle: { tension: 120, friction: 14 },
@@ -21,7 +27,7 @@ const convert = (acc, [name, value]) => ({
2127
[name]: new AnimatedValue(value),
2228
})
2329

24-
export default class Spring extends React.PureComponent {
30+
export default class Spring extends React.Component {
2531
static propTypes = {
2632
to: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
2733
from: PropTypes.object,
@@ -37,7 +43,6 @@ export default class Spring extends React.PureComponent {
3743
reset: PropTypes.bool,
3844
config: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
3945
immediate: PropTypes.oneOfType([PropTypes.bool, PropTypes.func]),
40-
hold: PropTypes.oneOfType([PropTypes.bool, PropTypes.func]),
4146
impl: PropTypes.func,
4247
inject: PropTypes.func,
4348
}
@@ -48,7 +53,6 @@ export default class Spring extends React.PureComponent {
4853
config: config.default,
4954
native: false,
5055
immediate: false,
51-
hold: false,
5256
reset: false,
5357
impl: SpringAnimation,
5458
inject: Globals.bugfixes,
@@ -65,8 +69,9 @@ export default class Spring extends React.PureComponent {
6569
this.updatePropsAsync(this.props)
6670
}
6771

68-
componentWillReceiveProps(props) {
69-
this.updatePropsAsync(props)
72+
componentWillUpdate(props) {
73+
if (props.reset || shallowDiff(props.to, this.props.to))
74+
this.updatePropsAsync(props)
7075
}
7176

7277
updatePropsAsync(props) {
@@ -90,7 +95,6 @@ export default class Spring extends React.PureComponent {
9095
config,
9196
attach,
9297
immediate,
93-
hold,
9498
reset,
9599
onFrame,
96100
onRest,
@@ -149,11 +153,12 @@ export default class Spring extends React.PureComponent {
149153
if (callProp(immediate, name)) entry.animation.setValue(toValue)
150154

151155
entry.stopped = false
156+
152157
entry.onFinish = cb => {
153158
this.animations[name].stopped = true
154159
if (this.getAnimations().every(a => a.stopped)) {
155160
const current = { ...this.props.from, ...this.props.to }
156-
onRest && onRest(current)
161+
if (onRest) onRest(current)
157162
cb && typeof cb === 'function' && cb(current)
158163

159164
if (didInject) {
@@ -164,16 +169,16 @@ export default class Spring extends React.PureComponent {
164169
}
165170
}
166171
}
167-
entry.start = cb => {
168-
// Skip held animations
169-
if (callProp(hold, name)) return entry.onFinish(cb)
170172

173+
entry.start = cb => {
174+
if (entry.animation.__getValue() === toValue) return
171175
controller(
172176
entry.animation,
173177
{ to: toValue, ...callProp(config, name) },
174178
impl
175179
).start(props => props.finished && entry.onFinish(cb))
176180
}
181+
177182
entry.stop = () => {
178183
entry.stopped = true
179184
entry.animation.stopAnimation()
@@ -256,7 +261,6 @@ export default class Spring extends React.PureComponent {
256261
immediate,
257262
impl,
258263
inject,
259-
hold,
260264
...forward
261265
} = props
262266
return forward

0 commit comments

Comments
 (0)