@momo-kits/foundation 0.169.3 → 0.169.4-beta.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.
@@ -13,7 +13,7 @@ import Animated, {
13
13
  } from 'react-native-reanimated';
14
14
  import { scheduleOnRN } from 'react-native-worklets';
15
15
  import { ApplicationContext } from '../Context';
16
- import { Colors } from '../Consts';
16
+ import { Colors, Spacing } from '../Consts';
17
17
  import { Icon } from '../Icon';
18
18
  import { useScaleSize, exportFontFamily } from '../Text';
19
19
  import { type AnimatedCompatValue } from '../Application/utils';
@@ -50,8 +50,11 @@ export const FloatingButton: React.FC<FloatingButtonProps> = ({
50
50
  const labelFontFamily = exportFontFamily('bold');
51
51
  const maxWidth = useSharedValue(0);
52
52
  const minWidth = size === 'small' ? 36 : 48;
53
+ const iconSize = size === 'small' ? 12 : 24;
53
54
  const opacityAnimated = useSharedValue(0);
54
55
  const widthAnimated = useSharedValue<number | null>(null);
56
+ const paddingLeftAnimated = useSharedValue(Spacing.M);
57
+ const collapsedPaddingLeft = useSharedValue(Spacing.M);
55
58
  const lastOffset = useSharedValue(0);
56
59
  const lastDirection = useSharedValue<string | null>(null);
57
60
  const [showText, setShowText] = useState(true);
@@ -73,6 +76,9 @@ export const FloatingButton: React.FC<FloatingButtonProps> = ({
73
76
  lastDirection.value = direction;
74
77
  if (direction === 'down') {
75
78
  opacityAnimated.value = withTiming(0, { duration: 100 });
79
+ paddingLeftAnimated.value = withTiming(collapsedPaddingLeft.value, {
80
+ duration: 100,
81
+ });
76
82
  widthAnimated.value = withTiming(
77
83
  minWidth,
78
84
  { duration: 100 },
@@ -82,6 +88,7 @@ export const FloatingButton: React.FC<FloatingButtonProps> = ({
82
88
  );
83
89
  } else {
84
90
  opacityAnimated.value = withTiming(1, { duration: 100 });
91
+ paddingLeftAnimated.value = withTiming(Spacing.M, { duration: 100 });
85
92
  widthAnimated.value = withTiming(
86
93
  maxWidth.value,
87
94
  { duration: 100 },
@@ -98,6 +105,7 @@ export const FloatingButton: React.FC<FloatingButtonProps> = ({
98
105
 
99
106
  const containerStyle = useAnimatedStyle(() => ({
100
107
  width: widthAnimated.value ?? undefined,
108
+ paddingLeft: paddingLeftAnimated.value,
101
109
  }));
102
110
 
103
111
  const labelStyle = useAnimatedStyle(() => ({
@@ -107,8 +115,14 @@ export const FloatingButton: React.FC<FloatingButtonProps> = ({
107
115
  const handleLayout = (event: LayoutChangeEvent) => {
108
116
  const layout = event.nativeEvent.layout;
109
117
  if (widthAnimated.value != null) return;
110
- maxWidth.value = layout.width;
111
- widthAnimated.value = layout.width;
118
+ // layout is already scaled: rescale by height/minWidth so `width` isn't scaled twice
119
+ const expandedWidth = (layout.width * minWidth) / layout.height;
120
+ maxWidth.value = expandedWidth;
121
+ widthAnimated.value = expandedWidth;
122
+ // collapsed it is a circle as wide as it is tall: center the icon from the
123
+ // rendered height so it stays centered when sizes are scaled but padding is not
124
+ collapsedPaddingLeft.value =
125
+ (layout.height - (layout.height * iconSize) / minWidth) / 2;
112
126
  };
113
127
 
114
128
  if (renderComponent) {
@@ -140,11 +154,7 @@ export const FloatingButton: React.FC<FloatingButtonProps> = ({
140
154
  ]}
141
155
  >
142
156
  <TouchableOpacity style={styles.content} onPress={onPress}>
143
- <Icon
144
- source={icon}
145
- size={size === 'small' ? 12 : 24}
146
- color={iconColor}
147
- />
157
+ <Icon source={icon} size={iconSize} color={iconColor} />
148
158
  {showText && !!label && (
149
159
  <Animated.Text
150
160
  allowFontScaling={false}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/foundation",
3
- "version": "0.169.3",
3
+ "version": "0.169.4-beta.1",
4
4
  "description": "React Native Component Kits",
5
5
  "main": "index.ts",
6
6
  "scripts": {},