Documentation Index
Fetch the complete documentation index at: https://docs.rebellapp.com/llms.txt
Use this file to discover all available pages before exploring further.
Use this API to stop watching for device shake events that were registered with my.watchShake().
Parameters
This API takes no parameters.
Code Example
Basic Usage
// Stop watching for shakes
my.offWatchShake();
Toggle Shake Detection
Page({
data: {
shakeEnabled: false
},
toggleShake() {
if (this.data.shakeEnabled) {
my.offWatchShake();
this.setData({ shakeEnabled: false });
} else {
this.enableShake();
this.setData({ shakeEnabled: true });
}
},
enableShake() {
my.watchShake({
success: () => {
this.handleShake();
if (this.data.shakeEnabled) {
this.enableShake();
}
}
});
},
handleShake() {
my.vibrate();
console.log('Shake detected!');
}
});
Page Lifecycle Management
Page({
onShow() {
this.startShakeWatch();
},
onHide() {
// Stop watching when page is hidden
my.offWatchShake();
},
startShakeWatch() {
my.watchShake({
success: () => {
this.onShake();
this.startShakeWatch();
}
});
},
onShake() {
// Handle shake event
}
});
Always call my.offWatchShake() when leaving a page or when shake detection is no longer needed to conserve battery and resources.
my.watchShake
Watch for shake events
my.vibrate
Trigger device vibration