mirror of
https://github.com/zhigang1992/react-native-reanimated.git
synced 2026-01-12 22:50:47 +08:00
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.
49 lines
1.2 KiB
JavaScript
49 lines
1.2 KiB
JavaScript
import React from 'react';
|
|
import { createAnimatedAlways } from './AnimatedAlways';
|
|
import AnimatedNode from './AnimatedNode';
|
|
|
|
class Code extends React.Component {
|
|
static resolveNode = maybeNode => {
|
|
if (typeof maybeNode === 'function') {
|
|
return Code.resolveNode(maybeNode());
|
|
}
|
|
|
|
if (maybeNode instanceof AnimatedNode) {
|
|
return maybeNode;
|
|
}
|
|
|
|
return null;
|
|
};
|
|
|
|
componentDidMount() {
|
|
const { children, exec } = this.props;
|
|
const nodeChildren = Code.resolveNode(children);
|
|
const nodeExec = Code.resolveNode(exec);
|
|
|
|
const cantResolveNode = nodeChildren === null && nodeExec === null;
|
|
|
|
if (cantResolveNode) {
|
|
const error =
|
|
nodeChildren === null
|
|
? `Got "${typeof children}" type passed to children`
|
|
: `Got "${typeof exec}" type passed to exec`;
|
|
|
|
throw new Error(
|
|
`<Animated.Code /> expects the 'exec' prop or children to be an animated node or a function returning an animated node. ${error}`
|
|
);
|
|
}
|
|
|
|
this.always = createAnimatedAlways(nodeExec || nodeChildren);
|
|
this.always.__attach();
|
|
}
|
|
|
|
componentWillUnmount() {
|
|
this.always.__detach();
|
|
}
|
|
|
|
render() {
|
|
return null;
|
|
}
|
|
}
|
|
export default Code;
|