Refactor event listeners to use container for touch and wheel events

This commit is contained in:
David Haz
2025-07-12 10:41:29 +03:00
parent 65240f0f8e
commit 7d64e4b756

View File

@@ -639,28 +639,32 @@ class App {
this.boundOnTouchDown = this.onTouchDown.bind(this) this.boundOnTouchDown = this.onTouchDown.bind(this)
this.boundOnTouchMove = this.onTouchMove.bind(this) this.boundOnTouchMove = this.onTouchMove.bind(this)
this.boundOnTouchUp = this.onTouchUp.bind(this) this.boundOnTouchUp = this.onTouchUp.bind(this)
window.addEventListener('resize', this.boundOnResize) window.addEventListener('resize', this.boundOnResize)
window.addEventListener('mousewheel', this.boundOnWheel)
window.addEventListener('wheel', this.boundOnWheel) this.container.addEventListener('wheel', this.boundOnWheel)
window.addEventListener('mousedown', this.boundOnTouchDown) this.container.addEventListener('mousedown', this.boundOnTouchDown)
this.container.addEventListener('touchstart', this.boundOnTouchDown)
window.addEventListener('mousemove', this.boundOnTouchMove) window.addEventListener('mousemove', this.boundOnTouchMove)
window.addEventListener('mouseup', this.boundOnTouchUp) window.addEventListener('mouseup', this.boundOnTouchUp)
window.addEventListener('touchstart', this.boundOnTouchDown)
window.addEventListener('touchmove', this.boundOnTouchMove) window.addEventListener('touchmove', this.boundOnTouchMove)
window.addEventListener('touchend', this.boundOnTouchUp) window.addEventListener('touchend', this.boundOnTouchUp)
} }
destroy() { destroy() {
window.cancelAnimationFrame(this.raf) window.cancelAnimationFrame(this.raf)
window.removeEventListener('resize', this.boundOnResize) window.removeEventListener('resize', this.boundOnResize)
window.removeEventListener('mousewheel', this.boundOnWheel)
window.removeEventListener('wheel', this.boundOnWheel)
window.removeEventListener('mousedown', this.boundOnTouchDown)
window.removeEventListener('mousemove', this.boundOnTouchMove) window.removeEventListener('mousemove', this.boundOnTouchMove)
window.removeEventListener('mouseup', this.boundOnTouchUp) window.removeEventListener('mouseup', this.boundOnTouchUp)
window.removeEventListener('touchstart', this.boundOnTouchDown)
window.removeEventListener('touchmove', this.boundOnTouchMove) window.removeEventListener('touchmove', this.boundOnTouchMove)
window.removeEventListener('touchend', this.boundOnTouchUp) window.removeEventListener('touchend', this.boundOnTouchUp)
this.container.removeEventListener('wheel', this.boundOnWheel)
this.container.removeEventListener('mousedown', this.boundOnTouchDown)
this.container.removeEventListener('touchstart', this.boundOnTouchDown)
if (this.renderer && this.renderer.gl && this.renderer.gl.canvas.parentNode) { if (this.renderer && this.renderer.gl && this.renderer.gl.canvas.parentNode) {
this.renderer.gl.canvas.parentNode.removeChild(this.renderer.gl.canvas as HTMLCanvasElement) this.renderer.gl.canvas.parentNode.removeChild(this.renderer.gl.canvas as HTMLCanvasElement)
} }