0

building a html canvas page in react-native webview. everything seem fine except the canvas.addEventListener call the call back with empty event object

var moveEvents = ["mousemove", "touchmove"]
moveEvents.forEach(function (moveEvent) {
canvas.addEventListener(moveEvent, function(e) {
    console.log(e) // {} 
    mouse.x = e.pageX - this.offsetLeft;
    mouse.y = e.pageY - this.offsetTop;
}, false);

don't know what could possible be wrong this behavior is only noticed on react-native here is the code working as expected on jsfiddle

Femi Oni
  • 796
  • 2
  • 9
  • 25

1 Answers1

1

I have been struggling with the exact same thing. Regular events through DOM or jQuery didn't work for me, but the following did.

canvas.ontouchmove = function(e) {
    //e.pageX;
    //e.pageY;
};
Chris
  • 1,068
  • 2
  • 14
  • 30
  • Ah! weird. So it's our fault for treating this as DOM env when it's not. i read this https://stackoverflow.com/questions/41804855/does-react-native-have-a-virtual-dom, and the articles sited. Thanks man for finding an answer to this. – Femi Oni Aug 10 '17 at 10:54