From 9682e3554cb008677b04d82974ecb839c2d6ade4 Mon Sep 17 00:00:00 2001 From: Qi Shengen Date: Mon, 30 Oct 2023 15:44:17 +0800 Subject: [PATCH 1/2] add props for disabling gesture --- index.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/index.js b/index.js index 664ba4e..5669b00 100644 --- a/index.js +++ b/index.js @@ -56,6 +56,10 @@ export default class SwitchSelector extends Component { } getSwipeDirection(gestureState) { + if (disableGestures) + { + return null; + } const { dx, dy, vx } = gestureState; // 0.1 velocity if (Math.abs(vx) > 0.1 && Math.abs(dy) < 80) { @@ -147,6 +151,7 @@ export default class SwitchSelector extends Component { accessibilityLabel, testID, touchableProps, + disableGestures, } = this.props; const { selected, sliderWidth } = this.state; @@ -300,6 +305,7 @@ SwitchSelector.defaultProps = { accessibilityLabel: null, testID: null, touchableProps: {}, + disableGestures: false, }; SwitchSelector.propTypes = { @@ -333,4 +339,5 @@ SwitchSelector.propTypes = { accessibilityLabel: PropTypes.string, testID: PropTypes.string, touchableProps: PropTypes.object, + disableGestures: PropTypes.bool, }; From 3234603b21b3d444e775cc08f626064e262d22ef Mon Sep 17 00:00:00 2001 From: Qi Shengen Date: Mon, 30 Oct 2023 15:50:58 +0800 Subject: [PATCH 2/2] fix props issue --- index.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 5669b00..838e08a 100644 --- a/index.js +++ b/index.js @@ -56,10 +56,8 @@ export default class SwitchSelector extends Component { } getSwipeDirection(gestureState) { - if (disableGestures) - { - return null; - } + const { disableGestures } = this.props; + if (disableGestures) return null; const { dx, dy, vx } = gestureState; // 0.1 velocity if (Math.abs(vx) > 0.1 && Math.abs(dy) < 80) {