canvas: ios: different touch.force implementation

This commit is contained in:
jean-emmanuel 2022-10-21 13:05:55 +02:00
parent 4984777dd8
commit edb014e1da
5 changed files with 12 additions and 76 deletions

View file

@ -1,9 +1,7 @@
var Canvas = require('../common/canvas'),
Script = require('../scripts/script'),
widgetManager = require('../../managers/widgets'),
html = require('nanohtml'),
iOS = require('../../ui/ios'),
iosEvents = ['altitudeAngle', 'azimuthAngle', 'force']
html = require('nanohtml')
class CanvasWidget extends Canvas {
@ -116,60 +114,16 @@ class CanvasWidget extends Canvas {
this.batchDraw()
}
if (iOS) {
var code = String(this.getProp('onTouch'))
if (iosEvents.some(x=>code.includes(x))) {
this.iosTouch = true
this.iosTouchCache = {}
this.iosTouchPolls = {}
IOS_TOUCH_POLLING = true
// enable data getters in ../../events/utils.js
}
}
this.on('draginit',(e)=>{
touchCb(e, 'start')
if (this.iosTouch) {
// cache touch inforamtions
this.iosTouchCache[e.pointerId] = e
// start polling extra touch inforamtions
this.iosTouchPolls[e.pointerId] = setInterval(()=>{
if (!this.iosTouchCache[e.pointerId]) return
var changed = false
for (var p of iosEvents) {
// update event data
if (this.iosTouchCache[e.pointerId]['update_' + p]()) changed = true
}
if (changed) {
// if polled value has changed, retrig last move event
// reset movement data since this is only relevant when
// the pointer doesn't move
this.iosTouchCache[e.pointerId].movementX = 0
this.iosTouchCache[e.pointerId].movementY = 0
// call touch move callback
touchCb(this.iosTouchCache[e.pointerId], 'move')
}
}, 1000 / 30)
}
}, {element: this.container, multitouch: true})
this.on('drag',(e)=>{
touchCb(e, 'move')
if (this.iosTouch) {
// cache touch inforamtions
this.iosTouchCache[e.pointerId] = e
}
}, {element: this.container, multitouch: true})
this.on('dragend',(e)=>{
touchCb(e, 'stop')
if (this.iosTouch) {
// stop polling extra touch inforamtions
clearInterval(this.iosTouchPolls[e.pointerId])
delete this.iosTouchPolls[e.pointerId]
delete this.iosTouchCache[e.pointerId]
}
}, {element: this.container, multitouch: true})
}
@ -239,12 +193,6 @@ class CanvasWidget extends Canvas {
clearInterval(this.drawInterval)
if (this.iosTouch) {
for (var k in this.iosTouchPolls) {
clearInterval(this.iosTouchPolls[k])
}
}
super.onRemove()
}