@@ -8,21 +8,26 @@ export interface DividerProps extends ViewProps {
8
8
lineStyle ?: ViewProps [ 'style' ] ;
9
9
labelStyle ?: TextProps [ 'style' ] ;
10
10
type ?: 'horizontal' | 'vertical' ;
11
+ /** 分割线标题的位置 */
12
+ orientation ?: 'left' | 'right' | 'center' ;
11
13
}
12
14
13
15
export default class Divider extends Component < DividerProps > {
14
16
static defaultProps : DividerProps = {
15
17
type : 'horizontal' ,
16
18
gutter : 8 ,
19
+ orientation : 'center' ,
17
20
} ;
18
21
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 ;
20
23
if ( typeof children === 'string' ) {
21
24
label = children ;
22
25
children = null ;
23
26
}
24
27
const lineStyleArr = [ ] ;
25
28
const warpperStyles = [ ] ;
29
+ const startStyles = [ ] ;
30
+ const endStyles = [ ] ;
26
31
if ( type === 'horizontal' ) {
27
32
warpperStyles . unshift ( styles . horizontal ) ;
28
33
lineStyleArr . unshift ( styles . lineHorizontal ) ;
@@ -42,12 +47,19 @@ export default class Divider extends Component<DividerProps> {
42
47
if ( lineStyle && typeof lineStyle === 'number' ) {
43
48
lineStyle = StyleSheet . flatten ( lineStyle ) ;
44
49
}
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 ] } /> ;
46
58
return (
47
59
< View style = { [ styles . warpper , ...warpperStyles , style ] } { ...restProps } >
48
- { line }
60
+ { lineStart }
49
61
{ children }
50
- { children && line }
62
+ { children && lineEnd }
51
63
</ View >
52
64
) ;
53
65
}
@@ -69,10 +81,16 @@ const styles = StyleSheet.create({
69
81
flexGrow : 1 ,
70
82
flexShrink : 1 ,
71
83
} ,
72
- line : {
84
+ lineStart : {
73
85
backgroundColor : 'rgb(229, 229, 229)' ,
74
86
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 ,
76
94
flexGrow : 1 ,
77
95
} ,
78
96
lineHorizontal : {
0 commit comments