Skip to content

Commit

Permalink
Add setValue to InternalAnimatedValue (#532)
Browse files Browse the repository at this point in the history
- fix #481
- add errors for better hints when types are passed incorrectly
  • Loading branch information
EvanBacon authored and osdnk committed Jan 2, 2020
1 parent bdc7b59 commit aacc353
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/core/AnimatedParam.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,17 @@ export class AnimatedParam extends AnimatedNode {
}

setValue(value) {
if (!this.argsStack.length) throw new Error(`param: setValue(${value}) failed because argsStack is empty`);
const top = this.argsStack[this.argsStack.length - 1];
top.setValue(value);
if (top.setValue) {
top.setValue(value);
} else {
throw new Error(`param: setValue(${value}) failed because the top element has no known method for updating it's current value.`)
}
}

__onEvaluate() {
if (!this.argsStack.length) throw new Error(`param: __onEvaluate() failed because argsStack is empty`);
const top = this.argsStack[this.argsStack.length - 1];
return val(top);
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/AnimatedSet.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class AnimatedSet extends AnimatedNode {

__onEvaluate() {
const newValue = val(this._value);
this._what._updateValue(newValue);
this._what.setValue(newValue);
return newValue;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/AnimatedValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import interpolate from '../derived/interpolate';
import InternalAnimatedValue from './InternalAnimatedValue';
import { Platform } from 'react-native';
import { evaluateOnce } from '../derived/evaluateOnce';
import ReanimatedModule from '../ReanimatedModule';
import ReanimatedModule from '../ReanimatedModule';

// Animated value wrapped with extra methods for omit cycle of dependencies
export default class AnimatedValue extends InternalAnimatedValue {
Expand Down
6 changes: 6 additions & 0 deletions src/core/InternalAnimatedValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ export default class InternalAnimatedValue extends AnimatedNode {
return this._value;
}

// AnimatedValue will override this method to modify the value of a native node.
setValue(value) {
this.__detachAnimation(this._animation);
this._updateValue(value);
}

_updateValue(value) {
this._value = value;
this.__forceUpdateCache(value);
Expand Down

0 comments on commit aacc353

Please sign in to comment.