wxml-to-canvas
wxml-to-canvas copied to clipboard
增加 shouldClearRect 配置,允许在绘制前不清空 canvas
背景:因为 wxml-to-canvas 不支持渐变色背景,所以希望在调用 renderToCanvas 之前,能够允许业务方自行对 canvas 进行一些绘制。然后目前 renderToCanvas 会清空 canvas 画布,导致业务方自行绘制的数据失效,因为增加 shouldClearRect 进行配置。
绘制渐变色背景图例子:
const { ctx } = this.wxmlToCanvasWidget;
// wxml-to-canvas 不支持渐变背景色,自行实现
ctx.save();
const {
canvasHeight,
canvasWidth,
} = this.data;
const grd = ctx.createLinearGradient(0, 0, 0, canvasHeight);
grd.addColorStop(0, '#FF6E55');
grd.addColorStop(1, '#EB4225');
ctx.fillStyle = grd;
ctx.fillRect(0, 0, canvasWidth, canvasHeight);
ctx.restore();
this.wxmlToCanvasWidget.renderToCanvas({
wxml,
style,
shouldClearRect: false,
}).then((res) => { ... });