Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix issue with image background #186

Merged
merged 1 commit into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@visactor/vstory-core",
"comment": "fix: fix issue with image background",
"type": "none"
}
],
"packageName": "@visactor/vstory-core"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@visactor/vstory",
"comment": "fix: fix issue with image background",
"type": "none"
}
],
"packageName": "@visactor/vstory"
}
30 changes: 21 additions & 9 deletions packages/vstory-core/src/core/canvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ export class StoryCanvas implements IStoryCanvas {
scaleX = 1,
scaleY = 1
} = params;
this._container && this._initCanvasByContainer(width, height, dpr);
params.canvas && this._initCanvasByCanvas(canvas, width ?? 500, height ?? 500, dpr);
this._container && this._initCanvasByContainer(width, height, dpr, background);
params.canvas && this._initCanvasByCanvas(canvas, width ?? 500, height ?? 500, dpr, background);

this._stage.background = background;
// this._stage.background = background;
this._stage.defaultLayer.setAttributes({ background: layerBackground });
this.initScale(width, height, scaleX, scaleY);
}

protected _initCanvasByContainer(width: number, height: number, dpr: number) {
protected _initCanvasByContainer(width: number, height: number, dpr: number, background: string) {
const container = this._container;
if (!container) {
return;
Expand All @@ -69,26 +69,38 @@ export class StoryCanvas implements IStoryCanvas {
canvas.id = `_visactor_story_canvas_${this._story.id}`;
this._canvas = canvas as any;
container.appendChild(canvas);
const stage = this._initCanvas(canvas, width ?? container.clientWidth, height ?? container.clientHeight, dpr);
const stage = this._initCanvas(
canvas,
width ?? container.clientWidth,
height ?? container.clientHeight,
dpr,
background
);
// @ts-ignore
this._stage = stage;
}

protected _initCanvasByCanvas(canvas: HTMLCanvasElement, width: number, height: number, dpr: number) {
const stage = this._initCanvas(canvas, width, height, dpr);
protected _initCanvasByCanvas(
canvas: HTMLCanvasElement,
width: number,
height: number,
dpr: number,
background: string
) {
const stage = this._initCanvas(canvas, width, height, dpr, background);
this._canvas = canvas as any;
// @ts-ignore
this._stage = stage;
}

protected _initCanvas(canvas: HTMLCanvasElement, width: number, height: number, dpr: number) {
protected _initCanvas(canvas: HTMLCanvasElement, width: number, height: number, dpr: number, background: string) {
const stage = createStage({
canvas: canvas,
width,
height,
dpr,
canvasControled: true,

background,
// 得开启自动渲染,否则编辑场景中无法触发视图更新
autoRender: false,
disableDirtyBounds: true,
Expand Down
Loading