Skip to content

Commit 6ac2fce

Browse files
Amber-Nan杨楠
andauthored
feat(Divider): 增加分割线标题的位置调整功能 & 更新文档 (#325)
* fix(Divider):优化 gutter属性不生效问题 * feat(Divider): 增加分割线标题的位置调整功能 & 更新文档 Co-authored-by: 杨楠 <[email protected]>
1 parent 5d67678 commit 6ac2fce

File tree

3 files changed

+66
-8
lines changed

3 files changed

+66
-8
lines changed

example/examples/src/routes/Divider/index.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,24 @@ export default class DividerView extends React.Component<DividerViewProps> {
2727
<Divider label="调整间隔" gutter={30} />
2828
<Text>分割线</Text>
2929
</Card>
30+
31+
<Card title="分割线标题位置">
32+
<Text>分割线</Text>
33+
<Divider
34+
label="left"
35+
orientation="left"
36+
labelStyle={{fontWeight: 'bold'}}
37+
/>
38+
<Text>分割线</Text>
39+
<Divider label="center" labelStyle={{fontWeight: 'bold'}} />
40+
<Text>分割线</Text>
41+
<Divider
42+
label="right"
43+
orientation="right"
44+
labelStyle={{fontWeight: 'bold'}}
45+
/>
46+
</Card>
47+
3048
<Card title="纵向分割线">
3149
<View style={{height: 200}}>
3250
<Divider type="vertical" label="OR" />

packages/core/src/Divider/README.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Divider 分割线
22
---
33

4-
<img src='https://user-images.githubusercontent.com/66067296/137705210-c1bd655f-8b0c-4ee1-b376-0bc59c573a61.png' alt='Divider' style='zoom:33%;' />
4+
<img src='https://user-images.githubusercontent.com/66067296/140264880-2e3ad121-d86f-4625-8149-7bf452b348db.png' alt='Divider' style='zoom:33%;' />
55

66
区隔内容的分割线。
77

@@ -25,6 +25,27 @@ function Demo() {
2525
}
2626
```
2727

28+
### 分割线标题位置
29+
30+
```jsx
31+
import { Fragment } from 'react';
32+
import { View, Text } from 'react-native';
33+
import { Divider } from '@uiw/react-native';
34+
35+
function Demo() {
36+
return (
37+
<Fragment>
38+
<Text>分割线</Text>
39+
<Divider label="left" orientation="left" labelStyle={{ fontWeight: 'bold' }} />
40+
<Text>分割线</Text>
41+
<Divider label="center" labelStyle={{ fontWeight: 'bold' }} />
42+
<Text>分割线</Text>
43+
<Divider label="right" orientation="right" labelStyle={{ fontWeight: 'bold' }} />
44+
</Fragment>
45+
);
46+
}
47+
```
48+
2849
### 纵向分割线
2950

3051
```jsx
@@ -48,4 +69,5 @@ function Demo() {
4869
|------|------|-----|------|
4970
| `label` | 分割线标题,文本内容 | String | - |
5071
| `type` | 水平还是垂直类型 | `horizontal`, `vertical` | `horizontal` |
51-
| `gutter` | 间距,更具 `type` 来设置上下或者左右间距 | Number | `8` |
72+
| `gutter` | 间距,更具 `type` 来设置上下或者左右间距 | Number | `8` |
73+
| `orientation` | 分割线标题的位置 | `left`, `right`,`center`| `center` |

packages/core/src/Divider/index.tsx

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,26 @@ export interface DividerProps extends ViewProps {
88
lineStyle?: ViewProps['style'];
99
labelStyle?: TextProps['style'];
1010
type?: 'horizontal' | 'vertical';
11+
/** 分割线标题的位置 */
12+
orientation?: 'left' | 'right' | 'center';
1113
}
1214

1315
export default class Divider extends Component<DividerProps> {
1416
static defaultProps: DividerProps = {
1517
type: 'horizontal',
1618
gutter: 8,
19+
orientation: 'center',
1720
};
1821
render() {
19-
let { children, style, gutter, label, lineStyle, labelStyle, type, ...restProps } = this.props;
22+
let { children, style, gutter, label, lineStyle, labelStyle, type, orientation, ...restProps } = this.props;
2023
if (typeof children === 'string') {
2124
label = children;
2225
children = null;
2326
}
2427
const lineStyleArr = [];
2528
const warpperStyles = [];
29+
const startStyles = [];
30+
const endStyles = [];
2631
if (type === 'horizontal') {
2732
warpperStyles.unshift(styles.horizontal);
2833
lineStyleArr.unshift(styles.lineHorizontal);
@@ -42,12 +47,19 @@ export default class Divider extends Component<DividerProps> {
4247
if (lineStyle && typeof lineStyle === 'number') {
4348
lineStyle = StyleSheet.flatten(lineStyle);
4449
}
45-
const line = <View style={[styles.line, ...lineStyleArr, lineStyle]} />;
50+
if (orientation === 'left') {
51+
endStyles.unshift({ flexGrow: 100 });
52+
}
53+
if (orientation === 'right') {
54+
startStyles.unshift({ flexGrow: 100 });
55+
}
56+
const lineStart = <View style={[styles.lineStart, ...lineStyleArr, ...startStyles, lineStyle]} />;
57+
const lineEnd = <View style={[styles.lineEnd, ...lineStyleArr, ...endStyles, lineStyle]} />;
4658
return (
4759
<View style={[styles.warpper, ...warpperStyles, style]} {...restProps}>
48-
{line}
60+
{lineStart}
4961
{children}
50-
{children && line}
62+
{children && lineEnd}
5163
</View>
5264
);
5365
}
@@ -69,10 +81,16 @@ const styles = StyleSheet.create({
6981
flexGrow: 1,
7082
flexShrink: 1,
7183
},
72-
line: {
84+
lineStart: {
7385
backgroundColor: 'rgb(229, 229, 229)',
7486
flexDirection: 'column',
75-
flexShrink: 1,
87+
flexShrink: 100,
88+
flexGrow: 1,
89+
},
90+
lineEnd: {
91+
backgroundColor: 'rgb(229, 229, 229)',
92+
flexDirection: 'column',
93+
flexShrink: 100,
7694
flexGrow: 1,
7795
},
7896
lineHorizontal: {

0 commit comments

Comments
 (0)