All Projects → rubcuadra → react-pressure

rubcuadra / react-pressure

Licence: MIT license
React HOC that enables 3D Touch on other components, available via npm

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to react-pressure

Zingtouch
A JavaScript touch gesture detection library for the modern web
Stars: ✭ 2,019 (+15430.77%)
Mutual labels:  touch
Hovertouchview
Stimulate Apple's Force Touch or 3D Touch on Android App with Hover Gesture
Stars: ✭ 192 (+1376.92%)
Mutual labels:  touch
Egjs View360
360 integrated viewing solution
Stars: ✭ 252 (+1838.46%)
Mutual labels:  touch
Yubikey Touch Detector
A tool to detect when your YubiKey is waiting for a touch (to send notification or display a visual indicator on the screen)
Stars: ✭ 167 (+1184.62%)
Mutual labels:  touch
Easybutton
Arduino library for debouncing momentary contact switches, detect press, release, long press and sequences with event definitions and callbacks.
Stars: ✭ 187 (+1338.46%)
Mutual labels:  touch
Toucheventbus
一种处理嵌套和非嵌套滑动冲突的解决方案
Stars: ✭ 222 (+1607.69%)
Mutual labels:  touch
Terminal Advancednewfile
Fast creation of files and directories. Mimics the operation of AdvancedNewFile (Vim plugin)
Stars: ✭ 134 (+930.77%)
Mutual labels:  touch
Virtual Controllers
Virtual controls for use in Flash based games on touch devices. Includes thumbstick and button ui elements
Stars: ✭ 16 (+23.08%)
Mutual labels:  touch
Tdtouchid
TDTouchID是一个封装好的指纹、FaceID验证库,可以用来做iOSAPP的登录/支付等验证。
Stars: ✭ 191 (+1369.23%)
Mutual labels:  touch
Swiped Events
Adds `swiped` events to the DOM in 0.7k of pure JavaScript
Stars: ✭ 249 (+1815.38%)
Mutual labels:  touch
Pull Element
Lightweight, high-performance and smooth pull element effect that support all directions
Stars: ✭ 171 (+1215.38%)
Mutual labels:  touch
Swip
a library to create multi device experiments
Stars: ✭ 2,109 (+16123.08%)
Mutual labels:  touch
Keen Slider
The HTML touch slider carousel with the most native feeling
Stars: ✭ 3,097 (+23723.08%)
Mutual labels:  touch
Toucheffects
Android View点击特效TouchEffects,几行代码为所有控件添加点击效果
Stars: ✭ 167 (+1184.62%)
Mutual labels:  touch
ZSFakeTouch
Simulate touch events for iOS 模拟点击
Stars: ✭ 104 (+700%)
Mutual labels:  touch
Layerjs
layerJS: Javascript UI composition framework
Stars: ✭ 1,825 (+13938.46%)
Mutual labels:  touch
Slip
Slip.js — UI library for manipulating lists via swipe and drag gestures
Stars: ✭ 2,421 (+18523.08%)
Mutual labels:  touch
DebounceMonitoring
📑 Add debounce logic for any method in a single line.
Stars: ✭ 44 (+238.46%)
Mutual labels:  touch
fancybox
jQuery lightbox script for displaying images, videos and more. Touch enabled, responsive and fully customizable.
Stars: ✭ 7,261 (+55753.85%)
Mutual labels:  touch
Clock Bar
Macbook | Clock, right on the touch bar
Stars: ✭ 237 (+1723.08%)
Mutual labels:  touch

React-Pressure.js

If you want to implement 3D touch on your react component this is the module for you

Installation & Usage

npm i --save react-pressure

How to

The project wrapps al the functionalities from Pressure.js into a React High Order component, any component enchanced by this will have force and pressing in its props . The HOC allows you to pass some config options.

props:

  • force : Contains a number between 0 and 1, it represents the amount of pressure done by the user
  • pressing : Contains *true* or *false*, it represents if the user is currently pressing or not the component

Options (Optional):

  • debug: true | false
  • polyfill: true | false
  • polyfillSpeedUp: 0 - 1000
  • polyfillSpeedDown: 0
  • preventSelect: true
  • only: null | "touch" | "mouse" | "pointer"

Debug

By default is false, if true then the component will print warnings/logs.

Polyfill Support

Using the "polyfill" keyword, you can disable polyfill support for the element. The polyfill is enabled by default and is useful if the device or browser does not support pressure, it will fall back to using time. For example instead of force from 0 to 1, it counts up from 0 to 1 over the course of one second, as long as you are holding the element. Try some of the examples on the main page on a devices that does not support pressure and see for yourself how it works.

Polyfill Speed Up

If you are using the polyfill, you can use the "polyfillSpeedUp" speed to determine how fast the polyfill takes to go from 0 to 1. The value is an integer in milliseconds and the default is 1000 (1 second). These great products are built on Semantic UI React. Add yours [here][22].

Polyfill Speed Down

If you are using the polyfill, you can use the "polyfillSpeedDown" speed to determine how fast the polyfill takes to go from 1 to 0 when the elemnt is released. The value is an integer in milliseconds and the default is 0 (aka off).

Device Detection

With Pressure, the third paramater is an optional object of options that can be passed in. The first option is device targeting. Using the "only" keyword, you can define if you want pressure to respond to ONLY touch, ONLY Mouse, or ONLY Pointer events.

touch: Iphones with 3D touch (6s,7)
mouse: Mac with Force Touch (Macbook Pro 2016/2017)
pointer: Wacom Tablets or devices that support Pointer Events

Prevent Select

Both Mac and iPhones have system wide features that they default to when force clicking on something (ex. defining a word on Mac or "peeking and popping" an image on iOS). Pressure prevents those actions from happening, however if you still want those actions to be possible on "Pressure" elements, you can pass in "preventSelect" as an option.

Example

If you want to implement 3D touch on your component you can do something like this:

import React, { Component } from 'react';
import Pressure from 'react-pressure';

class MyGreatComponent extends Component {
  render() {
    const message = this.props.pressing?"Stop please":"Touch me";
    return (
      <div>
        <h1>This is an awesome component</h1>
		<p>{message}</p>
        <p>The whole component has 3D touch detection</p>
        <p>You are using {this.props.force} force</p>
      </div>
    );
  }
}
//This is the important part
export default Pressure(MyGreatComponent);

By default all components have the configuration:

{
  polyfill: true,
  polyfillSpeedUp: 1000,
  polyfillSpeedDown: 1000,
  preventSelect: true,
  only: null
}

If you want to add some configurations you can modify the last part from the previous code and write something like this:(You can override some,none or all of the configurations)

//Now this changed
const configs = {
  polyfill: false, //Only people with 3D touch
  only: "touch"    //Only Iphones 
}
export default Pressure(MyGreatComponent,configs) ;

If you are using react-redux you can do something like:

export default connect(mapStateToProps,mapDispatchToProps)( Pressure(MyGreatComponent) );

If you have any doubt/recommendation you can write me or any trouble you can create a new thread on the issues area of the repository #ISSUES: 0.1.2 The latest realese of pressure.js has a weird bug in some Android devices, this new realese of react-pressure has a hotfix while the core code is upgraded, if you don't pass a configuration object then the HOC will try to guess if you are using a mobile phone, if it is de case then it uses the only:"touch", else it continues with the default configurations. 09/12/2017

#LIVE EXAMPLE:

Pressure Cubes: React & Three.js videogame that implements 3D touch to avoid cubes

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].