Skip to content

Commit 4494d10

Browse files
committed
Fix priority of Timeline initial scroll logic
1 parent 48f9a2b commit 4494d10

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

example/src/screens/timelineCalendar.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ export default class TimelineCalendarScreen extends Component {
213213
timelineProps={this.timelineProps}
214214
showNowIndicator
215215
scrollToNow
216+
scrollToFirst
216217
initialTime={INITIAL_TIME}
217218
/>
218219
</CalendarProvider>

src/timeline-list/index.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ export interface TimelineListProps {
1818
/**
1919
* General timeline props to pass to each timeline item
2020
*/
21-
timelineProps?: Omit<TimelineProps, 'events' | 'showNowIndicator' | 'scrollToNow' | 'initialTime'>;
21+
timelineProps?: Omit<TimelineProps, 'events' | 'scrollToFirst' | 'showNowIndicator' | 'scrollToNow' | 'initialTime'>;
22+
/**
23+
* Should scroll to first event of the day
24+
*/
25+
scrollToFirst?: boolean;
2226
/**
2327
* Should show now indicator (shown only on "today" timeline)
2428
*/
@@ -34,7 +38,7 @@ export interface TimelineListProps {
3438
}
3539

3640
const TimelineList = (props: TimelineListProps) => {
37-
const {timelineProps, events, showNowIndicator, scrollToNow, initialTime} = props;
41+
const {timelineProps, events, showNowIndicator, scrollToFirst, scrollToNow, initialTime} = props;
3842
const {date, updateSource, setDate} = useContext(Context);
3943
const listRef = useRef<any>();
4044
const prevDate = useRef(date);
@@ -103,9 +107,9 @@ const TimelineList = (props: TimelineListProps) => {
103107
key={item}
104108
date={item}
105109
events={timelineEvent}
106-
scrollToFirst={false}
107110
scrollToNow={_isToday && isInitialPage && scrollToNow}
108111
initialTime={!_isToday && isInitialPage ? initialTime : undefined}
112+
scrollToFirst={!_isToday && isInitialPage && scrollToFirst}
109113
scrollOffset={isCurrent ? undefined : timelineOffset}
110114
onChangeOffset={onTimelineOffsetChange}
111115
showNowIndicator={_isToday && showNowIndicator}

src/timeline/Timeline.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,10 @@ const Timeline = (props: TimelineProps) => {
119119

120120
useEffect(() => {
121121
let initialPosition = 0;
122-
if (scrollToFirst) {
123-
initialPosition = min(map(packedEvents, 'top')) ?? 0;
124-
} else if (scrollToNow) {
122+
if (scrollToNow) {
125123
initialPosition = calcNowOffset(HOUR_BLOCK_HEIGHT);
124+
} else if (scrollToFirst && packedEvents.length > 0) {
125+
initialPosition = min(map(packedEvents, 'top')) ?? 0;
126126
} else if (initialTime) {
127127
initialPosition = calcNowOffset(HOUR_BLOCK_HEIGHT, initialTime.hour, initialTime.minutes);
128128
}

0 commit comments

Comments
 (0)