@momo-kits/foundation 0.169.19-beta.4 → 0.169.19-beta.6
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.
- package/Input/InputSearch.tsx +10 -3
- package/Layout/FloatingButton.tsx +15 -20
- package/package.json +1 -1
package/Input/InputSearch.tsx
CHANGED
|
@@ -33,6 +33,7 @@ const SEARCH_ICON_SIZE = 24;
|
|
|
33
33
|
/**
|
|
34
34
|
* Search field with search icon, clear icon, optional trailing icon and a
|
|
35
35
|
* cancel button; with `typingData` it shows an animated placeholder instead.
|
|
36
|
+
* Deprecated `icon*` props fall back into the `trailing*` ones.
|
|
36
37
|
*/
|
|
37
38
|
const InputSearch: ForwardRefRenderFunction<InputRef, InputSearchProps> = (
|
|
38
39
|
{
|
|
@@ -40,9 +41,12 @@ const InputSearch: ForwardRefRenderFunction<InputRef, InputSearchProps> = (
|
|
|
40
41
|
onFocus,
|
|
41
42
|
onBlur,
|
|
42
43
|
value,
|
|
43
|
-
trailing,
|
|
44
|
-
trailingColor,
|
|
45
|
-
onPressTrailing,
|
|
44
|
+
trailing: trailingProp,
|
|
45
|
+
trailingColor: trailingColorProp,
|
|
46
|
+
onPressTrailing: onPressTrailingProp,
|
|
47
|
+
icon,
|
|
48
|
+
iconColor,
|
|
49
|
+
onPressIcon,
|
|
46
50
|
onChangeText,
|
|
47
51
|
buttonText = 'Hủy',
|
|
48
52
|
showButtonText = true,
|
|
@@ -59,6 +63,9 @@ const InputSearch: ForwardRefRenderFunction<InputRef, InputSearchProps> = (
|
|
|
59
63
|
ref,
|
|
60
64
|
) => {
|
|
61
65
|
const { theme } = useContext(ApplicationContext);
|
|
66
|
+
const trailing = trailingProp ?? icon;
|
|
67
|
+
const trailingColor = trailingColorProp ?? iconColor;
|
|
68
|
+
const onPressTrailing = onPressTrailingProp ?? onPressIcon;
|
|
62
69
|
const context = useContext<any>(MiniAppContext);
|
|
63
70
|
const scaledFontSize = useScaleSize(INPUT_FONT_SIZE);
|
|
64
71
|
const searchFontFamily = exportFontFamily('regular');
|
|
@@ -64,11 +64,8 @@ export const FloatingButton: React.FC<FloatingButtonProps> = ({
|
|
|
64
64
|
const labelFontFamily = exportFontFamily('bold');
|
|
65
65
|
const maxWidth = useSharedValue(0);
|
|
66
66
|
const minWidth = size === 'small' ? SMALL_SIZE : LARGE_SIZE;
|
|
67
|
-
const iconSize = size === 'small' ? SMALL_ICON_SIZE : LARGE_ICON_SIZE;
|
|
68
67
|
const opacityAnimated = useSharedValue(0);
|
|
69
68
|
const widthAnimated = useSharedValue<number | null>(null);
|
|
70
|
-
const paddingLeftAnimated = useSharedValue(Spacing.M);
|
|
71
|
-
const collapsedPaddingLeft = useSharedValue(Spacing.M);
|
|
72
69
|
const lastOffset = useSharedValue(0);
|
|
73
70
|
const lastDirection = useSharedValue<string | null>(null);
|
|
74
71
|
const [isLabelShown, setIsLabelShown] = useState(true);
|
|
@@ -78,6 +75,12 @@ export const FloatingButton: React.FC<FloatingButtonProps> = ({
|
|
|
78
75
|
opacityAnimated.value = withTiming(1, { duration: ANIMATION_DURATION });
|
|
79
76
|
}, [label, opacityAnimated]);
|
|
80
77
|
|
|
78
|
+
// Re-measure the expanded width when the label or its scaled size changes.
|
|
79
|
+
useEffect(() => {
|
|
80
|
+
if (lastDirection.value === 'down') return;
|
|
81
|
+
widthAnimated.value = null;
|
|
82
|
+
}, [label, scaledFontSize, lastDirection, widthAnimated]);
|
|
83
|
+
|
|
81
84
|
useAnimatedReaction(
|
|
82
85
|
() => sharedValue.value,
|
|
83
86
|
value => {
|
|
@@ -92,9 +95,6 @@ export const FloatingButton: React.FC<FloatingButtonProps> = ({
|
|
|
92
95
|
opacityAnimated.value = withTiming(0, {
|
|
93
96
|
duration: ANIMATION_DURATION,
|
|
94
97
|
});
|
|
95
|
-
paddingLeftAnimated.value = withTiming(collapsedPaddingLeft.value, {
|
|
96
|
-
duration: ANIMATION_DURATION,
|
|
97
|
-
});
|
|
98
98
|
widthAnimated.value = withTiming(
|
|
99
99
|
minWidth,
|
|
100
100
|
{ duration: ANIMATION_DURATION },
|
|
@@ -106,9 +106,6 @@ export const FloatingButton: React.FC<FloatingButtonProps> = ({
|
|
|
106
106
|
opacityAnimated.value = withTiming(1, {
|
|
107
107
|
duration: ANIMATION_DURATION,
|
|
108
108
|
});
|
|
109
|
-
paddingLeftAnimated.value = withTiming(Spacing.M, {
|
|
110
|
-
duration: ANIMATION_DURATION,
|
|
111
|
-
});
|
|
112
109
|
widthAnimated.value = withTiming(
|
|
113
110
|
maxWidth.value,
|
|
114
111
|
{ duration: ANIMATION_DURATION },
|
|
@@ -124,8 +121,8 @@ export const FloatingButton: React.FC<FloatingButtonProps> = ({
|
|
|
124
121
|
);
|
|
125
122
|
|
|
126
123
|
const containerStyle = useAnimatedStyle(() => ({
|
|
127
|
-
width
|
|
128
|
-
|
|
124
|
+
// 'auto' (not undefined) so Reanimated drops the old width and re-lays out.
|
|
125
|
+
width: widthAnimated.value ?? 'auto',
|
|
129
126
|
}));
|
|
130
127
|
|
|
131
128
|
const labelStyle = useAnimatedStyle(() => ({
|
|
@@ -135,14 +132,8 @@ export const FloatingButton: React.FC<FloatingButtonProps> = ({
|
|
|
135
132
|
const handleLayout = (event: LayoutChangeEvent) => {
|
|
136
133
|
const layout = event.nativeEvent.layout;
|
|
137
134
|
if (widthAnimated.value != null) return;
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
maxWidth.value = expandedWidth;
|
|
141
|
-
widthAnimated.value = expandedWidth;
|
|
142
|
-
// collapsed it is a circle as wide as it is tall: center the icon from the
|
|
143
|
-
// rendered height so it stays centered when sizes are scaled but padding is not
|
|
144
|
-
collapsedPaddingLeft.value =
|
|
145
|
-
(layout.height - (layout.height * iconSize) / minWidth) / 2;
|
|
135
|
+
maxWidth.value = layout.width;
|
|
136
|
+
widthAnimated.value = layout.width;
|
|
146
137
|
};
|
|
147
138
|
|
|
148
139
|
if (renderComponent) {
|
|
@@ -174,7 +165,11 @@ export const FloatingButton: React.FC<FloatingButtonProps> = ({
|
|
|
174
165
|
]}
|
|
175
166
|
>
|
|
176
167
|
<TouchableOpacity style={styles.content} onPress={onPress}>
|
|
177
|
-
<Icon
|
|
168
|
+
<Icon
|
|
169
|
+
source={icon}
|
|
170
|
+
size={size === 'small' ? SMALL_ICON_SIZE : LARGE_ICON_SIZE}
|
|
171
|
+
color={iconColor}
|
|
172
|
+
/>
|
|
178
173
|
{isLabelShown && !!label && (
|
|
179
174
|
<Animated.Text
|
|
180
175
|
allowFontScaling={false}
|