Skip to content

Commit 8684541

Browse files
committed
feat: 虚线css原生方式实现
1 parent e4cbeda commit 8684541

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

components/divider/Line.tsx

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,26 @@ const Line: React.FC<LinePropsType> = ({
3939
return <View style={solidLineStyle} />
4040
}, [solidLineStyle])
4141

42+
// ================== dashedCssDom ==================
43+
const dashedCssDom = useMemo(() => {
44+
const wrapperStyle: ViewStyle = {
45+
flex: 1,
46+
overflow: 'hidden',
47+
...(isHorizontal ? { height: _thickness } : { width: _thickness }),
48+
}
49+
const lineStyle: ViewStyle = {
50+
...(isHorizontal ? { height: 0 } : { width: 0 }),
51+
borderColor: backgroundColor,
52+
borderWidth: _thickness,
53+
borderStyle: 'dashed',
54+
}
55+
return (
56+
<View style={wrapperStyle}>
57+
<View style={lineStyle} />
58+
</View>
59+
)
60+
}, [isHorizontal, _thickness, backgroundColor])
61+
4262
// ================== dashedPattern ==================
4363
const dashedPattern = useMemo(() => {
4464
const [len, gap] =
@@ -72,8 +92,8 @@ const Line: React.FC<LinePropsType> = ({
7292
[isHorizontal, _thickness, backgroundColor, dashedPattern],
7393
)
7494

75-
// ================== dashedLineDom ==================
76-
const dashedLineDom = useMemo(() => {
95+
// ================== dashedJointDom ==================
96+
const dashedJointDom = useMemo(() => {
7797
const { l, g } = dashedPattern
7898
const count = Math.ceil((lineLength + g) / (g * 2 + l))
7999
return (
@@ -97,6 +117,15 @@ const Line: React.FC<LinePropsType> = ({
97117
getDashedLineStyle,
98118
])
99119

120+
// ================== dashedLineDom ==================
121+
const dashedLineDom = useMemo(() => {
122+
if (Array.isArray(pattern)) {
123+
return dashedJointDom
124+
} else {
125+
return dashedCssDom
126+
}
127+
}, [pattern, dashedCssDom, dashedJointDom])
128+
100129
// ================== lineDom ==================
101130
const lineDom = useMemo(() => {
102131
if (variant === 'dashed') {

0 commit comments

Comments
 (0)