@cleartrip/ct-design-button 5.19.0 → 5.21.0-SNAPSHOT-native-main.1

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.
@@ -1 +1 @@
1
- {"version":3,"file":"Button.native.d.ts","sourceRoot":"","sources":["../packages/components/Button/src/Button.native.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAC;AAEnD,OAAO,EAAa,IAAI,EAAE,MAAM,cAAc,CAAC;AAwC/C,QAAA,MAAM,MAAM;;;;;;;;;;;;YAAZ,CAAA;iBAKa,CAAC;kBAKP,CAAC;2BAKO,CAAC;2BAMV,CAAD;;;+BA0DJ,CAAC;AAIF,eAAe,MAAM,CAAC"}
1
+ {"version":3,"file":"Button.native.d.ts","sourceRoot":"","sources":["../packages/components/Button/src/Button.native.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA2C,MAAM,OAAO,CAAC;AAEhE,OAAO,EAAa,IAAI,EAAE,MAAM,cAAc,CAAC;AA+C/C,QAAA,MAAM,MAAM;;;;;;;;;;;;YAdM,CAAC;iBAIf,CAAJ;kBAMc,CAAC;2BAEoE,CAAC;2BAO3E,CAAC;;;+BAiGT,CAAC;AAIF,eAAe,MAAM,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cleartrip/ct-design-button",
3
- "version": "5.19.0",
3
+ "version": "5.21.0-SNAPSHOT-native-main.1",
4
4
  "description": "",
5
5
  "types": "dist/index.d.ts",
6
6
  "react-native": "src/index.ts",
@@ -26,21 +26,31 @@
26
26
  "dependencies": {
27
27
  "@emotion/react": "^11.14.0",
28
28
  "@emotion/styled": "^11.14.0",
29
- "@cleartrip/ct-design-typography": "5.18.0",
30
- "@cleartrip/ct-design-conditional-wrap": "5.19.0",
31
- "@cleartrip/ct-design-types": "5.18.0",
32
- "@cleartrip/ct-design-dotted-loader": "5.19.0",
33
- "@cleartrip/ct-design-theme": "5.18.0",
34
- "@cleartrip/ct-design-style-manager": "5.18.0",
35
- "@cleartrip/ct-design-event-propagation": "5.19.0",
36
- "@cleartrip/ct-design-container": "5.19.0"
29
+ "@cleartrip/ct-design-typography": "5.21.0-SNAPSHOT-native-main.1",
30
+ "@cleartrip/ct-design-container": "5.21.0-SNAPSHOT-native-main.1",
31
+ "@cleartrip/ct-design-conditional-wrap": "5.21.0-SNAPSHOT-native-main.1",
32
+ "@cleartrip/ct-design-dotted-loader": "5.21.0-SNAPSHOT-native-main.1",
33
+ "@cleartrip/ct-design-theme": "5.21.0-SNAPSHOT-native-main.1",
34
+ "@cleartrip/ct-design-types": "5.21.0-SNAPSHOT-native-main.1",
35
+ "@cleartrip/ct-design-style-manager": "5.21.0-SNAPSHOT-native-main.1",
36
+ "@cleartrip/ct-design-event-propagation": "5.21.0-SNAPSHOT-native-main.1"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@emotion/babel-plugin": "^11.12.0"
40
40
  },
41
41
  "peerDependencies": {
42
42
  "react": ">=16.8.0",
43
- "react-dom": ">=16.8.0"
43
+ "react-dom": ">=16.8.0",
44
+ "react-native": ">=0.68.0",
45
+ "react-native-reanimated": ">=3.0.0"
46
+ },
47
+ "peerDependenciesMeta": {
48
+ "react-native": {
49
+ "optional": true
50
+ },
51
+ "react-native-reanimated": {
52
+ "optional": true
53
+ }
44
54
  },
45
55
  "publishConfig": {
46
56
  "access": "public"
@@ -1,6 +1,7 @@
1
- import React, { forwardRef, useMemo } from 'react';
1
+ import React, { forwardRef, useCallback, useMemo } from 'react';
2
2
 
3
3
  import { Pressable, View } from 'react-native';
4
+ import Animated, { useAnimatedStyle, useSharedValue, withTiming, Easing } from 'react-native-reanimated';
4
5
  import { useStyles } from '@cleartrip/ct-design-style-manager';
5
6
  import { useTheme } from '@cleartrip/ct-design-theme';
6
7
  import { makeStyles } from '@cleartrip/ct-design-style-manager';
@@ -40,6 +41,12 @@ const staticButtonStyles = makeStyles((theme) => {
40
41
  };
41
42
  });
42
43
 
44
+ const AnimatedPressable = Animated.createAnimatedComponent(Pressable);
45
+
46
+ const PRESS_IN_SCALE = 0.96;
47
+ const PRESS_ANIMATION_DURATION = 120;
48
+ const pressAnimationConfig = { duration: PRESS_ANIMATION_DURATION, easing: Easing.out(Easing.quad) };
49
+
43
50
  const Button = forwardRef(
44
51
  (
45
52
  {
@@ -86,12 +93,35 @@ const Button = forwardRef(
86
93
 
87
94
  const mergedEvents = useMergeEvents({ onClick: [onClick] });
88
95
 
96
+ const pressProgress = useSharedValue(0);
97
+
98
+ const animatedPressStyle = useAnimatedStyle(() => {
99
+ const scale = 1 + pressProgress.value * (PRESS_IN_SCALE - 1);
100
+ return {
101
+ transform: [{ scale }],
102
+ };
103
+ });
104
+
105
+ const handlePressIn = useCallback(() => {
106
+ pressProgress.value = withTiming(1, pressAnimationConfig, (finished) => {
107
+ if (finished) {
108
+ pressProgress.value = withTiming(0, pressAnimationConfig);
109
+ }
110
+ });
111
+ }, [pressProgress]);
112
+
89
113
  return (
90
114
  <Conditional
91
115
  condition={!!onClick}
92
116
  wrap={(children) => <EventCollectorProvider value={mergedEvents}>{children}</EventCollectorProvider>}
93
117
  >
94
- <Pressable ref={ref} disabled={disabled || loading} style={mergedRootStyles} onPress={onClick}>
118
+ <AnimatedPressable
119
+ ref={ref}
120
+ disabled={disabled || loading}
121
+ style={[mergedRootStyles, animatedPressStyle]}
122
+ onPress={onClick}
123
+ onPressIn={handlePressIn}
124
+ >
95
125
  {loading ? (
96
126
  <DottedLoader />
97
127
  ) : (
@@ -115,7 +145,7 @@ const Button = forwardRef(
115
145
  )}
116
146
  </>
117
147
  )}
118
- </Pressable>
148
+ </AnimatedPressable>
119
149
  </Conditional>
120
150
  );
121
151
  },