npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cordova-plugin-forcetouch

v1.2.4

Published

Cordova Plugin iOS Force Touch

Downloads

36

Readme

Cordova iOS Force Touch Plugin

(cordova-plugin-forcetouch v1.2.4)

 

Author

Matteo Pisani
E-mail: [email protected]
Linkedin: http://www.linkedin.com/in/matteopisani

Description

This plugin allows developer to manage Force Touch readable values of supported Apple devices.

It returns Force Touch data, prefixed with "ForceTouch" object, for each Touch Point available on the screen.

Supported Devices (Apple)

  • iPhone 7
  • iPhone 7 Plus
  • iPhone 6S
  • iPhone 6S Plus
  • iPad Pro

Supported OS

  • iOS >= 9.0

Starting

Create a new Cordova Project

$ cordova create ForceTouchApplication com.development.forcetouch ForceTouchApplication

Installing the plugin (from GIT)

Clone the plugin

$ git clone https://github.com/xonoxitron/cordova-plugin-forcetouch.git

Install the plugin

$ cd ForceTouchApplication
$ cordova -d plugin add ../cordova-plugin-forcetouch

Or alternatively

Installing the plugin (from NPM)

Clone the plugin

$ cd ForceTouchApplication
$ git clone cordova-plugin-forcetouch

Using

Edit ~/ForceTouchApplication/www/yourfile.js and add the following code inside an onDeviceReady event

document.addEventListener('deviceready', function ()
{
  // on cordova start, asks plugin continuosly for ForceTouchData
  setInterval(getForceTouchData,15); // 15? => 1000ms/15 = ~60fps;
}, false);

// getForceTouchData Method
function getForceTouchData()
{
  ForceTouch.getForceTouchData(function (ForceTouchData)
  {
    // checking if device allows ForceTouch interaction
    var forceTouchCapability = '';
    switch(ForceTouchData.forceTouchCapability)
    {
      case '0':
        forceTouchCapability = 'Unknown';
      break;
      case '1':
        forceTouchCapability = 'Unavailable';
      break;
      case '2':
        forceTouchCapability = 'Available';
      break;
    }

    document.getElementById('forceTouchCapability').innerHTML = forceTouchCapability;

    if(ForceTouchData.touches[0])
    {
      // setting output values for first Touch Point at index:0 -> "ForceTouchData.touches[0]"
      document.getElementById('tapCount').innerHTML = ForceTouchData.touches[0].tapCount;
      document.getElementById('timestamp').innerHTML = ForceTouchData.touches[0].timestamp;
      document.getElementById('phase').innerHTML = ForceTouchData.touches[0].phase;
      document.getElementById('force').innerHTML = ForceTouchData.touches[0].force;
      document.getElementById('maximumPossibleForce').innerHTML = ForceTouchData.touches[0].maximumPossibleForce;

      var force = parseFloat(ForceTouchData.touches[0].force);
      // checking if No Touch or StandardTouch or Force Touch
      if(ForceTouchData.touches[0].tapCount == 0 && force == 0.0)
        document.getElementById('touchType').innerHTML = 'No Touch';
      else
      if((ForceTouchData.touches[0].tapCount > 0 && force == 0.0) || (force > 0.0 && force < 0.08))
        document.getElementById('touchType').innerHTML = 'Standard Touch';
      else
      if(force > 0.08)
        document.getElementById('touchType').innerHTML = 'Force Touch';

      // printing Touch Point position coordinates
      console.log("x: " + ForceTouchData.touches[0].position.x + " ; " + "y: " + ForceTouchData.touches[0].position.y);
    }
    else
    {
      // no Touch Point available -> resetting output values
      document.getElementById('tapCount').innerHTML = '0';
      document.getElementById('timestamp').innerHTML = '0.000000';
      document.getElementById('phase').innerHTML = '0';
      document.getElementById('force').innerHTML = '0.000000';
      document.getElementById('maximumPossibleForce').innerHTML = '0.000000';
      document.getElementById('touchType').innerHTML = 'No Touch';
    }
    // printing ForceTouchData output for each Touch Point available on screen
    console.log(JSON.stringify(ForceTouchData.touches));
  });
}

Testing

Install iOS platform

cordova platform add ios

Run the code

cordova run ios

Or

cordova run ios --device

Demo Video

cordova-plugin-forcetouch test application running on iPhone 6S)

Test Application

  • Inside the path ~/cordova-plugin-forcetouch/test/ForceTouchApplication there's the XCode iOS test application, just open it, build it, connect your device and deploy it in.

  • When test application opens, it will start immediatly to acquire ForceTouchData (object).

  • Cordova core brings to JavaScript the object in question by calling through API Force Touch Properties of UITouch Class.

  • By pressing the touchscreen, if your device is supported, you should read each of the ForceTouchData Properties listed below the "DEVICE IS READY".

  • Phone 5,1 (No ForceTouch)

 

  • iPhone 8,1 (ForceTouch Supported)

 

ForceTouchData (object)

  • iPhone 6S/6S Plus: From 1 to 5 touches
  • iPad Pro: From 1 to 10 touches
{
    "forceTouchCapability": "2",
    "touches": {
        "0": {
            "position":{
              "x": "345.500000",
              "y":"258.000000"
            },
            "force": "0.783153",
            "maximumPossibleForce": "6.666667",
            "phase": "1",
            "tapCount": "1",
            "timestamp": "2532.418879"
        },
        "1": {
            "position":{
              "x": "73.500000",
              "y":"272.500000"
            },
            "force": "0.387500",
            "maximumPossibleForce": "6.666667",
            "phase": "1",
            "tapCount": "1",
            "timestamp": "2532.402129"
        },
        "2": {
            "position":{
              "x": "183.000000",
              "y":"341.00000"
            },
            "force": "0.512394",
            "maximumPossibleForce": "6.666667",
            "phase": "1",
            "tapCount": "1",
            "timestamp": "2532.385464"
        },
        "3": {
            "position":{
              "x": "239.500000",
              "y":"416.000000"
            },
            "force": "0.237816",
            "maximumPossibleForce": "6.666667",
            "phase": "1",
            "tapCount": "1",
            "timestamp": "2532.615237"
        },
        [...]
    }
}

Multi-Touch Handling

ForceTouch.getForceTouchData(function (ForceTouchData)
{
  var touchesCount = Object.keys(ForceTouchData.touches).length;
  for(var i=0; i < touchesCount; i++)
  {
    // storing touch object at index "i"
    var currentTouch = ForceTouchData.touches[i];
    // accessing to ForceTouchData
    console.log(currentTouch.position.x);
    console.log(currentTouch.position.y);
    console.log(currentTouch.force);
    console.log(currentTouch.maximumPossibleForce);
    console.log(currentTouch.phase);
    console.log(currentTouch.tapCount);
    console.log(currentTouch.timestamp);
    // and so on for each loop cycle
  }
});

Data Types

position.x               (float)
position.y               (float)
forceTouchCapability     (int enum)  0:UNKNOWN | 1:UNAVAILABLE | 2:AVAILABLE
tapCount                 (int)
timestamp                (float)
phase                    (int)       0:TOUCH BEGAN | 1:TOUCH MOVES
force                    (float)     MIN VALUE: 0.0 | MAX VALUE: 1.0
maximumPossibleForce     (float)

Apple Official Force Touch Documentation for iOS

https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITouch_Class/index.html