From 77c1d589ca7a6001b1cc8dcfdf4b85d92b24422c Mon Sep 17 00:00:00 2001 From: neverland Date: Mon, 1 May 2023 16:34:17 +0800 Subject: [PATCH] fix(Signature): should prevent page move when signing (#11796) --- packages/vant/src/signature/Signature.tsx | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/vant/src/signature/Signature.tsx b/packages/vant/src/signature/Signature.tsx index 0b272fe6e..96d8e3def 100644 --- a/packages/vant/src/signature/Signature.tsx +++ b/packages/vant/src/signature/Signature.tsx @@ -10,6 +10,7 @@ import { makeNumberProp, makeStringProp, createNamespace, + preventDefault, } from '../utils'; import { Button } from '../button'; @@ -54,6 +55,8 @@ export default defineComponent({ return false; } + preventDefault(event); + const evt = event.changedTouches ? event.changedTouches[0] : event.targetTouches[0]; @@ -74,8 +77,8 @@ export default defineComponent({ state.ctx?.stroke(); }; - const touchEnd = (event: { preventDefault: () => void }) => { - event.preventDefault(); + const touchEnd = (event: TouchEvent) => { + preventDefault(event); emit('end'); }; @@ -83,10 +86,11 @@ export default defineComponent({ if (!state.ctx) { return false; } - emit('start'); + state.ctx.beginPath(); state.ctx.lineWidth = props.lineWidth; state.ctx.strokeStyle = props.penColor; + emit('start'); }; const isCanvasEmpty = (canvas: HTMLCanvasElement) => { @@ -141,7 +145,7 @@ export default defineComponent({ width={state.width} height={state.height} onTouchstartPassive={touchStart} - onTouchmovePassive={touchMove} + onTouchmove={touchMove} onTouchend={touchEnd} /> ) : (