Skip to content

Commit

Permalink
sets hasMaybeAction prop
Browse files Browse the repository at this point in the history
  • Loading branch information
esganzerla committed Mar 10, 2017
1 parent 64b5010 commit eb9031b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_Store
node_modules/
npm-debug.log
testings/
18 changes: 18 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
// Use IntelliSense to learn about possible Node.js debug attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Debug iOS",
"program": "${workspaceRoot}/.vscode/launchReactNative.js",
"type": "reactnative",
"request": "launch",
"platform": "ios",
"sourceMaps": true,
"target": "iPhone 5s",
"outDir": "${workspaceRoot}/.vscode/.react"
}
]
}
9 changes: 7 additions & 2 deletions SwipeCards.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
View,
Animated,
PanResponder,
Dimensions,
Image
} from 'react-native';

Expand Down Expand Up @@ -76,6 +77,7 @@ export default class SwipeCards extends Component {
static propTypes = {
cards: React.PropTypes.array,
cardKey: React.PropTypes.string,
hasMaybeAction: React.PropTypes.bool,
loop: React.PropTypes.bool,
onLoop: React.PropTypes.func,
allowGestureTermination: React.PropTypes.bool,
Expand Down Expand Up @@ -104,6 +106,7 @@ export default class SwipeCards extends Component {
static defaultProps = {
cards: [],
cardKey: 'key',
hasMaybeAction: false,
loop: false,
onLoop: () => null,
allowGestureTermination: true,
Expand Down Expand Up @@ -188,7 +191,7 @@ export default class SwipeCards extends Component {

const hasSwipedHorizontally = Math.abs(this.state.pan.x._value) > SWIPE_THRESHOLD
const hasSwipedVertically = Math.abs(this.state.pan.y._value) > SWIPE_THRESHOLD
if (hasSwipedHorizontally || hasSwipedVertically) {
if (hasSwipedHorizontally || (hasSwipedVertically && this.props.hasMaybeAction)) {

let cancelled = false;

Expand All @@ -200,7 +203,7 @@ export default class SwipeCards extends Component {
cancelled = this.props.handleYup(this.state.card);
} else if (hasMovedLeft) {
cancelled = this.props.handleNope(this.state.card);
} else if (hasMovedUp) {
} else if (hasMovedUp && this.props.hasMaybeAction) {
cancelled = this.props.handleMaybe(this.state.card);
} else {
cancelled = true
Expand Down Expand Up @@ -471,6 +474,8 @@ export default class SwipeCards extends Component {
}

renderMaybe() {
if (!this.props.hasMaybeAction) return null;

let {pan} = this.state;

let maybeOpacity = pan.y.interpolate({ inputRange: [-SWIPE_THRESHOLD, -(SWIPE_THRESHOLD/2)], outputRange: [1, 0], extrapolate: 'clamp' });
Expand Down

0 comments on commit eb9031b

Please sign in to comment.