shake.js
shake.js copied to clipboard
Simplify the API?
The current flow for detecting a shake looks more complicated than it needs to be:
var myShakeEvent = new Shake({ ... senstivity options ... });
window.addEventListener('shake', shakeEventDidOccur, false);
window.removeEventListener('shake', shakeEventDidOccur, false);
myShakeEvent.stop();
@leecrossley's cordova-plugin-shake-detection has a minimally simple API:
shake.startWatch(shakeEventDidOccur, /* ... sensitivity options ... */);
shake.stopWatch();
Could the API be simplified?
This is indeed on my road-map. I plan to remove the shake custom event, and simply allow folks to pass their callbacks on instantiation.
Great to hear!
I could imagine a use case for having more Shake instances instead of a singleton (e.g. supporting light shakes vs. heavy shakes), but the shake event doesn't receive any parameters, so it couldn't distinguish how it was called anyway.
Will the request full screen from the API work with the shake event ?
This isn't really related to this issue. Not quite sure I understand your question, but you can execute any code you want when the event occurs. Please see the readme for how to use the plugin.
I tried the proximity api to execute fullscreen , it did not happen
What does that have to do with this plugin?
As far as I understand that's a limitation of the full screen API, not this plugin. Shake is a custom event, so not necessarily the same as a native click.
Regardless, this has nothing to do with this issue. Please open a new issue if you would like to discuss this further.
I'm sorry @abkhan25 but the comments about full-screen and whatnot are off-topic here.
@alexgibson: feel free to delete the clutter, including this comment of mine.
I can here to propose a callback instead of custom event as you mentioned in second comment. I need to play a sound when user shakes, but it's not possible with a custom event. It requires a user interaction. Which I guess device motion is. So a callback should fix that.
up up, this is important issue