@holper/react-native-holper-storybook 0.6.88 → 0.6.90
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);
|
|
@@ -1,22 +1,45 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { Platform } from 'react-native';
|
|
2
3
|
import PropTypes from 'prop-types';
|
|
3
4
|
import Ionicons from 'react-native-vector-icons/Ionicons';
|
|
4
|
-
import RNFlashMessage, {
|
|
5
|
+
import RNFlashMessage, {
|
|
6
|
+
showMessage,
|
|
7
|
+
renderFlashMessageIcon,
|
|
8
|
+
} from 'react-native-flash-message';
|
|
5
9
|
import { Colors } from '../../configs/constants';
|
|
6
10
|
|
|
7
|
-
export const customRenderFlashMessageIcon = (
|
|
8
|
-
|
|
11
|
+
export const customRenderFlashMessageIcon = (
|
|
12
|
+
icon = 'success',
|
|
13
|
+
style = {},
|
|
14
|
+
customProps = {}
|
|
15
|
+
) => {
|
|
16
|
+
switch (icon) {
|
|
9
17
|
case 'success':
|
|
10
|
-
return
|
|
18
|
+
return (
|
|
19
|
+
<Ionicons
|
|
20
|
+
name='checkmark-circle-outline'
|
|
21
|
+
color={Colors.darkblue}
|
|
22
|
+
size={30}
|
|
23
|
+
/>
|
|
24
|
+
);
|
|
11
25
|
case 'error':
|
|
12
|
-
return
|
|
26
|
+
return (
|
|
27
|
+
<Ionicons
|
|
28
|
+
name='alert-circle-outline'
|
|
29
|
+
color={Colors.darkblue}
|
|
30
|
+
size={30}
|
|
31
|
+
/>
|
|
32
|
+
);
|
|
13
33
|
}
|
|
14
34
|
|
|
15
35
|
// it's good to inherit the original method...
|
|
16
36
|
return renderFlashMessageIcon(icon, style, customProps);
|
|
17
37
|
};
|
|
18
38
|
|
|
19
|
-
|
|
39
|
+
const statusBarHeight =
|
|
40
|
+
Platform.OS === 'android' ? { statusBarHeight: 10 } : {};
|
|
41
|
+
|
|
42
|
+
export const sendMessage = ({ variant, message, description }) => {
|
|
20
43
|
return showMessage({
|
|
21
44
|
position: 'top',
|
|
22
45
|
message,
|
|
@@ -25,8 +48,8 @@ export const sendMessage = ({variant, message, description}) => {
|
|
|
25
48
|
type: variant,
|
|
26
49
|
backgroundColor: variant === 'success' ? Colors.green : Colors.lightred,
|
|
27
50
|
color: Colors.darkblue,
|
|
28
|
-
|
|
29
|
-
|
|
51
|
+
hideOnPress: true,
|
|
52
|
+
...statusBarHeight,
|
|
30
53
|
});
|
|
31
54
|
};
|
|
32
55
|
|
|
@@ -34,17 +57,17 @@ sendMessage.defaultProps = {
|
|
|
34
57
|
options: {
|
|
35
58
|
variant: 'success',
|
|
36
59
|
message: ' ',
|
|
37
|
-
description: ' '
|
|
38
|
-
}
|
|
60
|
+
description: ' ',
|
|
61
|
+
},
|
|
39
62
|
};
|
|
40
63
|
|
|
41
64
|
sendMessage.propTypes = {
|
|
42
65
|
options: PropTypes.shape({
|
|
43
66
|
variant: PropTypes.oneOf(['success', 'error']),
|
|
44
67
|
message: PropTypes.string,
|
|
45
|
-
description: PropTypes.string
|
|
46
|
-
})
|
|
47
|
-
}
|
|
68
|
+
description: PropTypes.string,
|
|
69
|
+
}),
|
|
70
|
+
};
|
|
48
71
|
|
|
49
72
|
const FlashMessage = () => {
|
|
50
73
|
return (
|
|
@@ -54,6 +77,6 @@ const FlashMessage = () => {
|
|
|
54
77
|
textStyle={{ fontFamily: 'poppins_regular' }}
|
|
55
78
|
/>
|
|
56
79
|
);
|
|
57
|
-
}
|
|
80
|
+
};
|
|
58
81
|
|
|
59
82
|
export default FlashMessage;
|