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

Two-Finger Touch on Waveform Blocks UI Interaction #4020

Open
Shahid-Fahad opened this issue Feb 10, 2025 · 0 comments
Open

Two-Finger Touch on Waveform Blocks UI Interaction #4020

Shahid-Fahad opened this issue Feb 10, 2025 · 0 comments
Labels

Comments

@Shahid-Fahad
Copy link

Shahid-Fahad commented Feb 10, 2025

Description
When interacting with the waveform using two fingers (not just pinch-zoom, just two touches), the entire UI becomes unresponsive to further touch interactions. This issue occurs even when touchAction is set to "none" or "pan-x pan-y", and event listeners are used to block multi-touch gestures.

import WaveSurfer from "wavesurfer.js";

const WaveformComponent = ({ audioUrl }) => {
  const waveformRef = useRef<HTMLDivElement>(null);

  useEffect(() => {
    if (!waveformRef.current) return;

    const wavesurfer = WaveSurfer.create({
      container: waveformRef.current,
      waveColor: "violet",
      progressColor: "purple",
      barWidth: 2,
    });

    wavesurfer.load(audioUrl);

    return () => wavesurfer.destroy();
  }, [audioUrl]);

  useEffect(() => {
    const handleTouchStart = (event: TouchEvent) => {
      if (event.touches.length > 1) {
        event.stopPropagation();
        event.preventDefault();
      }
    };

    const waveformElement = waveformRef.current;
    if (waveformElement) {
      waveformElement.addEventListener("touchstart", handleTouchStart, { passive: false });
    }

    return () => {
      if (waveformElement) {
        waveformElement.removeEventListener("touchstart", handleTouchStart);
      }
    };
  }, []);

  return (
    <div
      ref={waveformRef}
      style={{
        width: "100%",
        height: "300px",
        background: "var(--bg-secondary)",
        overflow: "hidden",
        touchAction: "none", // Disables browser's default multi-touch handling
      }}
    />
  );
};

export default WaveformComponent;

Maybe other users are also facing the same issue: #3833

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant