@codeleap/mobile 2.3.3 → 2.3.4

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.
@@ -11,6 +11,7 @@ export declare type TextProps = ComponentPropsWithoutRef<typeof NativeText> & {
11
11
  animated?: boolean;
12
12
  colorChangeConfig?: Partial<Animated.TimingAnimationConfig>;
13
13
  debugName?: string;
14
+ debounce?: number;
14
15
  } & BaseViewProps & MotiProps;
15
16
  export declare const Text: React.ForwardRefExoticComponent<import("react-native").TextProps & {
16
17
  text?: React.ReactNode;
@@ -18,4 +19,5 @@ export declare const Text: React.ForwardRefExoticComponent<import("react-native"
18
19
  animated?: boolean;
19
20
  colorChangeConfig?: Partial<Animated.TimingAnimationConfig>;
20
21
  debugName?: string;
22
+ debounce?: number;
21
23
  } & BaseViewProps & MotiProps<any, import("moti").StyleValueWithReplacedTransforms<any>, Partial<import("moti").StyleValueWithSequenceArraysWithoutTransform<import("moti").StyleValueWithReplacedTransforms<any>, string | number | symbol, string | number | symbol> & import("moti").StyleValueWithSequenceArraysWithTransform>> & React.RefAttributes<NativeText>>;
@@ -47,14 +47,32 @@ var utils_1 = require("../../utils");
47
47
  __exportStar(require("./styles"), exports);
48
48
  var MotiText = react_native_1.Animated.createAnimatedComponent(moti_1.MotiText);
49
49
  exports.Text = (0, react_1.forwardRef)(function (textProps, ref) {
50
- var _a = textProps.variants, variants = _a === void 0 ? [] : _a, text = textProps.text, children = textProps.children, style = textProps.style, colorChangeConfig = textProps.colorChangeConfig, props = __rest(textProps, ["variants", "text", "children", "style", "colorChangeConfig"]);
51
- var pressPolyfillEnabled = react_native_1.Platform.OS === 'android' && !!props.onPress;
52
- var _b = (0, common_1.useState)(false), pressed = _b[0], setPressed = _b[1];
50
+ var _a = textProps.variants, variants = _a === void 0 ? [] : _a, text = textProps.text, children = textProps.children, onPress = textProps.onPress, style = textProps.style, colorChangeConfig = textProps.colorChangeConfig, _b = textProps.debounce, debounce = _b === void 0 ? 1000 : _b, props = __rest(textProps, ["variants", "text", "children", "onPress", "style", "colorChangeConfig", "debounce"]);
51
+ var pressPolyfillEnabled = react_native_1.Platform.OS === 'android' && !!onPress;
52
+ var _c = (0, common_1.useState)(false), pressed = _c[0], setPressed = _c[1];
53
+ var pressedRef = React.useRef(false);
54
+ var _onPress = function (e) {
55
+ if (!onPress)
56
+ return;
57
+ if (common_1.TypeGuards.isNumber(debounce)) {
58
+ if (pressedRef.current) {
59
+ return;
60
+ }
61
+ pressedRef.current = true;
62
+ onPress === null || onPress === void 0 ? void 0 : onPress(e);
63
+ setTimeout(function () {
64
+ pressedRef.current = false;
65
+ }, debounce);
66
+ }
67
+ else {
68
+ onPress === null || onPress === void 0 ? void 0 : onPress(e);
69
+ }
70
+ };
53
71
  var handlePress = function (pressed) {
54
72
  if (!pressPolyfillEnabled)
55
73
  return;
56
74
  return function () {
57
- if (props.onPress) {
75
+ if (onPress) {
58
76
  setPressed(pressed);
59
77
  }
60
78
  };
@@ -77,7 +95,7 @@ exports.Text = (0, react_1.forwardRef)(function (textProps, ref) {
77
95
  hightlightPropertyOut: 'backgroundColor',
78
96
  }).getFeedbackStyle;
79
97
  var feedbackStyle = pressPolyfillEnabled ? getFeedbackStyle(pressed) : undefined;
80
- return <Component {...props} onPressIn={handlePress(true)} onPressOut={handlePress(false)} style={[styles, colorStyle, feedbackStyle]}
98
+ return <Component {...props} onPressIn={handlePress(true)} onPressOut={handlePress(false)} style={[styles, colorStyle, feedbackStyle]} onPress={_onPress}
81
99
  // @ts-ignore
82
100
  ref={ref}>
83
101
  {text}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/Text/index.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA8B;AAC9B,+BAA4D;AAC5D,2CAMyB;AACzB,6CAAwG;AACxG,6BAAuD;AACvD,qCAAmE;AAInE,2CAAwB;AAUxB,IAAM,QAAQ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O;QAC7B,qBAAqB,EAAE,iBAAiB;KACzC,CAAC,iBALsB,CAKtB;IACF,IAAM,aAAa,GAAG,oBAAoB,CAAC,CAAC,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;IAElF,OAAO,CAAC,SAAS,CAAC,IAAI,KAAK,CAAC,CAC1B,SAAS,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAC7D,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,UAAU,EAAE,aAAa,CAAC,CAAC,CAC3C,OAAO,CAAC,CAAC,QAAQ,CAAC;IAClB,aAAa;IACb,GAAG,CAAC,CAAC,GAAG,CAAC,CAET;IAAA,CAAC,IAAI,CACL;IAAA,CAAC,QAAQ,CACX;EAAA,EAAE,SAAS,CAAC,CAAA;AAEd,CAAC,CAAC,CAAA;AAEF,4CAA4C;AAC5C,UAAU;AACV,cAAc;AACd,KAAK;AAEL,6CAA6C;AAC7C,MAAM;AACN,gCAAgC;AAChC,0CAA0C;AAC1C,wBAAwB;AACxB,kDAAkD;AAClD,oBAAoB;AACpB,uBAAuB;AAEvB,UAAU;AACV,qBAAqB;AACrB,SAAS;AACT,MAAM;AACN,UAAU"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codeleap/mobile",
3
- "version": "2.3.3",
3
+ "version": "2.3.4",
4
4
  "main": "src/index.ts",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
@@ -21,22 +21,43 @@ export type TextProps = ComponentPropsWithoutRef<typeof NativeText> & {
21
21
  animated?: boolean
22
22
  colorChangeConfig?: Partial<Animated.TimingAnimationConfig>
23
23
  debugName?: string
24
+ debounce?: number
24
25
  } & BaseViewProps & MotiProps
25
26
 
26
27
  const MotiText = Animated.createAnimatedComponent(_MotiText)
27
28
 
28
29
  export const Text = forwardRef<NativeText, TextProps>((textProps, ref) => {
29
- const { variants = [], text, children, style, colorChangeConfig, ...props } = textProps
30
+ const { variants = [], text, children, onPress, style, colorChangeConfig, debounce = 1000, ...props } = textProps
30
31
 
31
- const pressPolyfillEnabled = Platform.OS === 'android' && !!props.onPress
32
+ const pressPolyfillEnabled = Platform.OS === 'android' && !!onPress
32
33
 
33
34
  const [pressed, setPressed] = useState(false)
35
+ const pressedRef = React.useRef(false)
36
+
37
+ const _onPress:TextProps['onPress'] = (e) => {
38
+ if (!onPress) return
39
+
40
+ if (TypeGuards.isNumber(debounce)) {
41
+ if (pressedRef.current) {
42
+ return
43
+ }
44
+
45
+ pressedRef.current = true
46
+ onPress?.(e)
47
+ setTimeout(() => {
48
+ pressedRef.current = false
49
+ }, debounce)
50
+
51
+ } else {
52
+ onPress?.(e)
53
+ }
54
+ }
55
+
34
56
  const handlePress = (pressed) => {
35
57
  if (!pressPolyfillEnabled) return
36
58
  return () => {
37
- if (props.onPress) {
59
+ if (onPress) {
38
60
  setPressed(pressed)
39
-
40
61
  }
41
62
  }
42
63
  }
@@ -67,6 +88,7 @@ export const Text = forwardRef<NativeText, TextProps>((textProps, ref) => {
67
88
  return <Component {...props}
68
89
  onPressIn={handlePress(true)} onPressOut={handlePress(false)}
69
90
  style={[styles, colorStyle, feedbackStyle]}
91
+ onPress={_onPress}
70
92
  // @ts-ignore
71
93
  ref={ref}
72
94
  >