Skip to content

Commit

Permalink
fix Render Bounds check (#218)
Browse files Browse the repository at this point in the history
Fixed an issue where the render bounds check is using the wrong
clippingRect and there was a miscalculation setting up the strict bound,
this caused the in / out of viewport event not being triggered properly.
  • Loading branch information
frank-weindel authored Mar 28, 2024
2 parents 05fed7f + b0a3742 commit f38273b
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions src/core/CoreNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ export class CoreNode extends EventEmitter implements ICoreNode {
}

if (this.updateType & UpdateType.RenderState) {
this.updateRenderState();
this.updateRenderState(parentClippingRect);
this.setUpdateType(UpdateType.IsRenderable);
}

Expand Down Expand Up @@ -574,25 +574,24 @@ export class CoreNode extends EventEmitter implements ICoreNode {
return false;
}

checkRenderBounds(): CoreNodeRenderState {
assertTruthy(this.clippingRect);
checkRenderBounds(parentClippingRect: RectWithValid): CoreNodeRenderState {
assertTruthy(this.renderBound);
const rectW = this.clippingRect.width || this.stage.root.width;
const rectH = this.clippingRect.height || this.stage.root.height;
const rectW = parentClippingRect.width || this.stage.root.width;
const rectH = parentClippingRect.height || this.stage.root.height;
this.strictBound = createBound(
this.clippingRect.x,
this.clippingRect.y,
rectW,
rectH,
parentClippingRect.x,
parentClippingRect.y,
parentClippingRect.x + rectW,
parentClippingRect.y + rectH,
this.strictBound,
);

const renderM = this.stage.boundsMargin;
this.preloadBound = createBound(
this.clippingRect.x - renderM[3],
this.clippingRect.y - renderM[0],
this.clippingRect.x + rectW + renderM[1],
this.clippingRect.y + rectH + renderM[2],
parentClippingRect.x - renderM[3],
parentClippingRect.y - renderM[0],
parentClippingRect.x + rectW + renderM[1],
parentClippingRect.y + rectH + renderM[2],
this.preloadBound,
);

Expand All @@ -606,8 +605,8 @@ export class CoreNode extends EventEmitter implements ICoreNode {
return CoreNodeRenderState.OutOfBounds;
}

updateRenderState() {
const renderState = this.checkRenderBounds();
updateRenderState(parentClippingRect: RectWithValid) {
const renderState = this.checkRenderBounds(parentClippingRect);
if (renderState !== this.renderState) {
const previous = this.renderState;
this.renderState = renderState;
Expand Down

0 comments on commit f38273b

Please sign in to comment.