UNPKG

@shopify/react-native-skia

Version:

High-performance React Native Graphics using Skia

95 lines 2.98 kB
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); } function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } export class JsiNode { constructor(ctx, type, props) { this.type = type; this.props = props; _defineProperty(this, "_children", []); _defineProperty(this, "Skia", void 0); this.Skia = ctx.Skia; } setProps(props) { this.props = props; } setProp(name, v) { const hasChanged = this.props[name] !== v; this.props[name] = v; return hasChanged; } getProps() { return this.props; } children() { return this._children; } addChild(child) { this.removeChild(child); this._children.push(child); } dispose() { this._children.forEach(child => child.dispose()); } removeChild(child) { const index = this._children.indexOf(child); if (index !== -1) { const [node] = this._children.splice(index, 1); node.dispose(); } } insertChildBefore(child, before) { const index = this._children.indexOf(child); if (index !== -1) { this._children.splice(index, 1); } const beforeIndex = this._children.indexOf(before); this._children.splice(beforeIndex, 0, child); } } export class JsiDeclarationNode extends JsiNode { constructor(ctx, declarationType, type, props) { super(ctx, type, props); this.declarationType = declarationType; _defineProperty(this, "invalidate", () => {}); } decorateChildren(ctx) { this.children().forEach(child => { if (child instanceof JsiDeclarationNode) { child.decorate(ctx); } }); } addChild(child) { if (!(child instanceof JsiDeclarationNode)) { throw new Error(`Cannot add child of type ${child.type} to ${this.type}`); } super.addChild(child); this.invalidate(); } insertChildBefore(child, before) { if (!(child instanceof JsiDeclarationNode)) { throw new Error(`Cannot add child of type ${child.type} to ${this.type}`); } super.insertChildBefore(child, before); this.invalidate(); } dispose() { this.invalidate(); super.dispose(); } setInvalidate(invalidate) { this.invalidate = invalidate; } setProps(props) { super.setProps(props); this.invalidate(); } setProp(name, v) { const hasChanged = super.setProp(name, v); if (hasChanged) { this.invalidate(); } return hasChanged; } } //# sourceMappingURL=Node.js.map