Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added onTap prop. #61

Merged
merged 1 commit into from
Jan 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ as well as the x distance, + or -, from where the swipe started to where it ende

**`onSwiped`** is called with the event, the X and Y delta, whether or not the event was a flick, and the current velocity of the swipe. `this.props.onSwiped(e, x, y, isFlick, velocity)`

**`onTap`** is called with the onTouchEnd event when the element has been tapped. `this.props.onTap(e)`

#####Configuration Props

**`flickThreshold`** is a number (float) which determines the max velocity of a swipe before it's considered a flick. The default value is `0.6`.
Expand Down Expand Up @@ -77,6 +79,7 @@ as well as the x distance, + or -, from where the swipe started to where it ende
onSwipedRight: React.PropTypes.func,
onSwipedDown: React.PropTypes.func,
onSwipedLeft: React.PropTypes.func,
onTap: React.PropTypes.func,
flickThreshold: React.PropTypes.number,
delta: React.PropTypes.number,
preventDefaultTouchmoveEvent: React.PropTypes.bool,
Expand Down
22 changes: 22 additions & 0 deletions examples/app/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const DIRECTIONS = ['Left', 'Right', 'Up', 'Down'];
const initialState = {
swiping: false,
swiped: false,
tap: false,
swipingDirection: '',
swipedDirection: '',
};
Expand All @@ -28,6 +29,7 @@ const initialStateApplied = {
onSwipedRightApplied: true,
onSwipedUpApplied: true,
onSwipedDownApplied: true,
onTapApplied: true,
};

export default class Main extends Component {
Expand Down Expand Up @@ -72,6 +74,14 @@ export default class Main extends Component {
});
}

onTap(...args) {
console.log('onTap args: ', args)
this.setState({
tap: true,
});
}


updateValue(type, value) {
this.setState({
[type]: value,
Expand Down Expand Up @@ -101,10 +111,12 @@ export default class Main extends Component {
swiped,
swipingDirection,
swipedDirection,
tap,
flickThreshold,
delta,
onSwipingApplied,
onSwipedApplied,
onTapApplied,
preventDefaultTouchmoveEvent,
stopPropagation,
nodeName,
Expand All @@ -124,6 +136,9 @@ export default class Main extends Component {
if (onSwipedApplied) {
swipeableDirProps.onSwiped = (...args)=>this.onSwiped(...args);
}
if (onTapApplied) {
swipeableDirProps.onTap = (...args)=>this.onTap(...args);
}

return (
<div className="row">
Expand Down Expand Up @@ -164,6 +179,13 @@ export default class Main extends Component {
</td>
<td>onSwiped</td><td>{swiped ? 'True' : 'False'}</td>
</tr>
<tr style={{color: onTapApplied ? '#000000' : '#cccccc'}}>
<td className="text-center">
<input type="checkbox" checked={onTapApplied}
onChange={(e)=>this.updateValue('onTapApplied', e.target.checked)} />
</td>
<td>onTap</td><td>{tap ? 'True' : 'False'}</td>
</tr>
<tr>
<td className="text-center"><a href="#appliedDirs">↓&nbsp;Below&nbsp;↓</a></td>
<td>onSwiping[Direction]</td><td>{swipingDirection}</td>
Expand Down
3 changes: 3 additions & 0 deletions src/Swipeable.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ const Swipeable = React.createClass({
this.props.onSwipedDown && this.props.onSwipedDown(e, pos.deltaY, isFlick)
}
}
} else {
this.props.onTap && this.props.onTap(e)
}

this.swipeable = getInitialState();
Expand All @@ -221,6 +223,7 @@ const Swipeable = React.createClass({
delete newProps.onSwipedRight
delete newProps.onSwipedDown
delete newProps.onSwipedLeft
delete newProps.onTap
delete newProps.flickThreshold
delete newProps.delta
delete newProps.preventDefaultTouchmoveEvent
Expand Down