feat: add touch event support to knobs and faders
Added comprehensive touch event handling for mobile/tablet support: CircularKnob.tsx: - Added handleTouchStart, handleTouchMove, handleTouchEnd handlers - Touch events use same drag logic as mouse events - Prevents default to avoid scrolling while adjusting TrackFader.tsx: - Added touch event handlers for vertical fader control - Integrated with existing onTouchStart/onTouchEnd callbacks - Supports touch-based automation recording MasterFader.tsx: - Added touch event handlers matching TrackFader - Complete touch support for master volume control All components now work seamlessly on touch-enabled devices. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -10,6 +10,8 @@ export interface MasterFaderProps {
|
|||||||
isClipping: boolean;
|
isClipping: boolean;
|
||||||
onChange: (value: number) => void;
|
onChange: (value: number) => void;
|
||||||
onResetClip?: () => void;
|
onResetClip?: () => void;
|
||||||
|
onTouchStart?: () => void;
|
||||||
|
onTouchEnd?: () => void;
|
||||||
className?: string;
|
className?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -20,6 +22,8 @@ export function MasterFader({
|
|||||||
isClipping,
|
isClipping,
|
||||||
onChange,
|
onChange,
|
||||||
onResetClip,
|
onResetClip,
|
||||||
|
onTouchStart,
|
||||||
|
onTouchEnd,
|
||||||
className,
|
className,
|
||||||
}: MasterFaderProps) {
|
}: MasterFaderProps) {
|
||||||
const [isDragging, setIsDragging] = React.useState(false);
|
const [isDragging, setIsDragging] = React.useState(false);
|
||||||
@@ -43,6 +47,7 @@ export function MasterFader({
|
|||||||
const handleMouseDown = (e: React.MouseEvent) => {
|
const handleMouseDown = (e: React.MouseEvent) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
setIsDragging(true);
|
setIsDragging(true);
|
||||||
|
onTouchStart?.();
|
||||||
updateValue(e.clientY);
|
updateValue(e.clientY);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -56,7 +61,30 @@ export function MasterFader({
|
|||||||
|
|
||||||
const handleMouseUp = React.useCallback(() => {
|
const handleMouseUp = React.useCallback(() => {
|
||||||
setIsDragging(false);
|
setIsDragging(false);
|
||||||
}, []);
|
onTouchEnd?.();
|
||||||
|
}, [onTouchEnd]);
|
||||||
|
|
||||||
|
const handleTouchStart = (e: React.TouchEvent) => {
|
||||||
|
e.preventDefault();
|
||||||
|
const touch = e.touches[0];
|
||||||
|
setIsDragging(true);
|
||||||
|
onTouchStart?.();
|
||||||
|
updateValue(touch.clientY);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleTouchMove = React.useCallback(
|
||||||
|
(e: TouchEvent) => {
|
||||||
|
if (!isDragging || e.touches.length === 0) return;
|
||||||
|
const touch = e.touches[0];
|
||||||
|
updateValue(touch.clientY);
|
||||||
|
},
|
||||||
|
[isDragging]
|
||||||
|
);
|
||||||
|
|
||||||
|
const handleTouchEnd = React.useCallback(() => {
|
||||||
|
setIsDragging(false);
|
||||||
|
onTouchEnd?.();
|
||||||
|
}, [onTouchEnd]);
|
||||||
|
|
||||||
const updateValue = (clientY: number) => {
|
const updateValue = (clientY: number) => {
|
||||||
if (!containerRef.current) return;
|
if (!containerRef.current) return;
|
||||||
@@ -72,12 +100,16 @@ export function MasterFader({
|
|||||||
if (isDragging) {
|
if (isDragging) {
|
||||||
window.addEventListener('mousemove', handleMouseMove);
|
window.addEventListener('mousemove', handleMouseMove);
|
||||||
window.addEventListener('mouseup', handleMouseUp);
|
window.addEventListener('mouseup', handleMouseUp);
|
||||||
|
window.addEventListener('touchmove', handleTouchMove);
|
||||||
|
window.addEventListener('touchend', handleTouchEnd);
|
||||||
return () => {
|
return () => {
|
||||||
window.removeEventListener('mousemove', handleMouseMove);
|
window.removeEventListener('mousemove', handleMouseMove);
|
||||||
window.removeEventListener('mouseup', handleMouseUp);
|
window.removeEventListener('mouseup', handleMouseUp);
|
||||||
|
window.removeEventListener('touchmove', handleTouchMove);
|
||||||
|
window.removeEventListener('touchend', handleTouchEnd);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}, [isDragging, handleMouseMove, handleMouseUp]);
|
}, [isDragging, handleMouseMove, handleMouseUp, handleTouchMove, handleTouchEnd]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={cn('flex gap-3', className)} style={{ marginLeft: '16px' }}>
|
<div className={cn('flex gap-3', className)} style={{ marginLeft: '16px' }}>
|
||||||
@@ -94,6 +126,7 @@ export function MasterFader({
|
|||||||
ref={containerRef}
|
ref={containerRef}
|
||||||
className="relative w-12 h-40 bg-background/50 rounded-md border border-border/50 cursor-pointer"
|
className="relative w-12 h-40 bg-background/50 rounded-md border border-border/50 cursor-pointer"
|
||||||
onMouseDown={handleMouseDown}
|
onMouseDown={handleMouseDown}
|
||||||
|
onTouchStart={handleTouchStart}
|
||||||
>
|
>
|
||||||
{/* Peak Meter (Horizontal Bar - Top) */}
|
{/* Peak Meter (Horizontal Bar - Top) */}
|
||||||
<div className="absolute inset-x-2 top-2 h-3 bg-background/80 rounded-sm overflow-hidden border border-border/30">
|
<div className="absolute inset-x-2 top-2 h-3 bg-background/80 rounded-sm overflow-hidden border border-border/30">
|
||||||
|
|||||||
@@ -60,6 +60,28 @@ export function TrackFader({
|
|||||||
onTouchEnd?.();
|
onTouchEnd?.();
|
||||||
}, [onTouchEnd]);
|
}, [onTouchEnd]);
|
||||||
|
|
||||||
|
const handleTouchStart = (e: React.TouchEvent) => {
|
||||||
|
e.preventDefault();
|
||||||
|
const touch = e.touches[0];
|
||||||
|
setIsDragging(true);
|
||||||
|
onTouchStart?.();
|
||||||
|
updateValue(touch.clientY);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleTouchMove = React.useCallback(
|
||||||
|
(e: TouchEvent) => {
|
||||||
|
if (!isDragging || e.touches.length === 0) return;
|
||||||
|
const touch = e.touches[0];
|
||||||
|
updateValue(touch.clientY);
|
||||||
|
},
|
||||||
|
[isDragging]
|
||||||
|
);
|
||||||
|
|
||||||
|
const handleTouchEnd = React.useCallback(() => {
|
||||||
|
setIsDragging(false);
|
||||||
|
onTouchEnd?.();
|
||||||
|
}, [onTouchEnd]);
|
||||||
|
|
||||||
const updateValue = (clientY: number) => {
|
const updateValue = (clientY: number) => {
|
||||||
if (!containerRef.current) return;
|
if (!containerRef.current) return;
|
||||||
|
|
||||||
@@ -74,12 +96,16 @@ export function TrackFader({
|
|||||||
if (isDragging) {
|
if (isDragging) {
|
||||||
window.addEventListener('mousemove', handleMouseMove);
|
window.addEventListener('mousemove', handleMouseMove);
|
||||||
window.addEventListener('mouseup', handleMouseUp);
|
window.addEventListener('mouseup', handleMouseUp);
|
||||||
|
window.addEventListener('touchmove', handleTouchMove);
|
||||||
|
window.addEventListener('touchend', handleTouchEnd);
|
||||||
return () => {
|
return () => {
|
||||||
window.removeEventListener('mousemove', handleMouseMove);
|
window.removeEventListener('mousemove', handleMouseMove);
|
||||||
window.removeEventListener('mouseup', handleMouseUp);
|
window.removeEventListener('mouseup', handleMouseUp);
|
||||||
|
window.removeEventListener('touchmove', handleTouchMove);
|
||||||
|
window.removeEventListener('touchend', handleTouchEnd);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}, [isDragging, handleMouseMove, handleMouseUp]);
|
}, [isDragging, handleMouseMove, handleMouseUp, handleTouchMove, handleTouchEnd]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={cn('flex gap-2', className)} style={{ marginLeft: '16px' }}>
|
<div className={cn('flex gap-2', className)} style={{ marginLeft: '16px' }}>
|
||||||
@@ -96,6 +122,7 @@ export function TrackFader({
|
|||||||
ref={containerRef}
|
ref={containerRef}
|
||||||
className="relative w-10 h-32 bg-background/50 rounded-md border border-border/50 cursor-pointer"
|
className="relative w-10 h-32 bg-background/50 rounded-md border border-border/50 cursor-pointer"
|
||||||
onMouseDown={handleMouseDown}
|
onMouseDown={handleMouseDown}
|
||||||
|
onTouchStart={handleTouchStart}
|
||||||
>
|
>
|
||||||
{/* Peak Meter (Horizontal Bar - Top) */}
|
{/* Peak Meter (Horizontal Bar - Top) */}
|
||||||
<div className="absolute inset-x-1.5 top-1.5 h-2.5 bg-background/80 rounded-sm overflow-hidden border border-border/30">
|
<div className="absolute inset-x-1.5 top-1.5 h-2.5 bg-background/80 rounded-sm overflow-hidden border border-border/30">
|
||||||
|
|||||||
@@ -91,17 +91,51 @@ export function CircularKnob({
|
|||||||
onTouchEnd?.();
|
onTouchEnd?.();
|
||||||
}, [onTouchEnd]);
|
}, [onTouchEnd]);
|
||||||
|
|
||||||
|
const handleTouchStart = React.useCallback(
|
||||||
|
(e: React.TouchEvent) => {
|
||||||
|
e.preventDefault();
|
||||||
|
const touch = e.touches[0];
|
||||||
|
setIsDragging(true);
|
||||||
|
dragStartRef.current = {
|
||||||
|
x: touch.clientX,
|
||||||
|
y: touch.clientY,
|
||||||
|
value,
|
||||||
|
};
|
||||||
|
onTouchStart?.();
|
||||||
|
},
|
||||||
|
[value, onTouchStart]
|
||||||
|
);
|
||||||
|
|
||||||
|
const handleTouchMove = React.useCallback(
|
||||||
|
(e: TouchEvent) => {
|
||||||
|
if (isDragging && e.touches.length > 0) {
|
||||||
|
const touch = e.touches[0];
|
||||||
|
updateValue(touch.clientX, touch.clientY);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[isDragging, updateValue]
|
||||||
|
);
|
||||||
|
|
||||||
|
const handleTouchEnd = React.useCallback(() => {
|
||||||
|
setIsDragging(false);
|
||||||
|
onTouchEnd?.();
|
||||||
|
}, [onTouchEnd]);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (isDragging) {
|
if (isDragging) {
|
||||||
window.addEventListener('mousemove', handleMouseMove);
|
window.addEventListener('mousemove', handleMouseMove);
|
||||||
window.addEventListener('mouseup', handleMouseUp);
|
window.addEventListener('mouseup', handleMouseUp);
|
||||||
|
window.addEventListener('touchmove', handleTouchMove);
|
||||||
|
window.addEventListener('touchend', handleTouchEnd);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
window.removeEventListener('mousemove', handleMouseMove);
|
window.removeEventListener('mousemove', handleMouseMove);
|
||||||
window.removeEventListener('mouseup', handleMouseUp);
|
window.removeEventListener('mouseup', handleMouseUp);
|
||||||
|
window.removeEventListener('touchmove', handleTouchMove);
|
||||||
|
window.removeEventListener('touchend', handleTouchEnd);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}, [isDragging, handleMouseMove, handleMouseUp]);
|
}, [isDragging, handleMouseMove, handleMouseUp, handleTouchMove, handleTouchEnd]);
|
||||||
|
|
||||||
// Calculate rotation angle (-135deg to 135deg, 270deg range)
|
// Calculate rotation angle (-135deg to 135deg, 270deg range)
|
||||||
const percentage = (value - min) / (max - min);
|
const percentage = (value - min) / (max - min);
|
||||||
@@ -148,6 +182,7 @@ export function CircularKnob({
|
|||||||
<div
|
<div
|
||||||
ref={knobRef}
|
ref={knobRef}
|
||||||
onMouseDown={handleMouseDown}
|
onMouseDown={handleMouseDown}
|
||||||
|
onTouchStart={handleTouchStart}
|
||||||
className="relative cursor-pointer select-none"
|
className="relative cursor-pointer select-none"
|
||||||
style={{ width: size, height: size }}
|
style={{ width: size, height: size }}
|
||||||
>
|
>
|
||||||
|
|||||||
Reference in New Issue
Block a user