@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.
- package/lib/module/components/ui/ActionMenuContent/ActionMenuContent.js +97 -0
- package/lib/module/components/ui/ActionMenuContent/ActionMenuContent.js.map +1 -0
- package/lib/module/components/ui/ActionMenuContent/index.js +4 -0
- package/lib/module/components/ui/ActionMenuContent/index.js.map +1 -0
- package/lib/module/components/ui/ActionMenuContent/styles.js +54 -0
- package/lib/module/components/ui/ActionMenuContent/styles.js.map +1 -0
- package/lib/module/components/ui/ActionMenuContent/types.js.map +1 -0
- package/lib/module/components/ui/Avatar/Avatar.js +3 -3
- package/lib/module/components/ui/Avatar/Avatar.js.map +1 -1
- package/lib/module/components/ui/Button/ButtonBase.js +10 -2
- package/lib/module/components/ui/Button/ButtonBase.js.map +1 -1
- package/lib/module/components/ui/DrawerHeader/DrawerHeader.js +3 -3
- package/lib/module/components/ui/DrawerHeader/DrawerHeader.js.map +1 -1
- package/lib/module/components/ui/IconButton/IconButton.js +5 -1
- package/lib/module/components/ui/IconButton/IconButton.js.map +1 -1
- package/lib/module/components/ui/ImagePreview/ImagePreview.js +200 -0
- package/lib/module/components/ui/ImagePreview/ImagePreview.js.map +1 -0
- package/lib/module/components/ui/ImagePreview/constants.js +5 -0
- package/lib/module/components/ui/ImagePreview/constants.js.map +1 -0
- package/lib/module/components/ui/ImagePreview/index.js +4 -0
- package/lib/module/components/ui/ImagePreview/index.js.map +1 -0
- package/lib/module/components/ui/ImagePreview/styles.js +55 -0
- package/lib/module/components/ui/ImagePreview/styles.js.map +1 -0
- package/lib/module/components/ui/ImagePreview/types.js +4 -0
- package/lib/module/components/ui/ImagePreview/types.js.map +1 -0
- package/lib/module/components/ui/Sheet/Sheet.js +40 -0
- package/lib/module/components/ui/Sheet/Sheet.js.map +1 -0
- package/lib/module/components/ui/Sheet/index.js +4 -0
- package/lib/module/components/ui/Sheet/index.js.map +1 -0
- package/lib/module/components/ui/Sheet/styles.js +41 -0
- package/lib/module/components/ui/Sheet/styles.js.map +1 -0
- package/lib/module/components/ui/Sheet/types.js +4 -0
- package/lib/module/components/ui/Sheet/types.js.map +1 -0
- package/lib/module/components/ui/SmsField/SmsField.js +40 -0
- package/lib/module/components/ui/SmsField/SmsField.js.map +1 -0
- package/lib/module/components/ui/SmsField/index.js +4 -0
- package/lib/module/components/ui/SmsField/index.js.map +1 -0
- package/lib/module/components/ui/SmsField/types.js +4 -0
- package/lib/module/components/ui/SmsField/types.js.map +1 -0
- package/lib/module/components/ui/TextEntryContent/TextEntryContent.js +60 -0
- package/lib/module/components/ui/TextEntryContent/TextEntryContent.js.map +1 -0
- package/lib/module/components/ui/TextEntryContent/index.js +4 -0
- package/lib/module/components/ui/TextEntryContent/index.js.map +1 -0
- package/lib/module/components/ui/TextEntryContent/styles.js +29 -0
- package/lib/module/components/ui/TextEntryContent/styles.js.map +1 -0
- package/lib/module/components/ui/TextEntryContent/types.js +4 -0
- package/lib/module/components/ui/TextEntryContent/types.js.map +1 -0
- package/lib/module/components/ui/Thumbnail/Thumbnail.js +3 -3
- package/lib/module/components/ui/Thumbnail/Thumbnail.js.map +1 -1
- package/lib/module/components/ui/index.js +5 -1
- package/lib/module/components/ui/index.js.map +1 -1
- package/lib/module/components/ui/shared/ImageAttempt.js.map +1 -1
- package/lib/module/components/ui/shared/selectImageAttemptSource.shared.js +6 -5
- package/lib/module/components/ui/shared/selectImageAttemptSource.shared.js.map +1 -1
- package/lib/module/components/ui/shared/useImageSource.js +11 -0
- package/lib/module/components/ui/shared/useImageSource.js.map +1 -0
- package/lib/module/icons/data.js +87 -1
- package/lib/module/icons/data.js.map +1 -1
- package/lib/module/utils/imageSource.js +47 -13
- package/lib/module/utils/imageSource.js.map +1 -1
- package/lib/typescript/src/components/ui/ActionMenuContent/ActionMenuContent.d.ts +4 -0
- package/lib/typescript/src/components/ui/ActionMenuContent/ActionMenuContent.d.ts.map +1 -0
- package/lib/typescript/src/components/ui/ActionMenuContent/index.d.ts +3 -0
- package/lib/typescript/src/components/ui/ActionMenuContent/index.d.ts.map +1 -0
- package/lib/typescript/src/components/ui/ActionMenuContent/styles.d.ts +51 -0
- package/lib/typescript/src/components/ui/ActionMenuContent/styles.d.ts.map +1 -0
- package/lib/typescript/src/components/ui/ActionMenuContent/types.d.ts +25 -0
- package/lib/typescript/src/components/ui/ActionMenuContent/types.d.ts.map +1 -0
- package/lib/typescript/src/components/ui/Button/ButtonBase.d.ts +3 -1
- package/lib/typescript/src/components/ui/Button/ButtonBase.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/IconButton/IconButton.d.ts +1 -1
- package/lib/typescript/src/components/ui/IconButton/IconButton.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/IconButton/types.d.ts +4 -0
- package/lib/typescript/src/components/ui/IconButton/types.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/ImagePreview/ImagePreview.d.ts +3 -0
- package/lib/typescript/src/components/ui/ImagePreview/ImagePreview.d.ts.map +1 -0
- package/lib/typescript/src/components/ui/ImagePreview/constants.d.ts +3 -0
- package/lib/typescript/src/components/ui/ImagePreview/constants.d.ts.map +1 -0
- package/lib/typescript/src/components/ui/ImagePreview/index.d.ts +3 -0
- package/lib/typescript/src/components/ui/ImagePreview/index.d.ts.map +1 -0
- package/lib/typescript/src/components/ui/ImagePreview/styles.d.ts +56 -0
- package/lib/typescript/src/components/ui/ImagePreview/styles.d.ts.map +1 -0
- package/lib/typescript/src/components/ui/ImagePreview/types.d.ts +33 -0
- package/lib/typescript/src/components/ui/ImagePreview/types.d.ts.map +1 -0
- package/lib/typescript/src/components/ui/Sheet/Sheet.d.ts +4 -0
- package/lib/typescript/src/components/ui/Sheet/Sheet.d.ts.map +1 -0
- package/lib/typescript/src/components/ui/Sheet/index.d.ts +3 -0
- package/lib/typescript/src/components/ui/Sheet/index.d.ts.map +1 -0
- package/lib/typescript/src/components/ui/Sheet/styles.d.ts +38 -0
- package/lib/typescript/src/components/ui/Sheet/styles.d.ts.map +1 -0
- package/lib/typescript/src/components/ui/Sheet/types.d.ts +13 -0
- package/lib/typescript/src/components/ui/Sheet/types.d.ts.map +1 -0
- package/lib/typescript/src/components/ui/SmsField/SmsField.d.ts +4 -0
- package/lib/typescript/src/components/ui/SmsField/SmsField.d.ts.map +1 -0
- package/lib/typescript/src/components/ui/SmsField/index.d.ts +3 -0
- package/lib/typescript/src/components/ui/SmsField/index.d.ts.map +1 -0
- package/lib/typescript/src/components/ui/SmsField/types.d.ts +12 -0
- package/lib/typescript/src/components/ui/SmsField/types.d.ts.map +1 -0
- package/lib/typescript/src/components/ui/TextEntryContent/TextEntryContent.d.ts +4 -0
- package/lib/typescript/src/components/ui/TextEntryContent/TextEntryContent.d.ts.map +1 -0
- package/lib/typescript/src/components/ui/TextEntryContent/index.d.ts +3 -0
- package/lib/typescript/src/components/ui/TextEntryContent/index.d.ts.map +1 -0
- package/lib/typescript/src/components/ui/TextEntryContent/styles.d.ts +26 -0
- package/lib/typescript/src/components/ui/TextEntryContent/styles.d.ts.map +1 -0
- package/lib/typescript/src/components/ui/TextEntryContent/types.d.ts +18 -0
- package/lib/typescript/src/components/ui/TextEntryContent/types.d.ts.map +1 -0
- package/lib/typescript/src/components/ui/index.d.ts +10 -2
- package/lib/typescript/src/components/ui/index.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/shared/ImageAttempt.d.ts +3 -2
- package/lib/typescript/src/components/ui/shared/ImageAttempt.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/shared/selectImageAttemptSource.shared.d.ts +3 -2
- package/lib/typescript/src/components/ui/shared/selectImageAttemptSource.shared.d.ts.map +1 -1
- package/lib/typescript/src/components/ui/shared/useImageSource.d.ts +6 -0
- package/lib/typescript/src/components/ui/shared/useImageSource.d.ts.map +1 -0
- package/lib/typescript/src/icons/data.d.ts +1 -1
- package/lib/typescript/src/icons/data.d.ts.map +1 -1
- package/lib/typescript/src/utils/imageSource.d.ts +3 -2
- package/lib/typescript/src/utils/imageSource.d.ts.map +1 -1
- package/lib/typescript/type-tests/content-api.d.ts +2 -0
- package/lib/typescript/type-tests/content-api.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/components/ui/ActionMenuContent/ActionMenuContent.tsx +118 -0
- package/src/components/ui/ActionMenuContent/index.ts +6 -0
- package/src/components/ui/ActionMenuContent/styles.ts +47 -0
- package/src/components/ui/ActionMenuContent/types.ts +27 -0
- package/src/components/ui/Avatar/Avatar.tsx +3 -3
- package/src/components/ui/Button/ButtonBase.tsx +11 -2
- package/src/components/ui/DrawerHeader/DrawerHeader.tsx +3 -3
- package/src/components/ui/IconButton/IconButton.tsx +9 -1
- package/src/components/ui/IconButton/types.ts +4 -0
- package/src/components/ui/ImagePreview/ImagePreview.tsx +243 -0
- package/src/components/ui/ImagePreview/constants.ts +2 -0
- package/src/components/ui/ImagePreview/index.ts +6 -0
- package/src/components/ui/ImagePreview/styles.ts +48 -0
- package/src/components/ui/ImagePreview/types.ts +37 -0
- package/src/components/ui/Sheet/Sheet.tsx +43 -0
- package/src/components/ui/Sheet/index.ts +2 -0
- package/src/components/ui/Sheet/styles.ts +40 -0
- package/src/components/ui/Sheet/types.ts +14 -0
- package/src/components/ui/SmsField/SmsField.tsx +40 -0
- package/src/components/ui/SmsField/index.ts +2 -0
- package/src/components/ui/SmsField/types.ts +15 -0
- package/src/components/ui/TextEntryContent/TextEntryContent.tsx +56 -0
- package/src/components/ui/TextEntryContent/index.ts +2 -0
- package/src/components/ui/TextEntryContent/styles.ts +17 -0
- package/src/components/ui/TextEntryContent/types.ts +18 -0
- package/src/components/ui/Thumbnail/Thumbnail.tsx +3 -3
- package/src/components/ui/index.ts +18 -2
- package/src/components/ui/shared/ImageAttempt.tsx +3 -2
- package/src/components/ui/shared/selectImageAttemptSource.shared.ts +7 -5
- package/src/components/ui/shared/useImageSource.ts +8 -0
- package/src/icons/data.ts +134 -0
- package/src/utils/imageSource.ts +78 -15
- package/lib/module/components/ui/BorderBeam/BorderBeam.js +0 -102
- package/lib/module/components/ui/BorderBeam/BorderBeam.js.map +0 -1
- package/lib/module/components/ui/BorderBeam/BorderBeam.web.js +0 -108
- package/lib/module/components/ui/BorderBeam/BorderBeam.web.js.map +0 -1
- package/lib/module/components/ui/BorderBeam/index.js +0 -4
- package/lib/module/components/ui/BorderBeam/index.js.map +0 -1
- package/lib/module/components/ui/BorderBeam/normalizeBorderBeam.js +0 -23
- package/lib/module/components/ui/BorderBeam/normalizeBorderBeam.js.map +0 -1
- package/lib/module/components/ui/BorderBeam/shared.js +0 -54
- package/lib/module/components/ui/BorderBeam/shared.js.map +0 -1
- package/lib/module/components/ui/BorderBeam/styles.js +0 -18
- package/lib/module/components/ui/BorderBeam/styles.js.map +0 -1
- package/lib/module/components/ui/BorderBeam/types.js.map +0 -1
- package/lib/typescript/src/components/ui/BorderBeam/BorderBeam.d.ts +0 -10
- package/lib/typescript/src/components/ui/BorderBeam/BorderBeam.d.ts.map +0 -1
- package/lib/typescript/src/components/ui/BorderBeam/BorderBeam.web.d.ts +0 -5
- package/lib/typescript/src/components/ui/BorderBeam/BorderBeam.web.d.ts.map +0 -1
- package/lib/typescript/src/components/ui/BorderBeam/index.d.ts +0 -3
- package/lib/typescript/src/components/ui/BorderBeam/index.d.ts.map +0 -1
- package/lib/typescript/src/components/ui/BorderBeam/normalizeBorderBeam.d.ts +0 -16
- package/lib/typescript/src/components/ui/BorderBeam/normalizeBorderBeam.d.ts.map +0 -1
- package/lib/typescript/src/components/ui/BorderBeam/shared.d.ts +0 -28
- package/lib/typescript/src/components/ui/BorderBeam/shared.d.ts.map +0 -1
- package/lib/typescript/src/components/ui/BorderBeam/styles.d.ts +0 -15
- package/lib/typescript/src/components/ui/BorderBeam/styles.d.ts.map +0 -1
- package/lib/typescript/src/components/ui/BorderBeam/types.d.ts +0 -23
- package/lib/typescript/src/components/ui/BorderBeam/types.d.ts.map +0 -1
- package/src/components/ui/BorderBeam/BorderBeam.tsx +0 -130
- package/src/components/ui/BorderBeam/BorderBeam.web.tsx +0 -127
- package/src/components/ui/BorderBeam/index.ts +0 -2
- package/src/components/ui/BorderBeam/normalizeBorderBeam.ts +0 -58
- package/src/components/ui/BorderBeam/shared.ts +0 -47
- package/src/components/ui/BorderBeam/styles.ts +0 -16
- package/src/components/ui/BorderBeam/types.ts +0 -23
- /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,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
|
-
};
|
|
File without changes
|