@@ -10,6 +10,14 @@ import Timeline, {TimelineProps} from '../timeline/Timeline';
1010import InfiniteList from '../infinite-list' ;
1111import useTimelinePages , { INITIAL_PAGE , NEAR_EDGE_THRESHOLD } from './useTimelinePages' ;
1212
13+ export interface TimelineListRenderItemInfo {
14+ item : string ;
15+ index : number ;
16+ isCurrent : boolean ;
17+ isInitialPage : boolean ;
18+ isToday : boolean ;
19+ }
20+
1321export interface TimelineListProps {
1422 /**
1523 * Map of all timeline events ({[date]: events})
@@ -19,6 +27,10 @@ export interface TimelineListProps {
1927 * General timeline props to pass to each timeline item
2028 */
2129 timelineProps ?: Omit < TimelineProps , 'events' | 'scrollToFirst' | 'showNowIndicator' | 'scrollToNow' | 'initialTime' > ;
30+ /**
31+ * Pass to render a custom Timeline item
32+ */
33+ renderItem ?: ( timelineProps : TimelineProps , info : TimelineListRenderItemInfo ) => JSX . Element ;
2234 /**
2335 * Should scroll to first event of the day
2436 */
@@ -38,7 +50,7 @@ export interface TimelineListProps {
3850}
3951
4052const TimelineList = ( props : TimelineListProps ) => {
41- const { timelineProps, events, showNowIndicator, scrollToFirst, scrollToNow, initialTime} = props ;
53+ const { timelineProps, events, renderItem , showNowIndicator, scrollToFirst, scrollToNow, initialTime} = props ;
4254 const { date, updateSource, setDate} = useContext ( Context ) ;
4355 const listRef = useRef < any > ( ) ;
4456 const prevDate = useRef ( date ) ;
@@ -100,20 +112,26 @@ const TimelineList = (props: TimelineListProps) => {
100112 const isInitialPage = index === INITIAL_PAGE ;
101113 const _isToday = isToday ( new XDate ( item ) ) ;
102114
115+ const _timelineProps = {
116+ ...timelineProps ,
117+ key : item ,
118+ date : item ,
119+ events : timelineEvent ,
120+ scrollToNow : _isToday && isInitialPage && scrollToNow ,
121+ initialTime : ! _isToday && isInitialPage ? initialTime : undefined ,
122+ scrollToFirst : ! _isToday && isInitialPage && scrollToFirst ,
123+ scrollOffset : isCurrent ? undefined : timelineOffset ,
124+ onChangeOffset : onTimelineOffsetChange ,
125+ showNowIndicator : _isToday && showNowIndicator
126+ } ;
127+
128+ if ( renderItem ) {
129+ return renderItem ( _timelineProps , { item, index, isCurrent, isInitialPage, isToday : _isToday } ) ;
130+ }
131+
103132 return (
104133 < >
105- < Timeline
106- { ...timelineProps }
107- key = { item }
108- date = { item }
109- events = { timelineEvent }
110- scrollToNow = { _isToday && isInitialPage && scrollToNow }
111- initialTime = { ! _isToday && isInitialPage ? initialTime : undefined }
112- scrollToFirst = { ! _isToday && isInitialPage && scrollToFirst }
113- scrollOffset = { isCurrent ? undefined : timelineOffset }
114- onChangeOffset = { onTimelineOffsetChange }
115- showNowIndicator = { _isToday && showNowIndicator }
116- />
134+ < Timeline { ..._timelineProps } />
117135 { /* NOTE: Keeping this for easy debugging */ }
118136 { /* <Text style={{position: 'absolute'}}>{item}</Text> */ }
119137 </ >
0 commit comments