question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[DISCUSS] To find better solutions for detecting touchable device

See original GitHub issue

Brief

There are some issues reporting echarts can’t detect properly whether touch-screen device supports touch events or not.

The current detection way in zrender/src/core/env.js is not enough compatible with all kinds of devices.

And I searched on StackOverflow, but it seems there is no the best way.

Therefore, for more compatibilities, should we allow the developer to configure it manually according to what they know about their devices? For example, we may add a new option into zrender and echarts to specify whether the touch event is supported. I have no such touchable device to test these, though.

ECharts

var zr = this._zr = zrender.init(dom, {
    renderer: opts.renderer || defaultRenderer,
    devicePixelRatio: opts.devicePixelRatio,
    width: opts.width,
    height: opts.height,
    touchEventsSupported: opts.touchEventsSupported
});

ZRender overrides env.touchEventsSupported if developer has specified manually

if (opts.touchEventsSupported != null) {
    env.touchEventsSupported = !!opts.touchEventsSupported;
}

Maybe this looks a bit weird. Of course, it would be better if there could be a good way to detect the touchable device.

Others

In highcharts, it uses /(Mobile|Android|Windows Phone)/.test(navigator.userAgent) to judge isTouchDevice and uses window.TouchEvent to judge hasTouch.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
dr-itzcommented, Oct 7, 2020

We had the same problem on some Windows touch devices. Since we use custom imports with webpack, I added this one for testing (typescript):

import zRenderEnv from 'zrender/lib/core/env';
zRenderEnv.touchEventsSupported = true;

this works nicely and touch is fixed on these devices. The question: Is there any downside in force-enabling this?

0reactions
jzeroncommented, Nov 5, 2021

Microsoft Surface Hub we had to disable pointerEventsSupported in addition to enabling touchEventsSupported:

import zRenderEnv from 'zrender/lib/core/env';
zRenderEnv.touchEventsSupported = true;
zRenderEnv.pointerEventsSupported = false;
Read more comments on GitHub >

github_iconTop Results From Across the Web

[DISCUSS] To find better solutions for detecting ... - GitHub
Brief There are some issues reporting echarts can't detect properly whether touch-screen device supports touch events or not.
Read more >
How to detect touch screen device using JavaScript?
How to detect touch screen device using JavaScript?
Read more >
Detecting touch: it's the 'why', not the 'how' - Mozilla Hacks
The suggested method of detecting if a browser using Pointer Events is running on a touch-enabled device instead involves checking for the ...
Read more >
The only way to detect touch with JavaScript - codeburst
Swipe interactions for the touchers​​ So you detect for a 'touch device' and only set up swipe interaction for users with touch-enabled devices....
Read more >
Detecting Touch Devices - A 2018 Update - Peterscene
It was true in 2013 and it's still true in 2018: you can't detect with 100% accuracy whether a site visitor is using...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found