diff --git a/package.json b/package.json index 8cbda3e..1e14167 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-circular-slider", - "version": "1.0.1", + "version": "1.0.4", "description": "React Native component for creating circular slider", "main": "src/CircularSlider.js", "repository": { diff --git a/src/CircularSlider.js b/src/CircularSlider.js index 89a84e3..c5a4f9c 100644 --- a/src/CircularSlider.js +++ b/src/CircularSlider.js @@ -46,7 +46,6 @@ function getGradientId(index) { } export default class CircularSlider extends PureComponent { - static propTypes = { onUpdate: PropTypes.func.isRequired, startAngle: PropTypes.number.isRequired, @@ -80,9 +79,23 @@ export default class CircularSlider extends PureComponent { componentWillMount() { this._sleepPanResponder = PanResponder.create({ + onStartShouldSetPanResponder: (evt, gestureState) => true, + onStartShouldSetPanResponderCapture: (evt, gestureState) => true, onMoveShouldSetPanResponder: (evt, gestureState) => true, onMoveShouldSetPanResponderCapture: (evt, gestureState) => true, - onPanResponderGrant: (evt, gestureState) => this.setCircleCenter(), + onPanResponderGrant: (evt, gestureState) => { + this.setCircleCenter() + const { onPressIn } = this.props + if (onPressIn) { + onPressIn() + } + }, + onPanResponderRelease: (evt, gestureState) => { + const { onPressOut } = this.props + if (onPressOut) { + onPressOut() + } + }, onPanResponderMove: (evt, { moveX, moveY }) => { const { circleCenterX, circleCenterY } = this.state; const { angleLength, startAngle, onUpdate } = this.props; @@ -101,13 +114,31 @@ export default class CircularSlider extends PureComponent { } onUpdate({ startAngle: newAngle, angleLength: newAngleLength % (2 * Math.PI) }); + // this._handleOnPress() + }, + onPanResponderTerminate: (evt, gestureState) => { + console.log('onPanResponderTerminate', evt) + return false }, }); this._wakePanResponder = PanResponder.create({ + onStartShouldSetPanResponder: (evt, gestureState) => true, + onStartShouldSetPanResponderCapture: (evt, gestureState) => true, onMoveShouldSetPanResponder: (evt, gestureState) => true, - onMoveShouldSetPanResponderCapture: (evt, gestureState) => true, - onPanResponderGrant: (evt, gestureState) => this.setCircleCenter(), + onPanResponderGrant: (evt, gestureState) => { + this.setCircleCenter() + const { onPressIn } = this.props + if (onPressIn) { + onPressIn() + } + }, + onPanResponderRelease: (evt, gestureState) => { + const { onPressOut } = this.props + if (onPressOut) { + onPressOut() + } + }, onPanResponderMove: (evt, { moveX, moveY }) => { const { circleCenterX, circleCenterY } = this.state; const { angleLength, startAngle, onUpdate } = this.props; @@ -120,6 +151,11 @@ export default class CircularSlider extends PureComponent { } onUpdate({ startAngle, angleLength: newAngleLength }); + // this._handleOnPress() + }, + onPanResponderTerminate: (evt, gestureState) => { + console.log('onPanResponderTerminate', evt) + return false }, }); }