提交 e07b81c4 编写于 作者: fxy060608's avatar fxy060608

fix(canvas): pass original touch event

上级 97c3a825
...@@ -35,15 +35,10 @@ function resolveColor(color: number[]) { ...@@ -35,15 +35,10 @@ function resolveColor(color: number[]) {
return 'rgba(' + color.join(',') + ')' return 'rgba(' + color.join(',') + ')'
} }
function processTouches(target: EventTarget, touches: TouchEvent['touches']) { function processTouches(rect: DOMRect, touches: TouchEvent['touches']) {
const eventTarget = target as HTMLElement Array.from(touches).forEach((touch) => {
let boundingClientRect = eventTarget.getBoundingClientRect() ;(touch as any).x = touch.clientX - rect.left
return Array.from(touches).map((touch) => { ;(touch as any).y = touch.clientY - rect.top
return {
identifier: touch.identifier,
x: touch.clientX - boundingClientRect.left,
y: touch.clientY - boundingClientRect.top,
}
}) })
} }
...@@ -172,27 +167,10 @@ function useListeners( ...@@ -172,27 +167,10 @@ function useListeners(
if (existing) { if (existing) {
eventHandler.push( eventHandler.push(
withWebEvent(($event) => { withWebEvent(($event) => {
trigger( const rect = $event.currentTarget.getBoundingClientRect()
event.replace('on', '').toLocaleLowerCase(), processTouches(rect, $event.touches)
extend( processTouches(rect, $event.changedTouches)
{}, trigger(event.replace('on', '').toLocaleLowerCase(), $event)
// $event无法直接assign
(() => {
let obj = {}
for (const key in $event) {
;(obj as any)[key] = $event[key]
}
return obj
})(),
{
touches: processTouches($event.currentTarget, $event.touches),
changedTouches: processTouches(
$event.currentTarget,
$event.changedTouches
),
}
) as unknown as Event
)
}) })
) )
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册