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: correct calcultation for trackRect is offscreen #1902

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
34 changes: 27 additions & 7 deletions src/web/View.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,37 @@ export type ViewProps = {
}

function computeContainerPosition(canvasSize: LegacyCanvasSize | CanvasSize, trackRect: DOMRect) {
const { right, top, left: trackLeft, bottom: trackBottom, width, height } = trackRect
const isOffscreen = trackRect.bottom < 0 || top > canvasSize.height || right < 0 || trackRect.left > canvasSize.width
const {
right: trackRight,
top: trackTop,
left: trackLeft,
bottom: trackBottom,
width: trackWidth,
height: trackHeight,
} = trackRect
const { width: canvasWidth, height: canvasHeight } = canvasSize
const isLegacyOffscreen = trackBottom < 0 || trackTop > canvasHeight || trackRight < 0 || trackLeft > canvasWidth
if (isNonLegacyCanvasSize(canvasSize)) {
const canvasBottom = canvasSize.top + canvasSize.height
const { top: canvasTop, left: canvasLeft } = canvasSize
const canvasBottom = canvasTop + canvasHeight
const canvasRight = canvasLeft + canvasWidth
const bottom = canvasBottom - trackBottom
const left = trackLeft - canvasSize.left
return { position: { width, height, left, top, bottom, right }, isOffscreen }
const left = trackLeft - canvasLeft
const top = trackTop - canvasTop
const right = canvasRight - trackRight
const isOffscreen =
trackBottom < canvasTop || trackTop > canvasBottom || trackRight < canvasLeft || trackLeft > canvasRight
return {
position: { width: trackWidth, height: trackHeight, left, bottom, top, right },
isOffscreen: isOffscreen,
}
}
// Fall back on old behavior if r3f < 8.1.0
const bottom = canvasSize.height - trackBottom
return { position: { width, height, top, left: trackLeft, bottom, right }, isOffscreen }
const bottom = canvasHeight - trackBottom
return {
position: { width: trackWidth, height: trackHeight, top: trackTop, left: trackLeft, bottom, right: trackRight },
isOffscreen: isLegacyOffscreen,
}
}

function prepareSkissor(
Expand Down