问题
I'm trying to completely remove the vibration that occurs on a long press of an element in a mobile browser.
Specifically, I have an image that I'm adding my own long-press functionality to, but the subtle short-vibrate that happens by default is interfering and I need to disable it.
I've successfully stopped the usual context menu from appearing by overriding it as follows:
window.oncontextmenu = function (event) {
event.preventDefault();
event.stopPropagation();
return false;
};
I've also added CSS to stop highlights and text selection etc - but I haven't been able to figure out what's causing the default vibrate after a few hundred ms.
Is there another lifecycle event that's popped on a long-press in a mobile browser, in or around oncontextmenu?
Full plunker Example here, long-press on the image from a mobile browser (I'm using chrome on Android) to see what I mean: https://plnkr.co/edit/y1KVPltTzEhQeMWGMa1F?p=preview
回答1:
I have been going through the same issue for the last day or so with my own React App, I have gone through the same steps as you with no success. Currently I have an Android app that is opening up the React web app using webView, what I have found is:
I am fairly sure what you(we)'re trying to do can't be done purely though ReactJS alone, the solution I used, as I am loading my ReactJS app through an Android app was to add the method:
android:hapticFeedbackEnabled="false"
to my AndroidManifest.xml file (docs here: https://developer.android.com/reference/android/view/View#attr_android:hapticFeedbackEnabled)
If you want to read more into native Android solutions there is a section of the Android Cookbook that focuses on custom haptic feedback: http://androidcookbook.com/Recipe.seam?recipeId=1242
Alternatively, there are solutions available through React-Native. React Native has a built in Vibration Module, config docs available here: https://facebook.github.io/react-native/docs/vibration
来源:https://stackoverflow.com/questions/46087752/how-to-completely-remove-mobile-browser-long-press-vibration