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

Unify sanitizing nodes for platform #549

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/core/AnimatedAlways.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class AnimatedAlways extends AnimatedNode {
what instanceof AnimatedNode,
`Reanimated: Animated.always node argument should be of type AnimatedNode but got ${what}`
);
super({ type: 'always', what: what.__nodeID }, [what]);
super({ type: 'always', what }, [what]);
this._what = what;
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/AnimatedBezier.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export default class AnimatedBezier extends AnimatedNode {
value instanceof AnimatedNode,
`Reanimated: Bezier node argument should be of type AnimatedNode but got ${value}`
);
super({ type: 'bezier', mX1, mY1, mX2, mY2, input: value.__nodeID }, [
super({ type: 'bezier', mX1, mY1, mX2, mY2, input: value }, [
value,
]);
this._value = value;
Expand Down
2 changes: 1 addition & 1 deletion src/core/AnimatedBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class AnimatedBlock extends AnimatedNode {
array.every(el => el instanceof AnimatedNode),
`Reanimated: Animated.block node argument should be an array with elements of type AnimatedNode. One or more of them are not AnimatedNodes`
);
super({ type: 'block', block: array.map(n => n.__nodeID) }, array);
super({ type: 'block', block: array }, array);
this._array = array;
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/AnimatedCall.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class AnimatedCall extends AnimatedNode {
args.every(el => el instanceof AnimatedNode),
`Reanimated: Animated.call node args should be an array with elements of type AnimatedNode. One or more of them are not AnimatedNodes`
);
super({ type: 'call', input: args.map(n => n.__nodeID) }, args);
super({ type: 'call', input: args }, args);
this._callback = jsFunction;
this._args = args;
}
Expand Down
6 changes: 3 additions & 3 deletions src/core/AnimatedCallFunc.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ class AnimatedCallFunc extends AnimatedNode {
super(
{
type: 'callfunc',
what: what.__nodeID,
args: args.map(n => n.__nodeID),
params: params.map(n => n.__nodeID),
what,
args,
params,
},
[...args]
);
Expand Down
2 changes: 1 addition & 1 deletion src/core/AnimatedClockTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class AnimatedClockTest extends AnimatedNode {
_clockNode;

constructor(clockNode) {
super({ type: 'clockTest', clock: clockNode.__nodeID });
super({ type: 'clockTest', clock: clockNode });
this._clockNode = clockNode;
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/AnimatedConcat.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class AnimatedConcat extends AnimatedNode {
),
`Reanimated: Animated.concat node arguments should be of type AnimatedNode or String or Number. One or more of them are not of that type. Node: ${input}`
);
super({ type: 'concat', input: input.map(n => n.__nodeID) }, input);
super({ type: 'concat', input }, input);
this._input = input;
}

Expand Down
6 changes: 3 additions & 3 deletions src/core/AnimatedCond.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ class AnimatedCond extends AnimatedNode {
super(
{
type: 'cond',
cond: condition.__nodeID,
ifBlock: ifBlock.__nodeID,
elseBlock: elseBlock ? elseBlock.__nodeID : undefined,
cond: condition,
ifBlock,
elseBlock,
},
[condition, ifBlock, elseBlock]
);
Expand Down
2 changes: 1 addition & 1 deletion src/core/AnimatedDebug.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class AnimatedDebug extends AnimatedNode {
value instanceof AnimatedNode,
`Reanimated: Animated.debug node second argument should be of type AnimatedNode but got ${value}`
);
super({ type: 'debug', message, value: value.__nodeID }, [value]);
super({ type: 'debug', message, value }, [value]);
this._message = message;
this._value = value;
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/AnimatedFunction.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class AnimatedFunction extends AnimatedNode {
super(
{
type: 'func',
what: what.__nodeID,
what,
},
[what, ...params]
);
Expand Down
19 changes: 13 additions & 6 deletions src/core/AnimatedNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,22 @@ let loopID = 1;
let propUpdatesEnqueued = null;

function sanitizeConfig(config) {
if (Platform.OS === 'web') {
if (Platform.OS === 'web' || ['undefined', 'string', 'function', 'boolean', 'number'].includes(typeof config)) {
return config;
}
for (const key in config) {
const value = config[key];
if (value instanceof AnimatedNode) {
config[key] = value.__nodeID;
} else if (Array.isArray(config)) {
return config.map(sanitizeConfig);
} else if (config instanceof AnimatedNode) {
return config.__nodeID;
} else if (typeof config === 'object') {
const output = {};
for (const property in config) {
if (property in config) {
output[property] = sanitizeConfig(config[property]);
}
}
return output;
}
// unhandled
return config;
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/AnimatedOperator.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class AnimatedOperator extends AnimatedNode {
`Reanimated: Animated.operator node second argument should be one or more of type AnimatedNode, String or Number but got ${input}`
);
super(
{ type: 'op', op: operator, input: input.map(n => n.__nodeID) },
{ type: 'op', op: operator, input },
input
);
this._op = operator;
Expand Down
2 changes: 1 addition & 1 deletion src/core/AnimatedSet.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class AnimatedSet extends AnimatedNode {
value instanceof AnimatedNode,
`Reanimated: Animated.set second argument should be of type AnimatedNode, String or Number but got ${value}`
);
super({ type: 'set', what: what.__nodeID, value: value.__nodeID }, [value]);
super({ type: 'set', what, value }, [value]);
invariant(!what._constant, 'Value to be set cannot be constant');
this._what = what;
this._value = value;
Expand Down
2 changes: 1 addition & 1 deletion src/core/AnimatedStartClock.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class AnimatedStartClock extends AnimatedNode {
clockNode instanceof AnimatedClock || clockNode instanceof AnimatedParam,
`Reanimated: Animated.startClock argument should be of type AnimatedClock but got ${clockNode}`
);
super({ type: 'clockStart', clock: clockNode.__nodeID });
super({ type: 'clockStart', clock: clockNode });
this._clockNode = clockNode;
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/AnimatedStopClock.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class AnimatedStopClock extends AnimatedNode {
clockNode instanceof AnimatedClock || clockNode instanceof AnimatedParam,
`Reanimated: Animated.stopClock argument should be of type AnimatedClock but got ${clockNode}`
);
super({ type: 'clockStop', clock: clockNode.__nodeID });
super({ type: 'clockStop', clock: clockNode });
this._clockNode = clockNode;
}

Expand Down