@unif/react-native-design 0.33.0 → 0.34.0

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.
Files changed (188) hide show
  1. package/lib/module/components/ui/ActionMenuContent/ActionMenuContent.js +97 -0
  2. package/lib/module/components/ui/ActionMenuContent/ActionMenuContent.js.map +1 -0
  3. package/lib/module/components/ui/ActionMenuContent/index.js +4 -0
  4. package/lib/module/components/ui/ActionMenuContent/index.js.map +1 -0
  5. package/lib/module/components/ui/ActionMenuContent/styles.js +54 -0
  6. package/lib/module/components/ui/ActionMenuContent/styles.js.map +1 -0
  7. package/lib/module/components/ui/ActionMenuContent/types.js.map +1 -0
  8. package/lib/module/components/ui/Avatar/Avatar.js +3 -3
  9. package/lib/module/components/ui/Avatar/Avatar.js.map +1 -1
  10. package/lib/module/components/ui/Button/ButtonBase.js +10 -2
  11. package/lib/module/components/ui/Button/ButtonBase.js.map +1 -1
  12. package/lib/module/components/ui/DrawerHeader/DrawerHeader.js +3 -3
  13. package/lib/module/components/ui/DrawerHeader/DrawerHeader.js.map +1 -1
  14. package/lib/module/components/ui/IconButton/IconButton.js +5 -1
  15. package/lib/module/components/ui/IconButton/IconButton.js.map +1 -1
  16. package/lib/module/components/ui/ImagePreview/ImagePreview.js +200 -0
  17. package/lib/module/components/ui/ImagePreview/ImagePreview.js.map +1 -0
  18. package/lib/module/components/ui/ImagePreview/constants.js +5 -0
  19. package/lib/module/components/ui/ImagePreview/constants.js.map +1 -0
  20. package/lib/module/components/ui/ImagePreview/index.js +4 -0
  21. package/lib/module/components/ui/ImagePreview/index.js.map +1 -0
  22. package/lib/module/components/ui/ImagePreview/styles.js +55 -0
  23. package/lib/module/components/ui/ImagePreview/styles.js.map +1 -0
  24. package/lib/module/components/ui/ImagePreview/types.js +4 -0
  25. package/lib/module/components/ui/ImagePreview/types.js.map +1 -0
  26. package/lib/module/components/ui/Sheet/Sheet.js +40 -0
  27. package/lib/module/components/ui/Sheet/Sheet.js.map +1 -0
  28. package/lib/module/components/ui/Sheet/index.js +4 -0
  29. package/lib/module/components/ui/Sheet/index.js.map +1 -0
  30. package/lib/module/components/ui/Sheet/styles.js +41 -0
  31. package/lib/module/components/ui/Sheet/styles.js.map +1 -0
  32. package/lib/module/components/ui/Sheet/types.js +4 -0
  33. package/lib/module/components/ui/Sheet/types.js.map +1 -0
  34. package/lib/module/components/ui/SmsField/SmsField.js +40 -0
  35. package/lib/module/components/ui/SmsField/SmsField.js.map +1 -0
  36. package/lib/module/components/ui/SmsField/index.js +4 -0
  37. package/lib/module/components/ui/SmsField/index.js.map +1 -0
  38. package/lib/module/components/ui/SmsField/types.js +4 -0
  39. package/lib/module/components/ui/SmsField/types.js.map +1 -0
  40. package/lib/module/components/ui/TextEntryContent/TextEntryContent.js +60 -0
  41. package/lib/module/components/ui/TextEntryContent/TextEntryContent.js.map +1 -0
  42. package/lib/module/components/ui/TextEntryContent/index.js +4 -0
  43. package/lib/module/components/ui/TextEntryContent/index.js.map +1 -0
  44. package/lib/module/components/ui/TextEntryContent/styles.js +29 -0
  45. package/lib/module/components/ui/TextEntryContent/styles.js.map +1 -0
  46. package/lib/module/components/ui/TextEntryContent/types.js +4 -0
  47. package/lib/module/components/ui/TextEntryContent/types.js.map +1 -0
  48. package/lib/module/components/ui/Thumbnail/Thumbnail.js +3 -3
  49. package/lib/module/components/ui/Thumbnail/Thumbnail.js.map +1 -1
  50. package/lib/module/components/ui/index.js +5 -1
  51. package/lib/module/components/ui/index.js.map +1 -1
  52. package/lib/module/components/ui/shared/ImageAttempt.js.map +1 -1
  53. package/lib/module/components/ui/shared/selectImageAttemptSource.shared.js +6 -5
  54. package/lib/module/components/ui/shared/selectImageAttemptSource.shared.js.map +1 -1
  55. package/lib/module/components/ui/shared/useImageSource.js +11 -0
  56. package/lib/module/components/ui/shared/useImageSource.js.map +1 -0
  57. package/lib/module/icons/data.js +87 -1
  58. package/lib/module/icons/data.js.map +1 -1
  59. package/lib/module/utils/imageSource.js +47 -13
  60. package/lib/module/utils/imageSource.js.map +1 -1
  61. package/lib/typescript/src/components/ui/ActionMenuContent/ActionMenuContent.d.ts +4 -0
  62. package/lib/typescript/src/components/ui/ActionMenuContent/ActionMenuContent.d.ts.map +1 -0
  63. package/lib/typescript/src/components/ui/ActionMenuContent/index.d.ts +3 -0
  64. package/lib/typescript/src/components/ui/ActionMenuContent/index.d.ts.map +1 -0
  65. package/lib/typescript/src/components/ui/ActionMenuContent/styles.d.ts +51 -0
  66. package/lib/typescript/src/components/ui/ActionMenuContent/styles.d.ts.map +1 -0
  67. package/lib/typescript/src/components/ui/ActionMenuContent/types.d.ts +25 -0
  68. package/lib/typescript/src/components/ui/ActionMenuContent/types.d.ts.map +1 -0
  69. package/lib/typescript/src/components/ui/Button/ButtonBase.d.ts +3 -1
  70. package/lib/typescript/src/components/ui/Button/ButtonBase.d.ts.map +1 -1
  71. package/lib/typescript/src/components/ui/IconButton/IconButton.d.ts +1 -1
  72. package/lib/typescript/src/components/ui/IconButton/IconButton.d.ts.map +1 -1
  73. package/lib/typescript/src/components/ui/IconButton/types.d.ts +4 -0
  74. package/lib/typescript/src/components/ui/IconButton/types.d.ts.map +1 -1
  75. package/lib/typescript/src/components/ui/ImagePreview/ImagePreview.d.ts +3 -0
  76. package/lib/typescript/src/components/ui/ImagePreview/ImagePreview.d.ts.map +1 -0
  77. package/lib/typescript/src/components/ui/ImagePreview/constants.d.ts +3 -0
  78. package/lib/typescript/src/components/ui/ImagePreview/constants.d.ts.map +1 -0
  79. package/lib/typescript/src/components/ui/ImagePreview/index.d.ts +3 -0
  80. package/lib/typescript/src/components/ui/ImagePreview/index.d.ts.map +1 -0
  81. package/lib/typescript/src/components/ui/ImagePreview/styles.d.ts +56 -0
  82. package/lib/typescript/src/components/ui/ImagePreview/styles.d.ts.map +1 -0
  83. package/lib/typescript/src/components/ui/ImagePreview/types.d.ts +33 -0
  84. package/lib/typescript/src/components/ui/ImagePreview/types.d.ts.map +1 -0
  85. package/lib/typescript/src/components/ui/Sheet/Sheet.d.ts +4 -0
  86. package/lib/typescript/src/components/ui/Sheet/Sheet.d.ts.map +1 -0
  87. package/lib/typescript/src/components/ui/Sheet/index.d.ts +3 -0
  88. package/lib/typescript/src/components/ui/Sheet/index.d.ts.map +1 -0
  89. package/lib/typescript/src/components/ui/Sheet/styles.d.ts +38 -0
  90. package/lib/typescript/src/components/ui/Sheet/styles.d.ts.map +1 -0
  91. package/lib/typescript/src/components/ui/Sheet/types.d.ts +13 -0
  92. package/lib/typescript/src/components/ui/Sheet/types.d.ts.map +1 -0
  93. package/lib/typescript/src/components/ui/SmsField/SmsField.d.ts +4 -0
  94. package/lib/typescript/src/components/ui/SmsField/SmsField.d.ts.map +1 -0
  95. package/lib/typescript/src/components/ui/SmsField/index.d.ts +3 -0
  96. package/lib/typescript/src/components/ui/SmsField/index.d.ts.map +1 -0
  97. package/lib/typescript/src/components/ui/SmsField/types.d.ts +12 -0
  98. package/lib/typescript/src/components/ui/SmsField/types.d.ts.map +1 -0
  99. package/lib/typescript/src/components/ui/TextEntryContent/TextEntryContent.d.ts +4 -0
  100. package/lib/typescript/src/components/ui/TextEntryContent/TextEntryContent.d.ts.map +1 -0
  101. package/lib/typescript/src/components/ui/TextEntryContent/index.d.ts +3 -0
  102. package/lib/typescript/src/components/ui/TextEntryContent/index.d.ts.map +1 -0
  103. package/lib/typescript/src/components/ui/TextEntryContent/styles.d.ts +26 -0
  104. package/lib/typescript/src/components/ui/TextEntryContent/styles.d.ts.map +1 -0
  105. package/lib/typescript/src/components/ui/TextEntryContent/types.d.ts +18 -0
  106. package/lib/typescript/src/components/ui/TextEntryContent/types.d.ts.map +1 -0
  107. package/lib/typescript/src/components/ui/index.d.ts +10 -2
  108. package/lib/typescript/src/components/ui/index.d.ts.map +1 -1
  109. package/lib/typescript/src/components/ui/shared/ImageAttempt.d.ts +3 -2
  110. package/lib/typescript/src/components/ui/shared/ImageAttempt.d.ts.map +1 -1
  111. package/lib/typescript/src/components/ui/shared/selectImageAttemptSource.shared.d.ts +3 -2
  112. package/lib/typescript/src/components/ui/shared/selectImageAttemptSource.shared.d.ts.map +1 -1
  113. package/lib/typescript/src/components/ui/shared/useImageSource.d.ts +6 -0
  114. package/lib/typescript/src/components/ui/shared/useImageSource.d.ts.map +1 -0
  115. package/lib/typescript/src/icons/data.d.ts +1 -1
  116. package/lib/typescript/src/icons/data.d.ts.map +1 -1
  117. package/lib/typescript/src/utils/imageSource.d.ts +3 -2
  118. package/lib/typescript/src/utils/imageSource.d.ts.map +1 -1
  119. package/lib/typescript/type-tests/content-api.d.ts +2 -0
  120. package/lib/typescript/type-tests/content-api.d.ts.map +1 -0
  121. package/package.json +1 -1
  122. package/src/components/ui/ActionMenuContent/ActionMenuContent.tsx +118 -0
  123. package/src/components/ui/ActionMenuContent/index.ts +6 -0
  124. package/src/components/ui/ActionMenuContent/styles.ts +47 -0
  125. package/src/components/ui/ActionMenuContent/types.ts +27 -0
  126. package/src/components/ui/Avatar/Avatar.tsx +3 -3
  127. package/src/components/ui/Button/ButtonBase.tsx +11 -2
  128. package/src/components/ui/DrawerHeader/DrawerHeader.tsx +3 -3
  129. package/src/components/ui/IconButton/IconButton.tsx +9 -1
  130. package/src/components/ui/IconButton/types.ts +4 -0
  131. package/src/components/ui/ImagePreview/ImagePreview.tsx +243 -0
  132. package/src/components/ui/ImagePreview/constants.ts +2 -0
  133. package/src/components/ui/ImagePreview/index.ts +6 -0
  134. package/src/components/ui/ImagePreview/styles.ts +48 -0
  135. package/src/components/ui/ImagePreview/types.ts +37 -0
  136. package/src/components/ui/Sheet/Sheet.tsx +43 -0
  137. package/src/components/ui/Sheet/index.ts +2 -0
  138. package/src/components/ui/Sheet/styles.ts +40 -0
  139. package/src/components/ui/Sheet/types.ts +14 -0
  140. package/src/components/ui/SmsField/SmsField.tsx +40 -0
  141. package/src/components/ui/SmsField/index.ts +2 -0
  142. package/src/components/ui/SmsField/types.ts +15 -0
  143. package/src/components/ui/TextEntryContent/TextEntryContent.tsx +56 -0
  144. package/src/components/ui/TextEntryContent/index.ts +2 -0
  145. package/src/components/ui/TextEntryContent/styles.ts +17 -0
  146. package/src/components/ui/TextEntryContent/types.ts +18 -0
  147. package/src/components/ui/Thumbnail/Thumbnail.tsx +3 -3
  148. package/src/components/ui/index.ts +18 -2
  149. package/src/components/ui/shared/ImageAttempt.tsx +3 -2
  150. package/src/components/ui/shared/selectImageAttemptSource.shared.ts +7 -5
  151. package/src/components/ui/shared/useImageSource.ts +8 -0
  152. package/src/icons/data.ts +134 -0
  153. package/src/utils/imageSource.ts +78 -15
  154. package/lib/module/components/ui/BorderBeam/BorderBeam.js +0 -102
  155. package/lib/module/components/ui/BorderBeam/BorderBeam.js.map +0 -1
  156. package/lib/module/components/ui/BorderBeam/BorderBeam.web.js +0 -108
  157. package/lib/module/components/ui/BorderBeam/BorderBeam.web.js.map +0 -1
  158. package/lib/module/components/ui/BorderBeam/index.js +0 -4
  159. package/lib/module/components/ui/BorderBeam/index.js.map +0 -1
  160. package/lib/module/components/ui/BorderBeam/normalizeBorderBeam.js +0 -23
  161. package/lib/module/components/ui/BorderBeam/normalizeBorderBeam.js.map +0 -1
  162. package/lib/module/components/ui/BorderBeam/shared.js +0 -54
  163. package/lib/module/components/ui/BorderBeam/shared.js.map +0 -1
  164. package/lib/module/components/ui/BorderBeam/styles.js +0 -18
  165. package/lib/module/components/ui/BorderBeam/styles.js.map +0 -1
  166. package/lib/module/components/ui/BorderBeam/types.js.map +0 -1
  167. package/lib/typescript/src/components/ui/BorderBeam/BorderBeam.d.ts +0 -10
  168. package/lib/typescript/src/components/ui/BorderBeam/BorderBeam.d.ts.map +0 -1
  169. package/lib/typescript/src/components/ui/BorderBeam/BorderBeam.web.d.ts +0 -5
  170. package/lib/typescript/src/components/ui/BorderBeam/BorderBeam.web.d.ts.map +0 -1
  171. package/lib/typescript/src/components/ui/BorderBeam/index.d.ts +0 -3
  172. package/lib/typescript/src/components/ui/BorderBeam/index.d.ts.map +0 -1
  173. package/lib/typescript/src/components/ui/BorderBeam/normalizeBorderBeam.d.ts +0 -16
  174. package/lib/typescript/src/components/ui/BorderBeam/normalizeBorderBeam.d.ts.map +0 -1
  175. package/lib/typescript/src/components/ui/BorderBeam/shared.d.ts +0 -28
  176. package/lib/typescript/src/components/ui/BorderBeam/shared.d.ts.map +0 -1
  177. package/lib/typescript/src/components/ui/BorderBeam/styles.d.ts +0 -15
  178. package/lib/typescript/src/components/ui/BorderBeam/styles.d.ts.map +0 -1
  179. package/lib/typescript/src/components/ui/BorderBeam/types.d.ts +0 -23
  180. package/lib/typescript/src/components/ui/BorderBeam/types.d.ts.map +0 -1
  181. package/src/components/ui/BorderBeam/BorderBeam.tsx +0 -130
  182. package/src/components/ui/BorderBeam/BorderBeam.web.tsx +0 -127
  183. package/src/components/ui/BorderBeam/index.ts +0 -2
  184. package/src/components/ui/BorderBeam/normalizeBorderBeam.ts +0 -58
  185. package/src/components/ui/BorderBeam/shared.ts +0 -47
  186. package/src/components/ui/BorderBeam/styles.ts +0 -16
  187. package/src/components/ui/BorderBeam/types.ts +0 -23
  188. /package/lib/module/components/ui/{BorderBeam → ActionMenuContent}/types.js +0 -0
@@ -1,15 +0,0 @@
1
- export declare const styles: Readonly<{
2
- container: {
3
- position: "relative";
4
- };
5
- visual: {
6
- position: "absolute";
7
- top: number;
8
- right: number;
9
- bottom: number;
10
- left: number;
11
- zIndex: number;
12
- elevation: number;
13
- };
14
- }>;
15
- //# sourceMappingURL=styles.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../../../../../../src/components/ui/BorderBeam/styles.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,MAAM;;;;;;;;;;;;;EAajB,CAAC"}
@@ -1,23 +0,0 @@
1
- import type { ReactNode } from 'react';
2
- import type { StyleProp, ViewStyle } from 'react-native';
3
- export type BorderBeamProps = {
4
- /** 被流光描边包围的内容。 */
5
- children: ReactNode;
6
- /** 是否显示并运行动画,默认 true。 */
7
- active?: boolean;
8
- /** 流光颜色,默认主题 primary。 */
9
- color?: string;
10
- /** 绕边一周的时长(毫秒),默认 2400。 */
11
- duration?: number;
12
- /** 描边宽度,默认 2。 */
13
- lineWidth?: number;
14
- /** 流光段长度(布局单位),默认 40。 */
15
- size?: number;
16
- /** 圆角半径,默认 radius.md。 */
17
- borderRadius?: number;
18
- /** 外层布局样式。 */
19
- style?: StyleProp<ViewStyle>;
20
- /** E2E / 测试定位。 */
21
- testID?: string;
22
- };
23
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../../src/components/ui/BorderBeam/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzD,MAAM,MAAM,eAAe,GAAG;IAC5B,kBAAkB;IAClB,QAAQ,EAAE,SAAS,CAAC;IACpB,yBAAyB;IACzB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,yBAAyB;IACzB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,2BAA2B;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,iBAAiB;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,yBAAyB;IACzB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,yBAAyB;IACzB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,cAAc;IACd,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAC7B,kBAAkB;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC"}
@@ -1,130 +0,0 @@
1
- import React, { useEffect, useState } from 'react';
2
- import type { LayoutChangeEvent } from 'react-native';
3
- import { View } from 'react-native';
4
- import Animated, {
5
- cancelAnimation,
6
- Easing,
7
- ReduceMotion,
8
- useAnimatedProps,
9
- useSharedValue,
10
- withRepeat,
11
- withTiming,
12
- } from 'react-native-reanimated';
13
- import Svg, { Rect } from 'react-native-svg';
14
-
15
- import { radius, useColors, usePrefersReducedMotion } from '../../../theme';
16
- import { A11Y_HIDDEN_PROPS } from '../shared/a11y';
17
- import { normalizeBorderBeam } from './normalizeBorderBeam';
18
- import {
19
- borderBeamGeometry,
20
- borderBeamTrail,
21
- EMPTY_BORDER_BEAM_LAYOUT,
22
- } from './shared';
23
- import { styles } from './styles';
24
- import type { BorderBeamProps } from './types';
25
-
26
- const AnimatedRect = Animated.createAnimatedComponent(Rect);
27
-
28
- /**
29
- * 沿内容边缘循环移动的装饰性流光描边。
30
- *
31
- * 组件不承载加载、错误或焦点语义;业务状态仍由调用方自己的可访问元素表达。
32
- * 系统开启「减弱动态效果」时隐藏流光,只保留原内容。
33
- */
34
- export function BorderBeam({
35
- children,
36
- active = true,
37
- color,
38
- duration,
39
- lineWidth,
40
- size,
41
- borderRadius = radius.md,
42
- style,
43
- testID,
44
- }: BorderBeamProps): React.JSX.Element {
45
- const colors = useColors();
46
- const reducedMotion = usePrefersReducedMotion();
47
- const [layout, setLayout] = useState(EMPTY_BORDER_BEAM_LAYOUT);
48
- const normalized = normalizeBorderBeam({
49
- duration,
50
- lineWidth,
51
- size,
52
- borderRadius,
53
- });
54
- const geometry = borderBeamGeometry({ layout, ...normalized });
55
- const trail = borderBeamTrail(geometry.beamLength);
56
- const dashOffset = useSharedValue(0);
57
- const showVisual = active && !reducedMotion && geometry.perimeter > 0;
58
-
59
- useEffect(() => {
60
- cancelAnimation(dashOffset);
61
- dashOffset.value = 0;
62
- if (!showVisual) return;
63
- dashOffset.value = withRepeat(
64
- withTiming(-geometry.perimeter, {
65
- duration: normalized.duration,
66
- easing: Easing.linear,
67
- reduceMotion: ReduceMotion.System,
68
- }),
69
- -1,
70
- false,
71
- undefined,
72
- ReduceMotion.System
73
- );
74
- return () => cancelAnimation(dashOffset);
75
- }, [dashOffset, geometry.perimeter, normalized.duration, showVisual]);
76
-
77
- const animatedProps = useAnimatedProps(() => ({
78
- strokeDashoffset: dashOffset.value,
79
- }));
80
- const handleLayout = (event: LayoutChangeEvent): void => {
81
- const width = Math.max(0, event.nativeEvent.layout.width);
82
- const height = Math.max(0, event.nativeEvent.layout.height);
83
- setLayout((current) =>
84
- current.width === width && current.height === height
85
- ? current
86
- : { width, height }
87
- );
88
- };
89
-
90
- return (
91
- <View
92
- onLayout={handleLayout}
93
- style={[
94
- styles.container,
95
- { borderRadius: normalized.borderRadius },
96
- style,
97
- ]}
98
- testID={testID}
99
- >
100
- {children}
101
- {showVisual ? (
102
- <View pointerEvents="none" style={styles.visual} {...A11Y_HIDDEN_PROPS}>
103
- <Svg width={layout.width} height={layout.height}>
104
- {trail.map((layer) => (
105
- <AnimatedRect
106
- key={`${layer.length}-${layer.opacity}`}
107
- animatedProps={animatedProps}
108
- x={normalized.lineWidth / 2}
109
- y={normalized.lineWidth / 2}
110
- width={geometry.rectWidth}
111
- height={geometry.rectHeight}
112
- rx={geometry.radius}
113
- ry={geometry.radius}
114
- fill="none"
115
- stroke={color ?? colors.primary}
116
- strokeOpacity={layer.opacity}
117
- strokeWidth={normalized.lineWidth}
118
- strokeLinecap="round"
119
- strokeDasharray={[
120
- layer.length,
121
- Math.max(0, geometry.perimeter - layer.length),
122
- ]}
123
- />
124
- ))}
125
- </Svg>
126
- </View>
127
- ) : null}
128
- </View>
129
- );
130
- }
@@ -1,127 +0,0 @@
1
- import React, { useEffect, useRef, useState } from 'react';
2
- import type { LayoutChangeEvent } from 'react-native';
3
- import { View } from 'react-native';
4
- import Svg, { Rect } from 'react-native-svg';
5
-
6
- import { radius, useColors, usePrefersReducedMotion } from '../../../theme';
7
- import { A11Y_HIDDEN_PROPS } from '../shared/a11y';
8
- import { normalizeBorderBeam } from './normalizeBorderBeam';
9
- import {
10
- borderBeamGeometry,
11
- borderBeamTrail,
12
- EMPTY_BORDER_BEAM_LAYOUT,
13
- } from './shared';
14
- import { styles } from './styles';
15
- import type { BorderBeamProps } from './types';
16
-
17
- const KEYFRAMES_ID = 'unif-border-beam-keyframes';
18
- const win: any = globalThis as any;
19
-
20
- function ensureKeyframes(): void {
21
- if (typeof win.document === 'undefined') return;
22
- if (win.document.getElementById(KEYFRAMES_ID)) return;
23
- const sheet = win.document.createElement('style');
24
- sheet.id = KEYFRAMES_ID;
25
- sheet.textContent =
26
- '@keyframes unif-border-beam-flow { from { stroke-dashoffset: 0; } to { stroke-dashoffset: calc(-1 * var(--unif-border-beam-path)); } }';
27
- win.document.head.appendChild(sheet);
28
- }
29
-
30
- /** Web 版用 CSS keyframes 插值,JS 只在布局或 props 变化时更新一次。 */
31
- export function BorderBeam({
32
- children,
33
- active = true,
34
- color,
35
- duration,
36
- lineWidth,
37
- size,
38
- borderRadius = radius.md,
39
- style,
40
- testID,
41
- }: BorderBeamProps): React.JSX.Element {
42
- const colors = useColors();
43
- const reducedMotion = usePrefersReducedMotion();
44
- const [layout, setLayout] = useState(EMPTY_BORDER_BEAM_LAYOUT);
45
- const rectRefs = useRef<any[]>([]);
46
- const normalized = normalizeBorderBeam({
47
- duration,
48
- lineWidth,
49
- size,
50
- borderRadius,
51
- });
52
- const geometry = borderBeamGeometry({ layout, ...normalized });
53
- const trail = borderBeamTrail(geometry.beamLength);
54
- const showVisual = active && !reducedMotion && geometry.perimeter > 0;
55
-
56
- useEffect(() => {
57
- if (!showVisual) return;
58
- ensureKeyframes();
59
- const nodes = rectRefs.current.filter((node) => node?.style);
60
- if (nodes.length === 0) return;
61
- nodes.forEach((node) => {
62
- node.style.setProperty(
63
- '--unif-border-beam-path',
64
- `${geometry.perimeter}px`
65
- );
66
- node.style.animation = `unif-border-beam-flow ${normalized.duration}ms linear infinite`;
67
- });
68
- return () => {
69
- nodes.forEach((node) => {
70
- node.style.animation = '';
71
- });
72
- };
73
- }, [geometry.perimeter, normalized.duration, showVisual]);
74
-
75
- const handleLayout = (event: LayoutChangeEvent): void => {
76
- const width = Math.max(0, event.nativeEvent.layout.width);
77
- const height = Math.max(0, event.nativeEvent.layout.height);
78
- setLayout((current) =>
79
- current.width === width && current.height === height
80
- ? current
81
- : { width, height }
82
- );
83
- };
84
-
85
- return (
86
- <View
87
- onLayout={handleLayout}
88
- style={[
89
- styles.container,
90
- { borderRadius: normalized.borderRadius },
91
- style,
92
- ]}
93
- testID={testID}
94
- >
95
- {children}
96
- {showVisual ? (
97
- <View pointerEvents="none" style={styles.visual} {...A11Y_HIDDEN_PROPS}>
98
- <Svg width={layout.width} height={layout.height}>
99
- {trail.map((layer, index) => (
100
- <Rect
101
- key={`${layer.length}-${layer.opacity}`}
102
- ref={(node) => {
103
- rectRefs.current[index] = node;
104
- }}
105
- x={normalized.lineWidth / 2}
106
- y={normalized.lineWidth / 2}
107
- width={geometry.rectWidth}
108
- height={geometry.rectHeight}
109
- rx={geometry.radius}
110
- ry={geometry.radius}
111
- fill="none"
112
- stroke={color ?? colors.primary}
113
- strokeOpacity={layer.opacity}
114
- strokeWidth={normalized.lineWidth}
115
- strokeLinecap="round"
116
- strokeDasharray={[
117
- layer.length,
118
- Math.max(0, geometry.perimeter - layer.length),
119
- ]}
120
- />
121
- ))}
122
- </Svg>
123
- </View>
124
- ) : null}
125
- </View>
126
- );
127
- }
@@ -1,2 +0,0 @@
1
- export { BorderBeam } from './BorderBeam';
2
- export type { BorderBeamProps } from './types';
@@ -1,58 +0,0 @@
1
- export type NormalizedBorderBeam = {
2
- duration: number;
3
- lineWidth: number;
4
- size: number;
5
- borderRadius: number;
6
- };
7
-
8
- export const BORDER_BEAM_DEFAULTS: NormalizedBorderBeam = {
9
- duration: 2400,
10
- lineWidth: 2,
11
- size: 40,
12
- borderRadius: 12,
13
- };
14
-
15
- type BorderBeamNumbers = Partial<NormalizedBorderBeam>;
16
-
17
- const normalizeNumber = (
18
- value: number | undefined,
19
- fallback: number,
20
- min: number,
21
- max: number,
22
- allowZero = false
23
- ): number => {
24
- if (
25
- typeof value !== 'number' ||
26
- !Number.isFinite(value) ||
27
- value < 0 ||
28
- (!allowZero && value === 0)
29
- ) {
30
- return fallback;
31
- }
32
- return Math.min(max, Math.max(min, value));
33
- };
34
-
35
- export function normalizeBorderBeam(input: BorderBeamNumbers) {
36
- return {
37
- duration: normalizeNumber(
38
- input.duration,
39
- BORDER_BEAM_DEFAULTS.duration,
40
- 300,
41
- 60_000
42
- ),
43
- lineWidth: normalizeNumber(
44
- input.lineWidth,
45
- BORDER_BEAM_DEFAULTS.lineWidth,
46
- 0.5,
47
- 8
48
- ),
49
- size: normalizeNumber(input.size, BORDER_BEAM_DEFAULTS.size, 8, 1_000),
50
- borderRadius: normalizeNumber(
51
- input.borderRadius,
52
- BORDER_BEAM_DEFAULTS.borderRadius,
53
- 0,
54
- 1_000,
55
- true
56
- ),
57
- };
58
- }
@@ -1,47 +0,0 @@
1
- export type BorderBeamLayout = Readonly<{ width: number; height: number }>;
2
-
3
- export const EMPTY_BORDER_BEAM_LAYOUT: BorderBeamLayout = {
4
- width: 0,
5
- height: 0,
6
- };
7
-
8
- const BORDER_BEAM_TRAIL = [
9
- { lengthRatio: 1, opacity: 0.12 },
10
- { lengthRatio: 0.75, opacity: 0.24 },
11
- { lengthRatio: 0.5, opacity: 0.42 },
12
- { lengthRatio: 0.25, opacity: 0.88 },
13
- ] as const;
14
-
15
- /**
16
- * 把单色线段拆成由淡到亮的叠加尾迹。
17
- *
18
- * 所有层共享同一动画相位,较短且更亮的层叠在前端,形成接近渐变的彗星头;
19
- * 同时避免 SVG gradient 在 Native/Web 上的实现差异。
20
- */
21
- export function borderBeamTrail(beamLength: number) {
22
- const safeLength = Math.max(0, beamLength);
23
- return BORDER_BEAM_TRAIL.map(({ lengthRatio, opacity }) => ({
24
- length: safeLength * lengthRatio,
25
- opacity,
26
- }));
27
- }
28
-
29
- export function borderBeamGeometry(input: {
30
- layout: BorderBeamLayout;
31
- lineWidth: number;
32
- size: number;
33
- borderRadius: number;
34
- }) {
35
- const { layout, lineWidth } = input;
36
- const rectWidth = Math.max(0, layout.width - lineWidth);
37
- const rectHeight = Math.max(0, layout.height - lineWidth);
38
- const perimeter = Math.max(0, 2 * (rectWidth + rectHeight));
39
- const beamLength = Math.min(input.size, perimeter / 2);
40
- return {
41
- beamLength,
42
- perimeter,
43
- rectHeight,
44
- rectWidth,
45
- radius: Math.min(input.borderRadius, rectWidth / 2, rectHeight / 2),
46
- };
47
- }
@@ -1,16 +0,0 @@
1
- import { StyleSheet } from 'react-native';
2
-
3
- export const styles = StyleSheet.create({
4
- container: {
5
- position: 'relative',
6
- },
7
- visual: {
8
- position: 'absolute',
9
- top: 0,
10
- right: 0,
11
- bottom: 0,
12
- left: 0,
13
- zIndex: 1,
14
- elevation: 1,
15
- },
16
- });
@@ -1,23 +0,0 @@
1
- import type { ReactNode } from 'react';
2
- import type { StyleProp, ViewStyle } from 'react-native';
3
-
4
- export type BorderBeamProps = {
5
- /** 被流光描边包围的内容。 */
6
- children: ReactNode;
7
- /** 是否显示并运行动画,默认 true。 */
8
- active?: boolean;
9
- /** 流光颜色,默认主题 primary。 */
10
- color?: string;
11
- /** 绕边一周的时长(毫秒),默认 2400。 */
12
- duration?: number;
13
- /** 描边宽度,默认 2。 */
14
- lineWidth?: number;
15
- /** 流光段长度(布局单位),默认 40。 */
16
- size?: number;
17
- /** 圆角半径,默认 radius.md。 */
18
- borderRadius?: number;
19
- /** 外层布局样式。 */
20
- style?: StyleProp<ViewStyle>;
21
- /** E2E / 测试定位。 */
22
- testID?: string;
23
- };