Skip to content

Commit 465bdc2

Browse files
#4 doc, demo, tweaks
1 parent d1b3377 commit 465bdc2

File tree

7 files changed

+61
-8
lines changed

7 files changed

+61
-8
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,29 @@ TapticEngine.impact({
6767
});
6868
```
6969

70+
#### `gestureSelection[start | changed | end]`
71+
The functions above are great for one-time events, not so much for gestures.
72+
Say for instance you want to tie this plugin to a range slider, then you can
73+
'start' the selection first, invoke 'changed' upon changes in the range (there may
74+
be many during one gesture), then 'end' when the slider changes are done.
75+
76+
Tell the taptic engine that a gesture for a selection change is starting.
77+
78+
```js
79+
TapticEngine.gestureSelectionStart();
80+
```
81+
82+
Tell the taptic engine that a selection changed during a gesture.
83+
84+
```js
85+
TapticEngine.gestureSelectionChanged();
86+
```
87+
88+
Tell the taptic engine we are done with a gesture. This needs to be called lest resources are not properly recycled.
89+
90+
```js
91+
TapticEngine.gestureSelectionEnd();
92+
```
7093

7194
### Unofficial API (requires at least iPhone 6s)
7295
__BEWARE__ This uses an undocumented feature which may get your app rejected when reviewed by Apple.
@@ -97,6 +120,7 @@ This triggers the 'Nope' effect you get when fi. force touching a home icon whic
97120
Codewise this is exactly the same as `weakBoom` and `strongBoom`, except for the function name of course.
98121

99122
## Changelog
123+
* 2.1.0 [Max Lynch](https://github.com/mlynch) added `gestureSelection*` methods. See the doc above why those matter!
100124
* 2.0.1 A crash was fixed for iPhone 7 devices (official API), thanks [Max Lynch](https://github.com/mlynch)!
101125
* 2.0.0 Added official API for iPhone 7. Moved the old API to `TapticEngine.unofficial.*`. Requires Xcode 8 to build.
102126
* 1.0.0 Initial release, unofficial API only. Compatible with any Xcode version.

demo/index.html

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,20 @@ <h1>Taptic Engine</h1>
1212
<p class="event listening">Connecting to Device</p>
1313
<p class="event received">Device is Ready</p>
1414

15-
<h3>Unofficial API (iPhone >= 6s)</h3>
15+
<h2>Unofficial API (iPhone >= 6s)</h2>
1616
<button ontouchstart="weakBoom()">weak boom ('Peek')</button><br/><br/>
1717
<button ontouchstart="strongBoom()">strong boom ('Pop')</button><br/><br/>
1818
<button ontouchstart="burst()">burst ('Nope!')</button><br/><br/>
1919

20-
<h3>Official API (iPhone >= 7)</h3>
20+
<h2>Official API (iPhone >= 7)</h2>
2121
<button ontouchstart="notification('error')">notification</button><br/><br/>
2222
<button ontouchstart="selection()">selection</button><br/><br/>
2323
<button ontouchstart="impact('heavy')">impact</button><br/><br/>
24+
25+
<h3>Gesture selection</h3>
26+
<button ontouchstart="gestureSelectionStart()">start</button>&nbsp;
27+
<button ontouchstart="gestureSelectionChanged()">changes</button>&nbsp;
28+
<button ontouchstart="gestureSelectionEnd()">end</button><br/><br/>
2429
</div>
2530
</div>
2631
<script type="text/javascript" src="cordova.js"></script>
@@ -74,6 +79,25 @@ <h3>Official API (iPhone >= 7)</h3>
7479
}, onSuccess, onError);
7580
}
7681
}
82+
83+
function gestureSelectionStart() {
84+
if (window.TapticEngine) {
85+
TapticEngine.gestureSelectionStart(onSuccess, onError);
86+
}
87+
}
88+
89+
function gestureSelectionChanged() {
90+
if (window.TapticEngine) {
91+
TapticEngine.gestureSelectionChanged(onSuccess, onError);
92+
}
93+
}
94+
95+
function gestureSelectionEnd() {
96+
if (window.TapticEngine) {
97+
TapticEngine.gestureSelectionEnd(onSuccess, onError);
98+
}
99+
}
100+
77101
</script>
78102
</body>
79103
</html>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cordova-plugin-taptic-engine",
3-
"version": "2.0.1",
3+
"version": "2.1.0",
44
"description": "Use Apple's Taptic Engine to vibrate your iPhone 6s (or up) in a variety of ways.",
55
"cordova": {
66
"id": "cordova-plugin-taptic-engine",

plugin.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version='1.0' encoding='UTF-8'?>
22
<plugin
33
id="cordova-plugin-taptic-engine"
4-
version="2.0.1"
4+
version="2.1.0"
55
xmlns="http://apache.org/cordova/ns/plugins/1.0">
66

77
<name>Taptic Engine</name>

src/ios/TapticEngine.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
- (void) selection:(CDVInvokedUrlCommand*)command;
88
- (void) impact:(CDVInvokedUrlCommand*)command;
99

10+
- (void) gestureSelectionStart:(CDVInvokedUrlCommand*)command;
11+
- (void) gestureSelectionChanged:(CDVInvokedUrlCommand*)command;
12+
- (void) gestureSelectionEnd:(CDVInvokedUrlCommand*)command;
13+
1014
// Unofficial API
1115
- (void) weakBoom:(CDVInvokedUrlCommand*)command;
1216
- (void) strongBoom:(CDVInvokedUrlCommand*)command;

src/ios/TapticEngine.m

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ - (void) selection:(CDVInvokedUrlCommand *)command
6262
*/
6363
- (void) gestureSelectionStart:(CDVInvokedUrlCommand *)command
6464
{
65-
if(!self.selectionGenerator) {
65+
if (!self.selectionGenerator) {
6666
self.selectionGenerator = [UISelectionFeedbackGenerator new];
6767
if (self.selectionGenerator == nil || isSimulator) {
6868
[self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Unsupported Operating System"] callbackId:command.callbackId];
@@ -72,7 +72,6 @@ - (void) gestureSelectionStart:(CDVInvokedUrlCommand *)command
7272

7373
[self.selectionGenerator prepare];
7474

75-
7675
[self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK] callbackId:command.callbackId];
7776
}
7877

@@ -82,8 +81,8 @@ - (void) gestureSelectionStart:(CDVInvokedUrlCommand *)command
8281
*/
8382
- (void) gestureSelectionChanged:(CDVInvokedUrlCommand *)command
8483
{
85-
if(!self.selectionGenerator) {
86-
[self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Unsupported Operating System"] callbackId:command.callbackId];
84+
if (!self.selectionGenerator) {
85+
[self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"Invoke gestureSelectionStart first"] callbackId:command.callbackId];
8786
return;
8887
}
8988

www/TapticEngine.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@ TapticEngine.prototype.impact = function (options, onSuccess, onFail) {
3535
TapticEngine.prototype.gestureSelectionStart = function (onSuccess, onFail) {
3636
exec(onSuccess, onFail, "TapticEngine", "gestureSelectionStart", []);
3737
};
38+
3839
TapticEngine.prototype.gestureSelectionChanged = function (onSuccess, onFail) {
3940
exec(onSuccess, onFail, "TapticEngine", "gestureSelectionChanged", []);
4041
};
42+
4143
TapticEngine.prototype.gestureSelectionEnd = function (onSuccess, onFail) {
4244
exec(onSuccess, onFail, "TapticEngine", "gestureSelectionEnd", []);
4345
};

0 commit comments

Comments
 (0)