react-native-swipe-verify
Advanced tools
Comparing version 0.1.5 to 0.1.6
{ | ||
"name": "react-native-swipe-verify", | ||
"version": "0.1.5", | ||
"version": "0.1.6", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "author": { |
108
src/index.js
@@ -5,9 +5,9 @@ /** | ||
import React, { Component } from 'react' | ||
import PropTypes from 'prop-types' | ||
import { View, PanResponder, Animated, UIManager } from 'react-native' | ||
import React, { Component } from "react"; | ||
import PropTypes from "prop-types"; | ||
import { View, PanResponder, Animated, UIManager } from "react-native"; | ||
// Enable LayoutAnimation on Android | ||
if (UIManager.setLayoutAnimationEnabledExperimental) { | ||
UIManager.setLayoutAnimationEnabledExperimental(true) | ||
UIManager.setLayoutAnimationEnabledExperimental(true); | ||
} | ||
@@ -27,17 +27,17 @@ | ||
borderRadius: PropTypes.number | ||
} | ||
}; | ||
//default props value | ||
const defaultProps = { | ||
backgroundColor: '#fff', | ||
buttonColor: '#D50000', | ||
textColor: '#000', | ||
borderColor: 'rgba(0,0,0,0)', | ||
backgroundColor: "#fff", | ||
buttonColor: "#D50000", | ||
textColor: "#000", | ||
borderColor: "rgba(0,0,0,0)", | ||
okButton: { visible: true, duration: 300 }, | ||
borderRadius: 0 | ||
} | ||
}; | ||
export default class RNSwipeVerify extends Component { | ||
constructor(props) { | ||
super(props) | ||
super(props); | ||
@@ -52,3 +52,3 @@ this.state = { | ||
dimensions: { width: 0, height: 0 } | ||
} | ||
}; | ||
@@ -58,5 +58,5 @@ this._panResponder = PanResponder.create({ | ||
onPanResponderGrant: () => { | ||
const positionXY = this.state.drag.__getValue() | ||
this.state.drag.setOffset(positionXY) | ||
this.state.drag.setValue({ x: 0, y: 0 }) | ||
const positionXY = this.state.drag.__getValue(); | ||
this.state.drag.setOffset(positionXY); | ||
this.state.drag.setValue({ x: 0, y: 0 }); | ||
}, | ||
@@ -66,3 +66,3 @@ onPanResponderMove: Animated.event([null, { dx: this.state.drag.x }], { | ||
listener: (event, gestureState) => { | ||
const { buttonSize } = this.props | ||
const { buttonSize } = this.props; | ||
@@ -73,31 +73,31 @@ const { | ||
dimensions: { width } | ||
} = this.state | ||
const maxMoving = width - buttonSize | ||
} = this.state; | ||
const maxMoving = width - buttonSize; | ||
var toX = gestureState.dx | ||
var toX = gestureState.dx; | ||
if (toX < 0) toX = 0 | ||
if (toX > maxMoving) toX = maxMoving | ||
const percent = ((toX * 100) / maxMoving).toFixed() | ||
this.setState({ percent }) | ||
if (toX < 0) toX = 0; | ||
if (toX > maxMoving) toX = maxMoving; | ||
const percent = ((toX * 100) / maxMoving).toFixed(); | ||
this.setState({ percent }); | ||
if (verify) { | ||
drag.setValue({ x: 0, y: 0 }) | ||
return | ||
drag.setValue({ x: 0, y: 0 }); | ||
return; | ||
} | ||
drag.setValue({ x: toX, y: 0 }) | ||
drag.setValue({ x: toX, y: 0 }); | ||
} | ||
}), | ||
onPanResponderRelease: () => { | ||
if (this.state.verify) return | ||
if (this.state.verify) return; | ||
if (this.state.percent >= 100) { | ||
this.setState({ moving: false, verify: true }) | ||
this.props.onVerified() //communicate that the verification was successful | ||
this.setState({ moving: false, verify: true }); | ||
this.props.onVerified(); //communicate that the verification was successful | ||
const { visible, duration } = this.props.okButton | ||
const { visible, duration } = this.props.okButton; | ||
if (!visible) { | ||
this.toggleShowAnimation(false, duration) | ||
this.toggleShowAnimation(false, duration); | ||
} | ||
} else if (!this.state.verify) { | ||
this.reset() | ||
this.reset(); | ||
} | ||
@@ -110,13 +110,13 @@ }, | ||
} | ||
}) | ||
}); | ||
} | ||
reset() { | ||
this.state.drag.setOffset({ x: 0, y: 0 }) | ||
this.state.drag.setOffset({ x: 0, y: 0 }); | ||
Animated.timing(this.state.drag, { | ||
toValue: { x: 0, y: 0 }, | ||
duration: 300 | ||
}).start() | ||
this.toggleShowAnimation(true, this.props.okButton.duration) | ||
this.setState({ moving: false, verify: false, percent: 0 }) | ||
}).start(); | ||
this.toggleShowAnimation(true, this.props.okButton.duration); | ||
this.setState({ moving: false, verify: false, percent: 0 }); | ||
} | ||
@@ -132,3 +132,3 @@ | ||
} | ||
).start() | ||
).start(); | ||
} | ||
@@ -144,6 +144,6 @@ | ||
borderRadius | ||
} = this.props | ||
const { buttonOpacity } = this.state | ||
} = this.props; | ||
const { buttonOpacity } = this.state; | ||
const position = { transform: this.state.drag.getTranslateTransform() } | ||
const position = { transform: this.state.drag.getTranslateTransform() }; | ||
@@ -157,3 +157,4 @@ return ( | ||
padding: 2, | ||
flex: 1 | ||
flex: 1, | ||
height: buttonSize+4 | ||
}} | ||
@@ -163,4 +164,7 @@ > | ||
onLayout={event => { | ||
var { x, y, width, height } = event.nativeEvent.layout | ||
this.setState({ dimensions: { width, height }, position: { x, y } }) | ||
var { x, y, width, height } = event.nativeEvent.layout; | ||
this.setState({ | ||
dimensions: { width, height }, | ||
position: { x, y } | ||
}); | ||
}} | ||
@@ -171,3 +175,3 @@ style={{ | ||
borderRadius, | ||
justifyContent: 'center' | ||
justifyContent: "center" | ||
}} | ||
@@ -178,4 +182,4 @@ > | ||
style={{ | ||
position: 'absolute', | ||
alignSelf: 'center' | ||
position: "absolute", | ||
alignSelf: "center" | ||
}} | ||
@@ -196,4 +200,4 @@ > | ||
backgroundColor: buttonColor, | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
justifyContent: "center", | ||
alignItems: "center", | ||
opacity: buttonOpacity | ||
@@ -207,7 +211,7 @@ } | ||
</View> | ||
) | ||
); | ||
} | ||
} | ||
RNSwipeVerify.propTypes = propTypes | ||
RNSwipeVerify.defaultProps = defaultProps | ||
RNSwipeVerify.propTypes = propTypes; | ||
RNSwipeVerify.defaultProps = defaultProps; |
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
13412
186