@@ -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
1315export 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