@shopify/react-native-skia
Version:
High-performance React Native Graphics using Skia
84 lines (64 loc) • 1.97 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.JsiDrawingNode = void 0;
var _Node = require("./Node");
var _PaintNode = require("./PaintNode");
var _RenderNode = require("./RenderNode");
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
class JsiDrawingNode extends _RenderNode.JsiRenderNode {
constructor(ctx, type, props) {
super(ctx, type, props);
_defineProperty(this, "derived", void 0);
this.derived = this.deriveProps();
}
setProps(props) {
super.setProps(props);
this.derived = this.deriveProps();
}
setProp(name, value) {
const hasChanged = super.setProp(name, value);
if (hasChanged) {
this.derived = this.deriveProps();
}
return hasChanged;
}
addChild(child) {
if (!(child instanceof _Node.JsiDeclarationNode)) {
throw new Error(`Cannot add ${child.type} to ${this.type}`);
}
super.addChild(child);
this.derived = this.deriveProps();
}
insertChildBefore(child, before) {
if (!(child instanceof _Node.JsiDeclarationNode)) {
throw new Error(`Cannot add ${child.type} to ${this.type}`);
}
super.insertChildBefore(child, before);
this.derived = this.deriveProps();
}
renderNode(ctx) {
if (this.props.paint) {
this.draw({ ...ctx,
paint: this.props.paint
});
} else {
this.draw(ctx);
}
this.children().map(child => {
if (child instanceof _PaintNode.PaintNode) {
const declCtx = ctx.declarationCtx;
declCtx.save();
child.decorate(declCtx);
const paint = declCtx.paints.pop();
declCtx.restore();
this.draw({ ...ctx,
paint
});
}
});
}
}
exports.JsiDrawingNode = JsiDrawingNode;
//# sourceMappingURL=DrawingNode.js.map