react-swipeable
Advanced tools
Comparing version 1.0.0 to 1.1.0
{ | ||
"name": "react-swipeable", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Swipe bindings for react", | ||
@@ -5,0 +5,0 @@ "main": "Swipeable.js", |
var React = require('react') | ||
var FLICK_THRESHOLD = 0.3 | ||
var Swipeable = React.createClass({ | ||
propTypes: { | ||
onSwiped: React.PropTypes.func, | ||
onFlick: React.PropTypes.func, | ||
onSwipingUp: React.PropTypes.func, | ||
@@ -17,3 +20,4 @@ onSwipingRight: React.PropTypes.func, | ||
y: null, | ||
swiping: false | ||
swiping: false, | ||
start: 0 | ||
} | ||
@@ -51,2 +55,3 @@ }, | ||
this.setState({ | ||
start: Date.now(), | ||
x: e.touches[0].clientX, | ||
@@ -66,3 +71,3 @@ y: e.touches[0].clientY, | ||
if (pos.absX < this.props.delta && pos.abxY < this.props.delta) { | ||
if (pos.absX < this.props.delta && pos.absY < this.props.delta) { | ||
return | ||
@@ -107,3 +112,12 @@ } | ||
var pos = this.calculatePos(e) | ||
this.props.onSwiped && this.props.onSwiped(e, pos.absX, pos.abxY) | ||
var time = Date.now() - this.state.start | ||
var distance = pos.absX + pos.absY | ||
var isFlick = (time / distance) > FLICK_THRESHOLD | ||
if (isFlick) { | ||
this.props.onFlick && this.props.onFlick(e, pos.deltaX, pos.deltaY) | ||
} else { | ||
this.props.onSwiped && this.props.onSwiped(e, pos.absX, pos.absY) | ||
} | ||
} | ||
@@ -110,0 +124,0 @@ this.setState(this.getInitialState()) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5757
112