fix(core): browser compatibility issue with TouchList api (#389)

This commit is contained in:
Louis Young 2025-06-18 21:50:32 +08:00 committed by GitHub
parent 2b87cce7fe
commit 7c376e3254
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 1 additions and 27 deletions

View File

@ -1,6 +1,6 @@
export namespace MouseTouchEvent {
export const isTouchEvent = (event: TouchEvent | React.TouchEvent): event is TouchEvent =>
event?.touches instanceof TouchList;
Array.isArray(event?.touches) && event.touches.length > 0;
export const touchToMouseEvent = (event: Event): MouseEvent | Event => {
if (!isTouchEvent(event as TouchEvent)) {

View File

@ -1,14 +1 @@
import 'reflect-metadata';
Object.defineProperty(window, 'TouchList', {
value: class TouchList {
constructor(touches: Touch[] = []) {
touches.forEach((touch, index) => {
this[index] = touch;
});
Object.defineProperty(this, 'length', {
value: touches.length,
});
}
},
});

View File

@ -1,14 +1 @@
import 'reflect-metadata';
Object.defineProperty(window, 'TouchList', {
value: class TouchList {
constructor(touches: Touch[] = []) {
touches.forEach((touch, index) => {
this[index] = touch;
});
Object.defineProperty(this, 'length', {
value: touches.length,
});
}
},
});