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

fix(canvas): pass original touch event

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