Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[web][fix] Add setValue to InternalAnimatedValue #532

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small nitpick, IMO this.argsStack.length === 0 would be better here

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`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^

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