Files
react-native-reanimated/src/core/AnimatedCond.js
Michał Osadnik c841c34d10 Remove dependencies' cycles (#187)
The main problems were with setValue and interpolate so I made them not available internally and exposed it with addition class. In internal operation InternalAnimatedValue is used and it's not causing dependencies' cycles.

Changed logic of exposing nodes. Now there's no need to import whole base.js for wrapped nodes.
2019-04-25 10:49:54 +02:00

41 lines
960 B
JavaScript

import { val } from '../val';
import AnimatedNode from './AnimatedNode';
import { adapt } from '../core/AnimatedBlock';
class AnimatedCond extends AnimatedNode {
_condition;
_ifBlock;
_elseBlock;
constructor(condition, ifBlock, elseBlock) {
super(
{
type: 'cond',
cond: condition.__nodeID,
ifBlock: ifBlock.__nodeID,
elseBlock: elseBlock ? elseBlock.__nodeID : undefined,
},
[condition, ifBlock, elseBlock]
);
this._condition = condition;
this._ifBlock = ifBlock;
this._elseBlock = elseBlock;
}
__onEvaluate() {
if (val(this._condition)) {
return val(this._ifBlock);
} else {
return this._elseBlock !== undefined ? val(this._elseBlock) : undefined;
}
}
}
export function createAnimatedCond(cond, ifBlock, elseBlock) {
return new AnimatedCond(
adapt(cond),
adapt(ifBlock),
elseBlock === undefined ? undefined : adapt(elseBlock)
);
}