11import React , { useState , useEffect } from 'react' ;
22import { View , Text , StyleSheet , ViewProps } from 'react-native' ;
3+ import { TabsItemIconTypes } from '../Tabs/TabsItem' ;
4+ import Icon , { IconsProps } from '../Icon' ;
35
46export interface TimelineItemsProps {
57 /** 标题 */
68 title : string ;
79 /** 子标题 */
810 tips ?: string ;
9- /** 标示颜色 */
10- color ?: string ;
1111 /** 子项内容 */
1212 desc ?: string | string [ ] ;
13+ /** 自定义图标 */
14+ icon ?: IconsProps ;
1315}
1416
1517export interface TimelineProps extends ViewProps {
@@ -39,6 +41,20 @@ const Desc = (desc?: string | string[]) => {
3941 }
4042} ;
4143
44+ const IconCustom = ( icon ?: IconsProps ) => {
45+ if ( icon ) {
46+ return (
47+ < Icon
48+ name = { icon ?. name ? icon . name : 'circle-o' }
49+ size = { icon ?. size ? icon . size : 15 }
50+ color = { icon ?. color ? icon . color : '#e4e7ed' }
51+ />
52+ ) ;
53+ } else {
54+ return < Icon name = "circle-o" size = { 15 } color = "#e4e7ed" /> ;
55+ }
56+ } ;
57+
4258export default ( props : TimelineProps ) => {
4359 const { items = [ ] , isReverse, style, mode } = props ;
4460
@@ -54,11 +70,11 @@ export default (props: TimelineProps) => {
5470 }
5571 if ( mode ) {
5672 if ( mode === 'left' ) {
57- setModeType ( '98 %' ) ;
73+ setModeType ( '90 %' ) ;
5874 } else if ( mode === 'alternate' ) {
5975 setModeType ( '45%' ) ;
6076 } else {
61- setModeType ( '98 %' ) ;
77+ setModeType ( '90 %' ) ;
6278 }
6379 }
6480 } , [ isReverse , items ] ) ;
@@ -70,7 +86,7 @@ export default (props: TimelineProps) => {
7086 < View style = { [ styles . item ] } key = { index } >
7187 < View style = { { width : modeType , flexDirection : 'column' } } >
7288 { mode && mode === 'alternate' && index % 2 !== 0 && (
73- < View style = { { alignItems : 'flex-end' , flexDirection : 'column' } } >
89+ < View style = { { alignItems : 'flex-end' , flexDirection : 'column' , marginRight : 10 } } >
7490 < View style = { styles . top } >
7591 < Text style = { styles . title } > { item . title } </ Text >
7692 </ View >
@@ -79,7 +95,7 @@ export default (props: TimelineProps) => {
7995 </ View >
8096 ) }
8197 { mode && mode === 'left' && (
82- < View style = { { paddingRight : 10 , width : modeType , alignItems : 'flex-end' } } >
98+ < View style = { { width : '98%' , alignItems : 'flex-end' } } >
8399 < View style = { styles . top } >
84100 < Text style = { styles . title } > { item . title } </ Text >
85101 </ View >
@@ -89,27 +105,22 @@ export default (props: TimelineProps) => {
89105 ) }
90106 </ View >
91107
92- < View style = { { flexDirection : 'column' , backgroundColor : 'green ' } } >
108+ < View style = { { width : mode && mode === 'left' ? '10%' : 0 , flexDirection : 'column' , alignItems : 'center ' } } >
93109 { index < items . length - 1 && < View style = { styles . line } > </ View > }
94- < View
95- style = { [
96- styles . circular ,
97- {
98- backgroundColor : item . color || '#e4e7ed' ,
99- } ,
100- ] }
101- />
110+ { IconCustom ( item . icon ) }
102111 </ View >
103112
104- { ! mode && (
105- < View style = { { paddingLeft : 20 , alignItems : 'flex-start' , flex : 1 } } >
106- < View style = { styles . top } >
107- < Text style = { styles . title } > { item . title } </ Text >
113+ < View style = { { width : mode && mode === 'alternate' ? 0 : '90%' , flexDirection : 'column' } } >
114+ { ! mode && (
115+ < View style = { { paddingLeft : 10 , alignItems : 'flex-start' } } >
116+ < View style = { styles . top } >
117+ < Text style = { styles . title } > { item . title } </ Text >
118+ </ View >
119+ { item . tips && < Text style = { styles . tips } > { item . tips } </ Text > }
120+ { item . desc && Desc ( item . desc ) }
108121 </ View >
109- { item . tips && < Text style = { styles . tips } > { item . tips } </ Text > }
110- { item . desc && Desc ( item . desc ) }
111- </ View >
112- ) }
122+ ) }
123+ </ View >
113124
114125 < View style = { { width : modeType , flexDirection : 'column' } } >
115126 { mode && mode === 'alternate' && index % 2 === 0 && (
@@ -142,17 +153,8 @@ const styles = StyleSheet.create({
142153 flexDirection : 'row' ,
143154 justifyContent : 'space-between' ,
144155 } ,
145- circular : {
146- position : 'absolute' ,
147- left : - 6 ,
148- top : 3 ,
149- width : 14 ,
150- height : 14 ,
151- borderRadius : 16 ,
152- } ,
153156 line : {
154157 position : 'absolute' ,
155- left : 0 ,
156158 top : 17 ,
157159 bottom : - 3 ,
158160 width : 1 ,
0 commit comments