@@ -11,14 +11,30 @@ import InfiniteList from '../infinite-list';
1111import useTimelinePages , { INITIAL_PAGE , NEAR_EDGE_THRESHOLD } from './useTimelinePages' ;
1212
1313export interface TimelineListProps {
14+ /**
15+ * Map of all timeline events ({[date]: events})
16+ */
1417 events : { [ date : string ] : TimelineProps [ 'events' ] } ;
15- timelineProps ?: Omit < TimelineProps , 'events' | 'showNowIndicator' | 'scrollToNow' > ;
18+ /**
19+ * General timeline props to pass to each timeline item
20+ */
21+ timelineProps ?: Omit < TimelineProps , 'events' | 'showNowIndicator' | 'scrollToNow' | 'initialTime' > ;
22+ /**
23+ * Should show now indicator (shown only on "today" timeline)
24+ */
1625 showNowIndicator ?: boolean ;
26+ /**
27+ * Should initially scroll to current time (relevant only for "today" timeline)
28+ */
1729 scrollToNow ?: boolean ;
30+ /**
31+ * Should initially scroll to a specific time (relevant only for NOT "today" timelines)
32+ */
33+ initialTime ?: TimelineProps [ 'initialTime' ] ;
1834}
1935
2036const TimelineList = ( props : TimelineListProps ) => {
21- const { timelineProps, events, showNowIndicator, scrollToNow} = props ;
37+ const { timelineProps, events, showNowIndicator, scrollToNow, initialTime } = props ;
2238 const { date, updateSource, setDate} = useContext ( Context ) ;
2339 const listRef = useRef < any > ( ) ;
2440 const prevDate = useRef ( date ) ;
@@ -77,18 +93,22 @@ const TimelineList = (props: TimelineListProps) => {
7793 ( _type , item , index ) => {
7894 const timelineEvent = events [ item ] ;
7995 const isCurrent = prevDate . current === item ;
96+ const isInitialPage = index === INITIAL_PAGE ;
97+ const _isToday = isToday ( new XDate ( item ) ) ;
98+
8099 return (
81100 < >
82101 < Timeline
83102 { ...timelineProps }
84103 key = { item }
85104 date = { item }
86- scrollToNow = { scrollToNow && index === INITIAL_PAGE }
87- scrollToFirst = { false }
88105 events = { timelineEvent }
106+ scrollToFirst = { false }
107+ scrollToNow = { _isToday && isInitialPage && scrollToNow }
108+ initialTime = { ! _isToday && isInitialPage ? initialTime : undefined }
89109 scrollOffset = { isCurrent ? undefined : timelineOffset }
90110 onChangeOffset = { onTimelineOffsetChange }
91- showNowIndicator = { showNowIndicator && isToday ( new XDate ( item ) ) }
111+ showNowIndicator = { _isToday && showNowIndicator }
92112 />
93113 { /* NOTE: Keeping this for easy debugging */ }
94114 { /* <Text style={{position: 'absolute'}}>{item}</Text> */ }
0 commit comments