@holper/react-native-holper-storybook 0.6.88 → 0.6.89
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -2,6 +2,7 @@ import React, { useState, useEffect } from 'react';
|
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import { TouchableOpacity, ActivityIndicator } from 'react-native';
|
|
4
4
|
import { ViewPropTypes } from 'deprecated-react-native-prop-types';
|
|
5
|
+
import withPreventDoubleClick from './../PreventDoubleClick';
|
|
5
6
|
import { Colors } from '../../configs/constants';
|
|
6
7
|
import style from './style';
|
|
7
8
|
|
|
@@ -14,6 +15,7 @@ const Button = ({
|
|
|
14
15
|
size,
|
|
15
16
|
noShadow,
|
|
16
17
|
style: customStyle,
|
|
18
|
+
debounceDelay = 0,
|
|
17
19
|
children,
|
|
18
20
|
}) => {
|
|
19
21
|
const [isDisabled, setIsDisabled] = useState(disabled);
|
|
@@ -31,6 +33,14 @@ const Button = ({
|
|
|
31
33
|
}
|
|
32
34
|
};
|
|
33
35
|
|
|
36
|
+
const handleTap = () => {
|
|
37
|
+
onPress();
|
|
38
|
+
setIsDisabled(true);
|
|
39
|
+
setTimeout(() => {
|
|
40
|
+
setIsDisabled(false);
|
|
41
|
+
}, debounceDelay);
|
|
42
|
+
};
|
|
43
|
+
|
|
34
44
|
return (
|
|
35
45
|
<TouchableOpacity
|
|
36
46
|
style={[
|
|
@@ -43,7 +53,7 @@ const Button = ({
|
|
|
43
53
|
customStyle,
|
|
44
54
|
]}
|
|
45
55
|
disabled={isLoading || isDisabled}
|
|
46
|
-
onPress={
|
|
56
|
+
onPress={handleTap}
|
|
47
57
|
>
|
|
48
58
|
{isLoading ? (
|
|
49
59
|
<ActivityIndicator color={getSpinnerColor()} size={28} />
|
|
@@ -64,6 +74,7 @@ Button.defaultProps = {
|
|
|
64
74
|
size: 'medium',
|
|
65
75
|
style: {},
|
|
66
76
|
onPress: () => {},
|
|
77
|
+
debounceDelay: 0,
|
|
67
78
|
};
|
|
68
79
|
|
|
69
80
|
Button.propTypes = {
|
|
@@ -85,6 +96,7 @@ Button.propTypes = {
|
|
|
85
96
|
size: PropTypes.oneOf(['tiny', 'small', 'medium', 'fit', 'icon']),
|
|
86
97
|
style: ViewPropTypes.style,
|
|
87
98
|
onPress: PropTypes.func,
|
|
99
|
+
debounceDelay: PropTypes.number,
|
|
88
100
|
};
|
|
89
101
|
|
|
90
|
-
export default Button;
|
|
102
|
+
export default withPreventDoubleClick(Button);
|