Skip to content

Commit

Permalink
📱 Navigation > View > Add touch support
Browse files Browse the repository at this point in the history
  • Loading branch information
brunosimon committed Aug 30, 2021
1 parent fa10369 commit b0ba935
Showing 1 changed file with 49 additions and 1 deletion.
50 changes: 49 additions & 1 deletion src/Experience/Navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ export default class Navigation
*/
this.view.onMouseDown = (_event) =>
{
_event.preventDefault()

this.view.down(_event.clientX, _event.clientY)

window.addEventListener('mouseup', this.view.onMouseUp)
Expand All @@ -69,18 +71,64 @@ export default class Navigation

this.view.onMouseMove = (_event) =>
{
_event.preventDefault()

this.view.move(_event.clientX, _event.clientY)
}

this.view.onMouseUp = () =>
this.view.onMouseUp = (_event) =>
{
_event.preventDefault()

this.view.up()

window.removeEventListener('mouseup', this.view.onMouseUp)
window.removeEventListener('mousemove', this.view.onMouseMove)
}

window.addEventListener('mousedown', this.view.onMouseDown)

/**
* Touch events
*/
this.view.onTouchStart = (_event) =>
{
_event.preventDefault()

this.view.down(_event.touches[0].clientX, _event.touches[0].clientY)

window.addEventListener('touchend', this.view.onTouchEnd)
window.addEventListener('touchmove', this.view.onTouchMove)
}

this.view.onTouchMove = (_event) =>
{
_event.preventDefault()

this.view.move(_event.touches[0].clientX, _event.touches[0].clientY)
}

this.view.onTouchEnd = (_event) =>
{
_event.preventDefault()

this.view.up()

window.removeEventListener('touchend', this.view.onTouchEnd)
window.removeEventListener('touchmove', this.view.onTouchMove)
}

window.addEventListener('touchstart', this.view.onTouchStart)

/**
* Context menu
*/
this.view.onContextMenu = (_event) =>
{
_event.preventDefault()
}

window.addEventListener('contextmenu', this.view.onContextMenu)
}

update()
Expand Down

1 comment on commit b0ba935

@vercel
Copy link

@vercel vercel bot commented on b0ba935 Aug 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.