Skip to content

Commit

Permalink
EddyVerbruggen#6 Add Force Touch callbacks - added timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
EddyVerbruggen committed Dec 12, 2015
1 parent 4764ca6 commit 8b8bee6
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 5 deletions.
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,17 @@ Useful for context menu's, zooming in on images, whatnot.

```js
ThreeDeeTouch.watchForceTouches(function(result) {
console.log("force touch % " + result.force);
console.log("force touch x coordinate " + result.x);
console.log("force touch y coordinate " + result.y);
console.log("force touch % " + result.force); // 84
console.log("force touch timestamp " + result.timestamp); // 1449908744.706419
console.log("force touch x coordinate " + result.x); // 213
console.log("force touch y coordinate " + result.y); // 41
});
```

You can also track in JS which was the last element that received an `ontouchstart` event,
remember the timestamp when that happened and correlate that to the timestamp of the force touch.
If those are very close to each other you can safely assume the force touch was on that element.

### configureQuickActions
When your app starts you can add those fancy Quick Actions to the Home Screen icon.
You can configure up to four icons and they are 'cached' until you pass in a new set of icons.
Expand Down Expand Up @@ -208,6 +213,7 @@ This is the same as the `type` param of `configureQuickActions`, so it's what yo
`onHomeIconPressed` as `payload.type`. Just do something cool with that info.

## 6. Changelog
* 1.3.1 Added `timestamp` to the response of `watchForceTouches`.
* 1.3.0 You can now receive notifications when the user applies a 'Force Touch' on the webview.
* 1.2.2 Documentation on how to localize the title and subtitle of your static icons.
* 1.2.1 Documentation on how to add static icons to your app.
Expand Down
15 changes: 15 additions & 0 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ <h1>3D Touch</h1>
<p class="event listening">Connecting to Device</p>
<p class="event received">Device is Ready</p>
<button onclick="avail()">avail?</button><br/><br/>
<button onclick="watchForceTouches()">watchForceTouches</button><br/><br/>
<button onclick="enableLinkPreview()">enable link preview</button><br/><br/>
<button onclick="disableLinkPreview()">disable link preview</button><br/><br/>
<button onclick="configureQuickActions()">configure home icons</button><br/><br/>
Expand All @@ -52,6 +53,15 @@ <h1>3D Touch</h1>
ThreeDeeTouch.isAvailable(function(avail) {alert("avail? " + avail)});
}

function watchForceTouches() {
ThreeDeeTouch.watchForceTouches(function(result) {
console.log("force touch % " + result.force); // 84
console.log("force touch timestamp " + result.timestamp); // 1449908744.706419
console.log("force touch x coordinate " + result.x); // 213
console.log("force touch y coordinate " + result.y); // 41
});
}

function enableLinkPreview() {
ThreeDeeTouch.enableLinkPreview();
}
Expand All @@ -74,6 +84,11 @@ <h1>3D Touch</h1>
subtitle: 'Share like you care',
iconType: 'Share' // optional, case insensitive
},
{
type: 'search',
title: 'Search',
iconType: 'Search' // iconType is case insensitive
},
{
title: 'Show favorites',
iconTemplate: 'HeartTemplate' // from Assets catalog, note that there's also an iconType 'Love'
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cordova-plugin-3dtouch",
"version": "1.3.0",
"version": "1.3.1",
"description": "Add Quick Actions to your Home Screen which can be triggered by 3D Touch. Also, you can enable Link Preview with this plugin. Supported on iPhone6S an up.",
"cordova": {
"id": "cordova-plugin-3dtouch",
Expand Down
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version='1.0' encoding='UTF-8'?>
<plugin
id="cordova-plugin-3dtouch"
version="1.3.0"
version="1.3.1"
xmlns="http://apache.org/cordova/ns/plugins/1.0">

<name>3D Touch</name>
Expand Down
2 changes: 2 additions & 0 deletions src/ios/app/ThreeDeeTouch.m
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ - (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
[NSString stringWithFormat:@"%d", (int)percentage] , @"force",
[NSString stringWithFormat:@"%d", (int)coordinates.x], @"x",
[NSString stringWithFormat:@"%d", (int)coordinates.y], @"y",
// no need to use the touch.timestamp really since it's simply 'now'
[NSString stringWithFormat:@"%f", [[NSDate date] timeIntervalSince1970]], @"timestamp",
nil];

CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:result];
Expand Down

0 comments on commit 8b8bee6

Please sign in to comment.