fix: ensure canvas renders when dialog opens
Fixed canvas visualization not painting sometimes by: - Adding `open` prop check before rendering - Adding `open` to useEffect dependencies - Adding dimension validation for dynamic canvas sizes - Ensures canvas properly renders when dialog becomes visible Affected dialogs: DynamicsParameterDialog, TimeBasedParameterDialog, AdvancedParameterDialog 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -91,6 +91,8 @@ export function AdvancedParameterDialog({
|
|||||||
|
|
||||||
// Draw visual feedback
|
// Draw visual feedback
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
|
if (!open) return;
|
||||||
|
|
||||||
const canvas = canvasRef.current;
|
const canvas = canvasRef.current;
|
||||||
if (!canvas) return;
|
if (!canvas) return;
|
||||||
|
|
||||||
@@ -210,7 +212,7 @@ export function AdvancedParameterDialog({
|
|||||||
ctx.moveTo(0, height / 2);
|
ctx.moveTo(0, height / 2);
|
||||||
ctx.lineTo(width, height / 2);
|
ctx.lineTo(width, height / 2);
|
||||||
ctx.stroke();
|
ctx.stroke();
|
||||||
}, [parameters, effectType]);
|
}, [parameters, effectType, open]);
|
||||||
|
|
||||||
const handleApply = () => {
|
const handleApply = () => {
|
||||||
onApply({ ...parameters, type: effectType } as AdvancedParameters);
|
onApply({ ...parameters, type: effectType } as AdvancedParameters);
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ export function DynamicsParameterDialog({
|
|||||||
|
|
||||||
// Draw transfer curve (input level vs output level)
|
// Draw transfer curve (input level vs output level)
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (!canvasRef.current) return;
|
if (!open || !canvasRef.current) return;
|
||||||
|
|
||||||
const canvas = canvasRef.current;
|
const canvas = canvasRef.current;
|
||||||
const ctx = canvas.getContext('2d');
|
const ctx = canvas.getContext('2d');
|
||||||
@@ -149,6 +149,9 @@ export function DynamicsParameterDialog({
|
|||||||
const rect = canvas.getBoundingClientRect();
|
const rect = canvas.getBoundingClientRect();
|
||||||
const dpr = window.devicePixelRatio || 1;
|
const dpr = window.devicePixelRatio || 1;
|
||||||
|
|
||||||
|
// Ensure canvas has dimensions before drawing
|
||||||
|
if (rect.width === 0 || rect.height === 0) return;
|
||||||
|
|
||||||
// Set actual size in memory (scaled to account for extra pixel density)
|
// Set actual size in memory (scaled to account for extra pixel density)
|
||||||
canvas.width = rect.width * dpr;
|
canvas.width = rect.width * dpr;
|
||||||
canvas.height = rect.height * dpr;
|
canvas.height = rect.height * dpr;
|
||||||
@@ -296,7 +299,7 @@ export function DynamicsParameterDialog({
|
|||||||
ctx.fillText(db.toString(), x, height - 20);
|
ctx.fillText(db.toString(), x, height - 20);
|
||||||
}
|
}
|
||||||
|
|
||||||
}, [parameters, effectType]);
|
}, [parameters, effectType, open]);
|
||||||
|
|
||||||
const handleApply = () => {
|
const handleApply = () => {
|
||||||
onApply(parameters);
|
onApply(parameters);
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ export function TimeBasedParameterDialog({
|
|||||||
|
|
||||||
// Draw visualization
|
// Draw visualization
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (!canvasRef.current) return;
|
if (!open || !canvasRef.current) return;
|
||||||
|
|
||||||
const canvas = canvasRef.current;
|
const canvas = canvasRef.current;
|
||||||
const ctx = canvas.getContext('2d');
|
const ctx = canvas.getContext('2d');
|
||||||
@@ -135,6 +135,9 @@ export function TimeBasedParameterDialog({
|
|||||||
const rect = canvas.getBoundingClientRect();
|
const rect = canvas.getBoundingClientRect();
|
||||||
const dpr = window.devicePixelRatio || 1;
|
const dpr = window.devicePixelRatio || 1;
|
||||||
|
|
||||||
|
// Ensure canvas has dimensions before drawing
|
||||||
|
if (rect.width === 0 || rect.height === 0) return;
|
||||||
|
|
||||||
// Set actual size in memory
|
// Set actual size in memory
|
||||||
canvas.width = rect.width * dpr;
|
canvas.width = rect.width * dpr;
|
||||||
canvas.height = rect.height * dpr;
|
canvas.height = rect.height * dpr;
|
||||||
@@ -255,7 +258,7 @@ export function TimeBasedParameterDialog({
|
|||||||
ctx.setLineDash([]);
|
ctx.setLineDash([]);
|
||||||
}
|
}
|
||||||
|
|
||||||
}, [parameters, effectType]);
|
}, [parameters, effectType, open]);
|
||||||
|
|
||||||
const handleApply = () => {
|
const handleApply = () => {
|
||||||
onApply(parameters);
|
onApply(parameters);
|
||||||
|
|||||||
Reference in New Issue
Block a user