@shopify/react-native-skia
Version:
High-performance React Native Graphics using Skia
74 lines (65 loc) • 1.35 kB
JavaScript
import { NodeType } from "../../types";
import { fitRects, processRect } from "../datatypes";
import { JsiDrawingNode } from "../DrawingNode";
export class ImageNode extends JsiDrawingNode {
constructor(ctx, props) {
super(ctx, NodeType.Image, props);
}
deriveProps() {
var _this$props$fit;
const {
image
} = this.props;
if (!image) {
return {
src: {
x: 0,
y: 0,
width: 0,
height: 0
},
dst: {
x: 0,
y: 0,
width: 0,
height: 0
}
};
}
const fit = (_this$props$fit = this.props.fit) !== null && _this$props$fit !== void 0 ? _this$props$fit : "contain";
const rect = processRect(this.Skia, this.props);
const {
src,
dst
} = fitRects(fit, {
x: 0,
y: 0,
width: image.width(),
height: image.height()
}, rect);
return {
src,
dst
};
}
draw(_ref) {
let {
canvas,
paint
} = _ref;
const {
image
} = this.props;
if (!this.derived) {
throw new Error("ImageNode: src and dst are undefined");
}
const {
src,
dst
} = this.derived;
if (image) {
canvas.drawImageRect(image, src, dst, paint);
}
}
}
//# sourceMappingURL=ImageNode.js.map