Skip to content

Commit 18001b0

Browse files
authored
AgendaList - fix initial scroll not to performs if user started to scroll before it executed. Change useEffect to useDidUpdate to avoid second scroll on load (#2005)
1 parent a5a6ae2 commit 18001b0

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/expandableCalendar/agendaList.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
TextProps
2626
} from 'react-native';
2727

28+
import {useDidUpdate} from '../hooks';
2829
import {isToday, isGTE, sameDate} from '../dateutils';
2930
import {getMoment} from '../momentResolver';
3031
import {parseDate} from '../interface';
@@ -88,7 +89,9 @@ const AgendaList = (props: AgendaListProps) => {
8889
markToday = true,
8990
onViewableItemsChanged,
9091
} = props;
92+
9193
const {date, updateSource, setDate, setDisabled} = useContext(Context);
94+
9295
const style = useRef(styleConstructor(theme));
9396
const list = useRef<any>();
9497
const _topSection = useRef(sections[0]?.title);
@@ -104,7 +107,7 @@ const AgendaList = (props: AgendaListProps) => {
104107
}
105108
}, []);
106109

107-
useEffect(() => {
110+
useDidUpdate(() => {
108111
// NOTE: on first init data should set first section to the current date!!!
109112
if (updateSource !== UpdateSources.LIST_DRAG && updateSource !== UpdateSources.CALENDAR_INIT) {
110113
scrollToSection(date);
@@ -194,14 +197,15 @@ const AgendaList = (props: AgendaListProps) => {
194197
}
195198
}
196199
onViewableItemsChanged?.(info);
197-
}, [_topSection.current, didScroll.current, avoidDateUpdates, setDate, onViewableItemsChanged]);
200+
}, [avoidDateUpdates, setDate, onViewableItemsChanged]);
198201

199202
const _onScroll = useCallback((event: NativeSyntheticEvent<NativeScrollEvent>) => {
200203
if (!didScroll.current) {
201204
didScroll.current = true;
205+
scrollToSection.cancel();
202206
}
203207
onScroll?.(event);
204-
}, [didScroll.current, onScroll]);
208+
}, [onScroll]);
205209

206210
const _onMomentumScrollBegin = useCallback((event: NativeSyntheticEvent<NativeScrollEvent>) => {
207211
setDisabled?.(true);

0 commit comments

Comments
 (0)