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

Add new onResponder release callbacks as props #9

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
38 changes: 34 additions & 4 deletions library/transform/ViewTransformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ export default class ViewTransformer extends React.Component {
return;
}

if (gestureState.singleTapUp) {
this.props.onSingleTap && this.props.onSingleTap();
}

if (gestureState.doubleTapUp) {
if (!this.props.enableScale) {
Expand All @@ -234,10 +237,14 @@ export default class ViewTransformer extends React.Component {
pivotY = gestureState.y0 - this.state.pageY;
}

this.performDoubleTapUp(pivotX, pivotY);
if (this.props.onDoubleTap) {
this.props.onDoubleTap(pivotX, pivotY);
} else {
this.performDoubleTapUp(pivotX, pivotY);
}
} else {
if(this.props.enableTranslate) {
this.performFling(gestureState.vx, gestureState.vy);
this.props.enableFling && this.performFling(gestureState.vx, gestureState.vy);
} else {
this.animateBounce();
}
Expand Down Expand Up @@ -445,18 +452,41 @@ ViewTransformer.propTypes = {
* Use true to enable resistance effect on over pulling. Default is false.
*/
enableResistance: React.PropTypes.bool,
/**
* Use false to disable flinging back after moving the image away from the center.
* Default is true.
*/
enableFling: React.PropTypes.bool,

onViewTransformed: React.PropTypes.func,

onTransformGestureReleased: React.PropTypes.func,

onSingleTapConfirmed: React.PropTypes.func
/**
* Callback on a single tap (includes first and second tap of double-tap)
*/
onSingleTap: React.PropTypes.func,
/**
* Callback on a single tap which is not part of a double-tap
*/
onSingleTapConfirmed: React.PropTypes.func,
/**
* Callback on a double tap (if supplied, it overwrites default scaling behavior)
*
* The first two arguments of the callback are the x- and y-coordinates of the
* finger while tapping, respectively.
*/
onDoubleTap: React.PropTypes.func,
};
ViewTransformer.defaultProps = {
maxOverScrollDistance: 20,
enableScale: true,
enableTranslate: true,
enableTransform: true,
maxScale: 1,
enableResistance: false
enableResistance: false,
enableFling: true,
onSingleTap: undefined,
onSingleTapConfirmed: undefined,
onDoubleTap: undefined,
};