Giter VIP home page Giter VIP logo

react-touch-position's Introduction

react-touch-position

React Touch Position is a primitive component for composing UI features that require notification of touch position status.

It plots touch coordinates relative to itself and re-renders child components with new touch position props when touch position changes.

React Touch Position Supports the long press gesture and does not interfere with page or element scrolling.

It is safe for server rendering and cleans up after unmount on the client.

Status

CircleCI Coverage Status npm License

Demo

Please see the react-touch-position demo site.

Experiment with react-touch-position live on CodePen.

Touch Demo

Related Project

For mouse position tracking, please consider react-cursor-position.

Installation

npm install --save react-touch-position

Usage

import ReactTouchPosition from 'react-touch-position';
...
<ReactTouchPosition>
    <YourComponentOne/>
    <YourComponentTwo/>
</ReactTouchPosition>

ReactTouchPosition wraps its children in a div, which touch position is plotted relative to.

Each child component will receive the following props:

{
    isActive: Boolean,
    isPositionOutside: Boolean,
    touchPosition: {
        x: Number,
        y: Number
    }
}

This structure may be customized by implementing mapChildProps API feature.

Props API

className : String - Optionally provide a CSS class to be applied to the div rendered by react-touch-position.

style : Object - Optionally provide a style object to be applied to the div rendered by react-touch-position.

isActivatedOnTouch : Boolean - Optionally activate immediately on touch. Scrolling may not be possible when scroll gesture begins on target area. Recommended only when scrolling is not an expected use case.

mapChildProps : Function - Optionally model child component props to your custom shape. Function receives one parameter with the signature { isActive, isPositionOutside, touchPosition }, and returns an object that is compatible with the props interface of your components.

onActivationChanged : Function - Optionally provide a function that will be called when the component is active. Function receives one parameter with the signature { isActive }

onPositionChanged : Function - Optionally provide a function that will be called when touch position changes. Function will receive an object with the signature { isPositionOutside, touchPosition: { x, y } }, as a single parameter.

pressDuration : Number - Milliseconds delay before press gesture is activated. Defaults to 500.

pressMoveThreshold: Number - Amount of movement allowed during press event detection. Defaults to 5.

shouldDecorateChildren : Boolean - Defaults to true. Optionally suppress touchPosition decoration of child components by setting this prop false.

Support

Please open an issue.

Example Project

git clone https://github.com/ethanselzer/react-touch-position.git
cd react-touch-position/example
npm install
npm start

If your default browser does not start automatically, open a new browser window and go to localhost:3000

Development

git clone https://github.com/ethanselzer/react-touch-position.git
cd react-touch-position
npm install
npm run #print available commands

The Example Project may be used in development of react-touch-position. To import ReactTouchPosition from your local project change any import of ReactTouchPosition, on files in the components folder, to:

import ReactTouchPosition from '../../../dist/ReactTouchPosition';

The command npm run prepublsih must be run from the root of the project each time you want your ReactTouchPosition changes to be reflected in the example.

If you experience ReferenceError: Unknown plugin "'transform-es2015-modules-umd'" when running prepublish you may try running npm run prepublish-cjs instead.

Contributing

Please contribute using Github Flow. Create a branch, add commits, and open a pull request.

License

MIT

react-touch-position's People

Contributors

ethanselzer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

jibostore t3ddev

react-touch-position's Issues

Uncaught TypeError: Cannot read property 'any' of undefined

Keep on getting this issue:
image

When I stripe down the demo version all the way until there's only the BasicExample component left. It's still works but I do get the same error in the console. Upside of this stripped demo version compared with mine is that it doesn't break.

So I've tried the demo locally. But can't find where this issue is coming from.
Is this a known issue or are there more dependencies that I should take in account?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.