@momo-kits/collapse 0.153.2 → 0.154.1-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.
- package/index.tsx +50 -28
- package/package.json +1 -1
package/index.tsx
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, {
|
|
2
|
+
useContext,
|
|
3
|
+
useImperativeHandle,
|
|
4
|
+
useMemo,
|
|
5
|
+
useState,
|
|
6
|
+
} from 'react';
|
|
2
7
|
import {
|
|
3
8
|
Animated,
|
|
4
9
|
LayoutAnimation,
|
|
@@ -14,12 +19,12 @@ import {
|
|
|
14
19
|
Icon,
|
|
15
20
|
Image,
|
|
16
21
|
MiniAppContext,
|
|
17
|
-
|
|
22
|
+
useScaleSize,
|
|
18
23
|
ScreenContext,
|
|
19
24
|
Tag,
|
|
20
25
|
Text,
|
|
21
26
|
} from '@momo-kits/foundation';
|
|
22
|
-
import {CollapseHandle, CollapseImageSize, CollapseProps} from './types';
|
|
27
|
+
import { CollapseHandle, CollapseImageSize, CollapseProps } from './types';
|
|
23
28
|
import styles from './styles';
|
|
24
29
|
|
|
25
30
|
if (Platform.OS === 'android') {
|
|
@@ -52,11 +57,19 @@ const Collapse = React.forwardRef<CollapseHandle, CollapseProps>(
|
|
|
52
57
|
backgroundColor,
|
|
53
58
|
titleColor,
|
|
54
59
|
},
|
|
55
|
-
ref
|
|
60
|
+
ref,
|
|
56
61
|
) => {
|
|
57
|
-
const {theme} = useContext(ApplicationContext);
|
|
62
|
+
const { theme } = useContext(ApplicationContext);
|
|
58
63
|
const [expanded, setExpanded] = useState(expandDefault);
|
|
59
64
|
|
|
65
|
+
// Dynamic font sizes using useScaleSize
|
|
66
|
+
const fontSize14 = useScaleSize(14);
|
|
67
|
+
const lineHeight20 = useScaleSize(20);
|
|
68
|
+
const fontSize16 = useScaleSize(16);
|
|
69
|
+
const lineHeight22 = useScaleSize(22);
|
|
70
|
+
const fontSize18 = useScaleSize(18);
|
|
71
|
+
const lineHeight26 = useScaleSize(26);
|
|
72
|
+
|
|
60
73
|
const app = useContext<any>(MiniAppContext);
|
|
61
74
|
const screen = useContext<any>(ScreenContext);
|
|
62
75
|
const componentName = 'Collapse';
|
|
@@ -77,26 +90,26 @@ const Collapse = React.forwardRef<CollapseHandle, CollapseProps>(
|
|
|
77
90
|
switch (titleSize) {
|
|
78
91
|
case 'small': {
|
|
79
92
|
return {
|
|
80
|
-
fontSize:
|
|
81
|
-
lineHeight:
|
|
93
|
+
fontSize: fontSize14,
|
|
94
|
+
lineHeight: lineHeight20,
|
|
82
95
|
};
|
|
83
96
|
}
|
|
84
97
|
case 'medium': {
|
|
85
98
|
return {
|
|
86
|
-
fontSize:
|
|
87
|
-
lineHeight:
|
|
99
|
+
fontSize: fontSize16,
|
|
100
|
+
lineHeight: lineHeight22,
|
|
88
101
|
};
|
|
89
102
|
}
|
|
90
103
|
case 'large': {
|
|
91
104
|
return {
|
|
92
|
-
fontSize:
|
|
93
|
-
lineHeight:
|
|
105
|
+
fontSize: fontSize18,
|
|
106
|
+
lineHeight: lineHeight26,
|
|
94
107
|
};
|
|
95
108
|
}
|
|
96
109
|
default: {
|
|
97
110
|
return {
|
|
98
|
-
fontSize:
|
|
99
|
-
lineHeight:
|
|
111
|
+
fontSize: fontSize14,
|
|
112
|
+
lineHeight: lineHeight20,
|
|
100
113
|
};
|
|
101
114
|
}
|
|
102
115
|
}
|
|
@@ -113,7 +126,8 @@ const Collapse = React.forwardRef<CollapseHandle, CollapseProps>(
|
|
|
113
126
|
<Text
|
|
114
127
|
numberOfLines={1}
|
|
115
128
|
typography={'body_default_regular'}
|
|
116
|
-
accessibilityLabel={componentId + '|sub-title-text'}
|
|
129
|
+
accessibilityLabel={componentId + '|sub-title-text'}
|
|
130
|
+
>
|
|
117
131
|
{subTitle}
|
|
118
132
|
</Text>
|
|
119
133
|
);
|
|
@@ -140,7 +154,7 @@ const Collapse = React.forwardRef<CollapseHandle, CollapseProps>(
|
|
|
140
154
|
type: LayoutAnimation.Types.easeInEaseOut,
|
|
141
155
|
property: LayoutAnimation.Properties.opacity,
|
|
142
156
|
},
|
|
143
|
-
update: {type: LayoutAnimation.Types.easeInEaseOut},
|
|
157
|
+
update: { type: LayoutAnimation.Types.easeInEaseOut },
|
|
144
158
|
});
|
|
145
159
|
|
|
146
160
|
setExpanded(!expanded);
|
|
@@ -155,7 +169,8 @@ const Collapse = React.forwardRef<CollapseHandle, CollapseProps>(
|
|
|
155
169
|
{
|
|
156
170
|
backgroundColor: theme.colors.background.tonal,
|
|
157
171
|
},
|
|
158
|
-
]}
|
|
172
|
+
]}
|
|
173
|
+
>
|
|
159
174
|
<Icon
|
|
160
175
|
color={theme.colors.primary}
|
|
161
176
|
source={iconSource}
|
|
@@ -185,11 +200,12 @@ const Collapse = React.forwardRef<CollapseHandle, CollapseProps>(
|
|
|
185
200
|
},
|
|
186
201
|
]}
|
|
187
202
|
accessibilityLabel={componentId + '|touch'}
|
|
188
|
-
accessibilityState={{checked: expanded}}
|
|
203
|
+
accessibilityState={{ checked: expanded }}
|
|
204
|
+
>
|
|
189
205
|
{!!image && (
|
|
190
206
|
<Image
|
|
191
|
-
source={{uri: image}}
|
|
192
|
-
style={[styles.image, {width: imageSize, height: imageSize}]}
|
|
207
|
+
source={{ uri: image }}
|
|
208
|
+
style={[styles.image, { width: imageSize, height: imageSize }]}
|
|
193
209
|
accessibilityLabel={componentId + '|img'}
|
|
194
210
|
/>
|
|
195
211
|
)}
|
|
@@ -203,19 +219,22 @@ const Collapse = React.forwardRef<CollapseHandle, CollapseProps>(
|
|
|
203
219
|
color: titleColor ?? theme.colors.text.default,
|
|
204
220
|
},
|
|
205
221
|
]}
|
|
206
|
-
|
|
222
|
+
allowFontScaling={false}
|
|
223
|
+
accessibilityLabel={componentId + '|text'}
|
|
224
|
+
>
|
|
207
225
|
{title}
|
|
208
226
|
</RNText>
|
|
209
227
|
{!!description && (
|
|
210
228
|
<Text
|
|
211
229
|
numberOfLines={2}
|
|
212
230
|
typography={'body_default_regular'}
|
|
213
|
-
accessibilityLabel={componentId + '|description-text'}
|
|
231
|
+
accessibilityLabel={componentId + '|description-text'}
|
|
232
|
+
>
|
|
214
233
|
{description}
|
|
215
234
|
</Text>
|
|
216
235
|
)}
|
|
217
236
|
</View>
|
|
218
|
-
<View style={[styles.infoWrap, {justifyContent: headerAlign}]}>
|
|
237
|
+
<View style={[styles.infoWrap, { justifyContent: headerAlign }]}>
|
|
219
238
|
{renderInfo()}
|
|
220
239
|
</View>
|
|
221
240
|
</View>
|
|
@@ -242,7 +261,8 @@ const Collapse = React.forwardRef<CollapseHandle, CollapseProps>(
|
|
|
242
261
|
borderTopWidth: borderWidth,
|
|
243
262
|
borderColor,
|
|
244
263
|
},
|
|
245
|
-
]}
|
|
264
|
+
]}
|
|
265
|
+
>
|
|
246
266
|
{expanded && children}
|
|
247
267
|
</ParentComponent>
|
|
248
268
|
);
|
|
@@ -256,7 +276,8 @@ const Collapse = React.forwardRef<CollapseHandle, CollapseProps>(
|
|
|
256
276
|
borderTopWidth: borderWidth,
|
|
257
277
|
borderColor,
|
|
258
278
|
},
|
|
259
|
-
]}
|
|
279
|
+
]}
|
|
280
|
+
>
|
|
260
281
|
{expanded && children}
|
|
261
282
|
</ParentComponent>
|
|
262
283
|
);
|
|
@@ -271,13 +292,14 @@ const Collapse = React.forwardRef<CollapseHandle, CollapseProps>(
|
|
|
271
292
|
backgroundColor: backgroundColor ?? theme.colors.background.surface,
|
|
272
293
|
},
|
|
273
294
|
]}
|
|
274
|
-
accessibilityLabel={componentId}
|
|
295
|
+
accessibilityLabel={componentId}
|
|
296
|
+
>
|
|
275
297
|
{renderHeader()}
|
|
276
298
|
{renderContent()}
|
|
277
299
|
</View>
|
|
278
300
|
);
|
|
279
|
-
}
|
|
301
|
+
},
|
|
280
302
|
);
|
|
281
303
|
|
|
282
|
-
export {Collapse};
|
|
283
|
-
export type {CollapseProps, CollapseImageSize};
|
|
304
|
+
export { Collapse };
|
|
305
|
+
export type { CollapseProps, CollapseImageSize };
|