[DISCUSS] To find better solutions for detecting touchable device
- Dominant language
- TypeScript
- Stars
- 67.3k
- Forks
- 19.8k
- Avg merge
- 11d 14h
- Merged PRs (30d)
- 8
Description
### Brief
There are some issues reporting echarts can't detect properly whether touch-screen device supports touch events or not.
- #7406
- #9301
- #12166
- #12823
The current detection way in [`zrender/src/core/env.js`](https://github.com/ecomfe/zrender/blob/master/src/core/env.js#L149) is not enough compatible with all kinds of devices.
And I searched on [StackOverflow](https://stackoverflow.com/questions/4817029/whats-the-best-way-to-detect-a-touch-screen-device-using-javascript), 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**
```js
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
```js
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`.
Contributor guide
Assessment
This issue has not been assessed yet.