Skip to content
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
25 changes: 20 additions & 5 deletions lib/FlipCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,14 @@ export default class FlipCard extends Component {
this.props.onFlipStart(this.state.isFlipped)
this._animation(!this.state.isFlipped)
}
_animation (isFlipped) {
_animation (isFlipped) {
if (!this.timer) {
this.timer = setTimeout(() => {
this.setState({isFlipped: !this.state.isFlipped})
this.timer = null
}, 120)
}

Animated.spring(this.state.rotate,
{
toValue: Number(isFlipped),
Expand Down Expand Up @@ -77,6 +78,14 @@ export default class FlipCard extends Component {
})
}

_onPress() {
if (this.props.shouldFlipOnUserTap) {
this._toggleCard()
} else {
this.props.onPress()
}
}

render () {
var c = this.props.children;
var transform = this.props.perspective ? [{ perspective: this.props.perspective }] : []
Expand Down Expand Up @@ -162,8 +171,8 @@ export default class FlipCard extends Component {
return (
<TouchableOpacity
testID={this.props.testID}
activeOpacity={1}
onPress={() => { this._toggleCard(); }}
activeOpacity={ this.props.activeOpacity }
onPress={ this._onPress.bind(this) }
>
<Animated.View
{...this.props}
Expand Down Expand Up @@ -207,6 +216,9 @@ FlipCard.propTypes = {
alignHeight: PropTypes.bool,
alignWidth: PropTypes.bool,
useNativeDriver: PropTypes.bool,
shouldFlipOnUserTap: PropTypes.bool,
onPress: PropTypes.func,
activeOpacity: PropTypes.number,
children (props, propName, componentName) {
const prop = props[propName]
if (React.Children.count(prop) !== 2) {
Expand All @@ -223,7 +235,7 @@ FlipCard.propTypes = {
FlipCard.defaultProps = {
flip: false,
friction: 6,
perspective: 0,
perspective: (Platform.OS === "android") ? 1000 : 0,
flipHorizontal: false,
flipVertical: true,
clickable: true,
Expand All @@ -232,6 +244,9 @@ FlipCard.defaultProps = {
alignHeight: false,
alignWidth: false,
useNativeDriver: true,
shouldFlipOnUserTap: true,
activeOpacity: 1.0,
onPress: () => {}
}


Expand Down Expand Up @@ -295,4 +310,4 @@ Back.propTypes = {
perspective: PropTypes.number,
children (props, propName, componentName) {
}
}
}