VinnyFonseca
9/12/2019 - 11:52 AM

Active Touch Detection

const wasTouched = () => {
  myFrameworkOfChoice.dispatchEvent('USER_HAS_TOUCHED', true);
  window.removeEventListener('touchstart', wasTouched, false);
  window.addEventListener('mousedown', wasClicked, false);
};

const wasClicked = () => {
  myFrameworkOfChoice.dispatchEvent('USER_HAS_TOUCHED', false);
  window.removeEventListener('mousedown', wasClicked, false);
  window.addEventListener('touchstart', wasTouched, false);
};

window.addEventListener('touchstart', wasTouched, false);