Closed FlorianWendelborn closed 8 years ago
Thanks @dodekeract. Yeah this is a known issue. It is unfortunately the only way to test for support on mobile.
The way that it work is it loops over the touch event 10 or 20 times really quickly while you press it to check if any force value was made. I have to do it like this because to check for support on devices like an iPhone 6 or lower that don't support force touch, they all return force values for every touch event, they just are always 0 of course. So if you touch very very lightly on an iPhone 6s and it returns all 0's, the best assumption it can make is that your device does not support 3d touch.
I'm always open to suggestions on how to make this better, but it is complicated so this is the best I came up with.
In fact I actually have to loop over the force value and not just check if it is greater than 0 but if it changes at all. This is because on some android devices they give back a "1" or "0.66666" or any other variations of force values passed back on an event. So what I actually do is get the first force value and loop over the event 10 or 20 times and if the force value changes during any of those checks then that means they support pressure. Else they have no pressure sensitive screen.
I know, it is not trivial to check for support unfortunately :sob: Im not sure if there will ever be a better way since other devices give fake / false force values.
Didn't think that non-supporting devices would simply send 0. That's unfortunate. I can understand sending 0 or 1, but 0.6666? Wtf Android.
Maybe it's possible for the button/library to continue checking on every event? Not sure if that'd break your API though, since I haven't used it yet.
@dodekeract haha right? Super weird! Yeah that could be something to consider. It could check every time you press, or have an option to. Right now once it does the test it sets a global flag that I check for other presses on the page.
My only possible issue with that is if someone has something that is called in the "unsupported" callback, that does something on the page, then it is suddenly supported again on a different click, does that break the functionality on their page for example. I almost wonder if it fails, it should at least fail on the whole page. But it could be an optional setting to have it check each press so that it could have the potential to come back from a false negative.
This will stay as is for the time being. There is no good solution for this currently, though any input from anyone is greatly appreciated!
Just wanted to let you know, that I can let that button on the website say "not supported", when pressing very very lightly on an iPhone 6S Plus. I guess that's related to the force actually being 0.0000. I suggest to change the check from (I assume)
if (force)
toif (force == null)
or something similar.