@capawesome/capacitor-shake 0.0.1 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # @capawesome/capacitor-shake
1
+ # Capacitor Shake Plugin
2
2
 
3
3
  Capacitor plugin to detect shake gestures.
4
4
 
@@ -18,9 +18,14 @@ Capacitor plugin to detect shake gestures.
18
18
 
19
19
  Missing a feature? Just [open an issue](https://github.com/capawesome-team/capacitor-plugins/issues) and we'll take a look!
20
20
 
21
- ## Newsletter
21
+ ## Use Cases
22
22
 
23
- Stay up to date with the latest news and updates about the Capawesome, Capacitor, and Ionic ecosystem by subscribing to our [Capawesome Newsletter](https://cloud.capawesome.io/newsletter/).
23
+ The Shake plugin is typically used to trigger an action when the user shakes the device, for example:
24
+
25
+ - **Feedback and bug reporting**: Let users shake the device to open a feedback or bug report dialog.
26
+ - **Debug menus**: Open a hidden developer or debug menu in internal builds when the device is shaken.
27
+ - **Undo actions**: Offer a shake-to-undo interaction, a gesture many users already know from iOS.
28
+ - **Refresh content**: Reload data or shuffle content when a shake gesture is detected.
24
29
 
25
30
  ## Compatibility
26
31
 
@@ -60,6 +65,12 @@ No configuration required for this plugin.
60
65
 
61
66
  ## Usage
62
67
 
68
+ The following examples show how to detect shake gestures and stop detecting them.
69
+
70
+ ### Detect shake gestures
71
+
72
+ Attach a `shake` listener and start watching for shake gestures. Use the `sensitivity` option to control how strong a shake must be to trigger an event (see [Sensitivity Levels](#sensitivity-levels)). Only available on Android and iOS:
73
+
63
74
  ```typescript
64
75
  import { Shake } from '@capawesome/capacitor-shake';
65
76
 
@@ -69,6 +80,14 @@ const startWatching = async () => {
69
80
  });
70
81
  await Shake.startWatching({ sensitivity: 'medium' });
71
82
  };
83
+ ```
84
+
85
+ ### Stop detecting shake gestures
86
+
87
+ Stop watching and remove all listeners when you no longer need shake detection, for example when the user leaves the corresponding screen. The sensor is only active while you are watching, so this keeps the plugin battery-friendly:
88
+
89
+ ```typescript
90
+ import { Shake } from '@capawesome/capacitor-shake';
72
91
 
73
92
  const stopWatching = async () => {
74
93
  await Shake.stopWatching();
@@ -80,10 +99,10 @@ const stopWatching = async () => {
80
99
 
81
100
  <docgen-index>
82
101
 
83
- * [`addListener('shake', ...)`](#addlistenershake-)
84
- * [`removeAllListeners()`](#removealllisteners)
85
102
  * [`startWatching(...)`](#startwatching)
86
103
  * [`stopWatching()`](#stopwatching)
104
+ * [`addListener('shake', ...)`](#addlistenershake-)
105
+ * [`removeAllListeners()`](#removealllisteners)
87
106
  * [Interfaces](#interfaces)
88
107
  * [Type Aliases](#type-aliases)
89
108
 
@@ -92,69 +111,69 @@ const stopWatching = async () => {
92
111
  <docgen-api>
93
112
  <!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
94
113
 
95
- ### addListener('shake', ...)
114
+ ### startWatching(...)
96
115
 
97
116
  ```typescript
98
- addListener(eventName: 'shake', listenerFunc: () => void) => Promise<PluginListenerHandle>
117
+ startWatching(options?: StartWatchingOptions | undefined) => Promise<void>
99
118
  ```
100
119
 
101
- Called when a shake gesture is detected.
120
+ Start watching for shake gestures.
102
121
 
103
122
  Only available on Android and iOS.
104
123
 
105
- | Param | Type |
106
- | ------------------ | -------------------------- |
107
- | **`eventName`** | <code>'shake'</code> |
108
- | **`listenerFunc`** | <code>() =&gt; void</code> |
109
-
110
- **Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt;</code>
124
+ | Param | Type |
125
+ | ------------- | --------------------------------------------------------------------- |
126
+ | **`options`** | <code><a href="#startwatchingoptions">StartWatchingOptions</a></code> |
111
127
 
112
128
  **Since:** 0.1.0
113
129
 
114
130
  --------------------
115
131
 
116
132
 
117
- ### removeAllListeners()
133
+ ### stopWatching()
118
134
 
119
135
  ```typescript
120
- removeAllListeners() => Promise<void>
136
+ stopWatching() => Promise<void>
121
137
  ```
122
138
 
123
- Remove all listeners for this plugin.
139
+ Stop watching for shake gestures.
140
+
141
+ Only available on Android and iOS.
124
142
 
125
143
  **Since:** 0.1.0
126
144
 
127
145
  --------------------
128
146
 
129
147
 
130
- ### startWatching(...)
148
+ ### addListener('shake', ...)
131
149
 
132
150
  ```typescript
133
- startWatching(options?: StartWatchingOptions | undefined) => Promise<void>
151
+ addListener(eventName: 'shake', listenerFunc: () => void) => Promise<PluginListenerHandle>
134
152
  ```
135
153
 
136
- Start watching for shake gestures.
154
+ Called when a shake gesture is detected.
137
155
 
138
156
  Only available on Android and iOS.
139
157
 
140
- | Param | Type |
141
- | ------------- | --------------------------------------------------------------------- |
142
- | **`options`** | <code><a href="#startwatchingoptions">StartWatchingOptions</a></code> |
158
+ | Param | Type |
159
+ | ------------------ | -------------------------- |
160
+ | **`eventName`** | <code>'shake'</code> |
161
+ | **`listenerFunc`** | <code>() =&gt; void</code> |
162
+
163
+ **Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt;</code>
143
164
 
144
165
  **Since:** 0.1.0
145
166
 
146
167
  --------------------
147
168
 
148
169
 
149
- ### stopWatching()
170
+ ### removeAllListeners()
150
171
 
151
172
  ```typescript
152
- stopWatching() => Promise<void>
173
+ removeAllListeners() => Promise<void>
153
174
  ```
154
175
 
155
- Stop watching for shake gestures.
156
-
157
- Only available on Android and iOS.
176
+ Remove all listeners for this plugin.
158
177
 
159
178
  **Since:** 0.1.0
160
179
 
@@ -164,13 +183,6 @@ Only available on Android and iOS.
164
183
  ### Interfaces
165
184
 
166
185
 
167
- #### PluginListenerHandle
168
-
169
- | Prop | Type |
170
- | ------------ | ----------------------------------------- |
171
- | **`remove`** | <code>() =&gt; Promise&lt;void&gt;</code> |
172
-
173
-
174
186
  #### StartWatchingOptions
175
187
 
176
188
  | Prop | Type | Description | Default | Since |
@@ -178,6 +190,13 @@ Only available on Android and iOS.
178
190
  | **`sensitivity`** | <code><a href="#sensitivity">Sensitivity</a></code> | The sensitivity of the shake detection. Use `'light'` to detect gentle shakes and `'hard'` to only detect strong shakes. Only available on Android and iOS. | <code>'medium'</code> | 0.1.0 |
179
191
 
180
192
 
193
+ #### PluginListenerHandle
194
+
195
+ | Prop | Type |
196
+ | ------------ | ----------------------------------------- |
197
+ | **`remove`** | <code>() =&gt; Promise&lt;void&gt;</code> |
198
+
199
+
181
200
  ### Type Aliases
182
201
 
183
202
 
@@ -195,6 +214,42 @@ The `sensitivity` option controls how strong a shake must be to emit a `shake` e
195
214
  - `medium`: A moderate shake is required to trigger an event (default).
196
215
  - `hard`: Only a strong shake triggers an event.
197
216
 
217
+ ## FAQ
218
+
219
+ ### How is this plugin different from other similar plugins?
220
+
221
+ It focuses on doing one thing well: detecting physical shake gestures on Android and iOS through a single, fully typed API. You can tune how strong a shake must be with three sensitivity levels, and the motion sensor only runs between `startWatching(...)` and `stopWatching()`, so it stays battery-friendly. It is actively maintained against the latest Capacitor version, giving you consistent shake behavior on both platforms from one dependency.
222
+
223
+ ### Which platforms are supported by the Shake plugin?
224
+
225
+ The plugin is available on Android and iOS. On the Web, all methods reject as unimplemented, since browsers do not provide a comparable shake detection API.
226
+
227
+ ### Does shake detection drain the battery?
228
+
229
+ No, the plugin is designed to be battery-friendly. The motion sensor is only active between `startWatching(...)` and `stopWatching()`, so no sensor data is processed while you are not watching for shakes. Remember to call `stopWatching()` and `removeAllListeners()` when you no longer need shake detection.
230
+
231
+ ### How can I control how strong a shake must be?
232
+
233
+ Pass the `sensitivity` option to `startWatching(...)`. Use `light` to detect gentle shakes, `medium` (the default) for moderate shakes, or `hard` to only detect strong shakes. See [Sensitivity Levels](#sensitivity-levels) for details.
234
+
235
+ ### Do I need any permissions to detect shake gestures?
236
+
237
+ No, the plugin does not require any additional permissions or privacy descriptions on Android or iOS. You can install it and start watching for shake gestures right away.
238
+
239
+ ### Can I use this plugin with Ionic, React, Vue or Angular?
240
+
241
+ Yes, the plugin is framework-agnostic. It works in any Capacitor app regardless of the web framework, including Ionic with Angular, React, or Vue, as well as plain JavaScript projects.
242
+
243
+ ## Related Plugins
244
+
245
+ - [Accelerometer](https://capawesome.io/docs/sdks/capacitor/accelerometer/): Capture the acceleration force along the x, y, and z axes.
246
+ - [Gyroscope](https://capawesome.io/docs/sdks/capacitor/gyroscope/): Read the device's gyroscope sensor.
247
+ - [Haptics](https://capawesome.io/docs/sdks/capacitor/haptics/): Provide haptic feedback such as impacts, notifications, and vibrations.
248
+
249
+ ## Newsletter
250
+
251
+ Stay up to date with the latest news and updates about the Capawesome, Capacitor, and Ionic ecosystem by subscribing to our [Capawesome Newsletter](https://cloud.capawesome.io/newsletter/).
252
+
198
253
  ## Changelog
199
254
 
200
255
  See [CHANGELOG.md](https://github.com/capawesome-team/capacitor-plugins/blob/main/packages/shake/CHANGELOG.md).
@@ -30,7 +30,7 @@ android {
30
30
  buildTypes {
31
31
  release {
32
32
  minifyEnabled false
33
- proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
33
+ proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
34
34
  }
35
35
  }
36
36
  lintOptions {
package/dist/docs.json CHANGED
@@ -11,35 +11,30 @@
11
11
  ],
12
12
  "methods": [
13
13
  {
14
- "name": "addListener",
15
- "signature": "(eventName: 'shake', listenerFunc: () => void) => Promise<PluginListenerHandle>",
14
+ "name": "startWatching",
15
+ "signature": "(options?: StartWatchingOptions | undefined) => Promise<void>",
16
16
  "parameters": [
17
17
  {
18
- "name": "eventName",
19
- "docs": "",
20
- "type": "'shake'"
21
- },
22
- {
23
- "name": "listenerFunc",
18
+ "name": "options",
24
19
  "docs": "",
25
- "type": "() => void"
20
+ "type": "StartWatchingOptions | undefined"
26
21
  }
27
22
  ],
28
- "returns": "Promise<PluginListenerHandle>",
23
+ "returns": "Promise<void>",
29
24
  "tags": [
30
25
  {
31
26
  "name": "since",
32
27
  "text": "0.1.0"
33
28
  }
34
29
  ],
35
- "docs": "Called when a shake gesture is detected.\n\nOnly available on Android and iOS.",
30
+ "docs": "Start watching for shake gestures.\n\nOnly available on Android and iOS.",
36
31
  "complexTypes": [
37
- "PluginListenerHandle"
32
+ "StartWatchingOptions"
38
33
  ],
39
- "slug": "addlistenershake-"
34
+ "slug": "startwatching"
40
35
  },
41
36
  {
42
- "name": "removeAllListeners",
37
+ "name": "stopWatching",
43
38
  "signature": "() => Promise<void>",
44
39
  "parameters": [],
45
40
  "returns": "Promise<void>",
@@ -49,35 +44,40 @@
49
44
  "text": "0.1.0"
50
45
  }
51
46
  ],
52
- "docs": "Remove all listeners for this plugin.",
47
+ "docs": "Stop watching for shake gestures.\n\nOnly available on Android and iOS.",
53
48
  "complexTypes": [],
54
- "slug": "removealllisteners"
49
+ "slug": "stopwatching"
55
50
  },
56
51
  {
57
- "name": "startWatching",
58
- "signature": "(options?: StartWatchingOptions | undefined) => Promise<void>",
52
+ "name": "addListener",
53
+ "signature": "(eventName: 'shake', listenerFunc: () => void) => Promise<PluginListenerHandle>",
59
54
  "parameters": [
60
55
  {
61
- "name": "options",
56
+ "name": "eventName",
62
57
  "docs": "",
63
- "type": "StartWatchingOptions | undefined"
58
+ "type": "'shake'"
59
+ },
60
+ {
61
+ "name": "listenerFunc",
62
+ "docs": "",
63
+ "type": "() => void"
64
64
  }
65
65
  ],
66
- "returns": "Promise<void>",
66
+ "returns": "Promise<PluginListenerHandle>",
67
67
  "tags": [
68
68
  {
69
69
  "name": "since",
70
70
  "text": "0.1.0"
71
71
  }
72
72
  ],
73
- "docs": "Start watching for shake gestures.\n\nOnly available on Android and iOS.",
73
+ "docs": "Called when a shake gesture is detected.\n\nOnly available on Android and iOS.",
74
74
  "complexTypes": [
75
- "StartWatchingOptions"
75
+ "PluginListenerHandle"
76
76
  ],
77
- "slug": "startwatching"
77
+ "slug": "addlistenershake-"
78
78
  },
79
79
  {
80
- "name": "stopWatching",
80
+ "name": "removeAllListeners",
81
81
  "signature": "() => Promise<void>",
82
82
  "parameters": [],
83
83
  "returns": "Promise<void>",
@@ -87,30 +87,14 @@
87
87
  "text": "0.1.0"
88
88
  }
89
89
  ],
90
- "docs": "Stop watching for shake gestures.\n\nOnly available on Android and iOS.",
90
+ "docs": "Remove all listeners for this plugin.",
91
91
  "complexTypes": [],
92
- "slug": "stopwatching"
92
+ "slug": "removealllisteners"
93
93
  }
94
94
  ],
95
95
  "properties": []
96
96
  },
97
97
  "interfaces": [
98
- {
99
- "name": "PluginListenerHandle",
100
- "slug": "pluginlistenerhandle",
101
- "docs": "",
102
- "tags": [],
103
- "methods": [],
104
- "properties": [
105
- {
106
- "name": "remove",
107
- "tags": [],
108
- "docs": "",
109
- "complexTypes": [],
110
- "type": "() => Promise<void>"
111
- }
112
- ]
113
- },
114
98
  {
115
99
  "name": "StartWatchingOptions",
116
100
  "slug": "startwatchingoptions",
@@ -146,6 +130,22 @@
146
130
  "type": "Sensitivity"
147
131
  }
148
132
  ]
133
+ },
134
+ {
135
+ "name": "PluginListenerHandle",
136
+ "slug": "pluginlistenerhandle",
137
+ "docs": "",
138
+ "tags": [],
139
+ "methods": [],
140
+ "properties": [
141
+ {
142
+ "name": "remove",
143
+ "tags": [],
144
+ "docs": "",
145
+ "complexTypes": [],
146
+ "type": "() => Promise<void>"
147
+ }
148
+ ]
149
149
  }
150
150
  ],
151
151
  "enums": [],
@@ -4,35 +4,35 @@ import type { PluginListenerHandle } from '@capacitor/core';
4
4
  */
5
5
  export interface ShakePlugin {
6
6
  /**
7
- * Called when a shake gesture is detected.
7
+ * Start watching for shake gestures.
8
8
  *
9
9
  * Only available on Android and iOS.
10
10
  *
11
11
  * @since 0.1.0
12
12
  */
13
- addListener(eventName: 'shake', listenerFunc: () => void): Promise<PluginListenerHandle>;
13
+ startWatching(options?: StartWatchingOptions): Promise<void>;
14
14
  /**
15
- * Remove all listeners for this plugin.
15
+ * Stop watching for shake gestures.
16
+ *
17
+ * Only available on Android and iOS.
16
18
  *
17
19
  * @since 0.1.0
18
20
  */
19
- removeAllListeners(): Promise<void>;
21
+ stopWatching(): Promise<void>;
20
22
  /**
21
- * Start watching for shake gestures.
23
+ * Called when a shake gesture is detected.
22
24
  *
23
25
  * Only available on Android and iOS.
24
26
  *
25
27
  * @since 0.1.0
26
28
  */
27
- startWatching(options?: StartWatchingOptions): Promise<void>;
29
+ addListener(eventName: 'shake', listenerFunc: () => void): Promise<PluginListenerHandle>;
28
30
  /**
29
- * Stop watching for shake gestures.
30
- *
31
- * Only available on Android and iOS.
31
+ * Remove all listeners for this plugin.
32
32
  *
33
33
  * @since 0.1.0
34
34
  */
35
- stopWatching(): Promise<void>;
35
+ removeAllListeners(): Promise<void>;
36
36
  }
37
37
  /**
38
38
  * @since 0.1.0
@@ -1 +1 @@
1
- {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["import type { PluginListenerHandle } from '@capacitor/core';\n\n/**\n * @since 0.1.0\n */\nexport interface ShakePlugin {\n /**\n * Called when a shake gesture is detected.\n *\n * Only available on Android and iOS.\n *\n * @since 0.1.0\n */\n addListener(\n eventName: 'shake',\n listenerFunc: () => void,\n ): Promise<PluginListenerHandle>;\n /**\n * Remove all listeners for this plugin.\n *\n * @since 0.1.0\n */\n removeAllListeners(): Promise<void>;\n /**\n * Start watching for shake gestures.\n *\n * Only available on Android and iOS.\n *\n * @since 0.1.0\n */\n startWatching(options?: StartWatchingOptions): Promise<void>;\n /**\n * Stop watching for shake gestures.\n *\n * Only available on Android and iOS.\n *\n * @since 0.1.0\n */\n stopWatching(): Promise<void>;\n}\n\n/**\n * @since 0.1.0\n */\nexport interface StartWatchingOptions {\n /**\n * The sensitivity of the shake detection.\n *\n * Use `'light'` to detect gentle shakes and `'hard'` to only detect strong shakes.\n *\n * Only available on Android and iOS.\n *\n * @since 0.1.0\n * @default 'medium'\n * @example 'medium'\n */\n sensitivity?: Sensitivity;\n}\n\n/**\n * @since 0.1.0\n */\nexport type Sensitivity = 'hard' | 'light' | 'medium';\n"]}
1
+ {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["import type { PluginListenerHandle } from '@capacitor/core';\n\n/**\n * @since 0.1.0\n */\nexport interface ShakePlugin {\n /**\n * Start watching for shake gestures.\n *\n * Only available on Android and iOS.\n *\n * @since 0.1.0\n */\n startWatching(options?: StartWatchingOptions): Promise<void>;\n /**\n * Stop watching for shake gestures.\n *\n * Only available on Android and iOS.\n *\n * @since 0.1.0\n */\n stopWatching(): Promise<void>;\n /**\n * Called when a shake gesture is detected.\n *\n * Only available on Android and iOS.\n *\n * @since 0.1.0\n */\n addListener(\n eventName: 'shake',\n listenerFunc: () => void,\n ): Promise<PluginListenerHandle>;\n /**\n * Remove all listeners for this plugin.\n *\n * @since 0.1.0\n */\n removeAllListeners(): Promise<void>;\n}\n\n/**\n * @since 0.1.0\n */\nexport interface StartWatchingOptions {\n /**\n * The sensitivity of the shake detection.\n *\n * Use `'light'` to detect gentle shakes and `'hard'` to only detect strong shakes.\n *\n * Only available on Android and iOS.\n *\n * @since 0.1.0\n * @default 'medium'\n * @example 'medium'\n */\n sensitivity?: Sensitivity;\n}\n\n/**\n * @since 0.1.0\n */\nexport type Sensitivity = 'hard' | 'light' | 'medium';\n"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@capawesome/capacitor-shake",
3
- "version": "0.0.1",
4
- "description": "Capacitor plugin to detect shake gestures.",
3
+ "version": "0.1.1",
4
+ "description": "Capacitor plugin to detect shake gestures on Android and iOS.",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",
7
7
  "types": "dist/esm/index.d.ts",
@@ -33,11 +33,19 @@
33
33
  "url": "https://opencollective.com/capawesome"
34
34
  }
35
35
  ],
36
- "homepage": "https://capawesome.io/docs/plugins/shake/",
36
+ "homepage": "https://capawesome.io/docs/sdks/capacitor/shake/",
37
37
  "keywords": [
38
38
  "capacitor",
39
39
  "plugin",
40
- "native"
40
+ "native",
41
+ "capacitor-plugin",
42
+ "shake",
43
+ "shake detection",
44
+ "shake gesture",
45
+ "shake event",
46
+ "motion detection",
47
+ "accelerometer",
48
+ "sensor"
41
49
  ],
42
50
  "scripts": {
43
51
  "verify": "npm run verify:ios && npm run verify:android && npm run verify:web",