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

Block touch and keypress events, hide multitouch indicators in replays #657

Closed
wants to merge 4 commits into from
Closed
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
71 changes: 40 additions & 31 deletions packages/vscode-extension/src/webview/components/Preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,19 @@ function Preview({

type MouseMove = "Move" | "Down" | "Up";
function sendTouch(event: MouseEvent<HTMLDivElement>, type: MouseMove) {
if (replayData) {
return;
}

const { x, y } = getTouchPosition(event);
project.dispatchTouches([{ xRatio: x, yRatio: y }], type);
}

function sendMultiTouch(event: MouseEvent<HTMLDivElement>, type: MouseMove) {
if (replayData) {
return;
}

const pt = getTouchPosition(event);
const secondPt = calculateMirroredTouchPosition(pt, anchorPoint);
project.dispatchTouches(
Expand Down Expand Up @@ -451,8 +459,11 @@ function Preview({
function keyEventHandler(e: KeyboardEvent) {
if (document.activeElement === wrapperDivRef.current) {
e.preventDefault();
const isKeydown = e.type === "keydown";
if (replayData) {
return;
}

const isKeydown = e.type === "keydown";
const isMultitouchKeyPressed = Platform.select({
macos: e.code === "AltLeft" || e.code === "AltRight",
windows: e.code === "ControlLeft" || e.code === "ControlRight",
Expand All @@ -476,7 +487,7 @@ function Preview({
document.removeEventListener("keydown", keyEventHandler);
document.removeEventListener("keyup", keyEventHandler);
};
}, [project]);
}, [project, replayData]);

useEffect(() => {
if (projectStatus === "running") {
Expand Down Expand Up @@ -540,35 +551,33 @@ function Preview({
/>
{replayData && <ReplayUI onClose={onReplayClose} replayData={replayData} />}

{isMultiTouching && (
<div
style={{
"--x": `${touchPoint.x * 100}%`,
"--y": `${touchPoint.y * 100}%`,
"--size": `${normalTouchIndicatorSize}px`,
}}>
<TouchPointIndicator isPressing={isPressing} />
</div>
)}
{isMultiTouching && (
<div
style={{
"--x": `${anchorPoint.x * 100}%`,
"--y": `${anchorPoint.y * 100}%`,
"--size": `${smallTouchIndicatorSize}px`,
}}>
<TouchPointIndicator isPressing={false} />
</div>
)}
{isMultiTouching && (
<div
style={{
"--x": `${mirroredTouchPosition.x * 100}%`,
"--y": `${mirroredTouchPosition.y * 100}%`,
"--size": `${normalTouchIndicatorSize}px`,
}}>
<TouchPointIndicator isPressing={isPressing} />
</div>
{!replayData && isMultiTouching && (
<>
<div
style={{
"--x": `${touchPoint.x * 100}%`,
"--y": `${touchPoint.y * 100}%`,
"--size": `${normalTouchIndicatorSize}px`,
}}>
<TouchPointIndicator isPressing={isPressing} />
</div>
<div
style={{
"--x": `${anchorPoint.x * 100}%`,
"--y": `${anchorPoint.y * 100}%`,
"--size": `${smallTouchIndicatorSize}px`,
}}>
<TouchPointIndicator isPressing={false} />
</div>
<div
style={{
"--x": `${mirroredTouchPosition.x * 100}%`,
"--y": `${mirroredTouchPosition.y * 100}%`,
"--size": `${normalTouchIndicatorSize}px`,
}}>
<TouchPointIndicator isPressing={isPressing} />
</div>
</>
)}

{!replayData && inspectFrame && (
Expand Down