Skip to content

Commit 7b53761

Browse files
feat(AgendaList): allow user to control debounce in scrollToSection
1 parent a6119a6 commit 7b53761

File tree

5 files changed

+20
-4
lines changed

5 files changed

+20
-4
lines changed

docsRNC/docs/Components/AgendaList.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ Whether to block the date change in calendar (and calendar context provider) whe
4646
Whether to enable scrolling the agenda list to the next date with content when pressing a day without content
4747
<span style={{color: 'grey'}}>boolean</span>
4848

49+
### scrollToSectionDebounce
50+
51+
Delay applied when scrolling to the next date in the agenda after selecting a day, ensuring smooth navigation
52+
<span style={{color: 'grey'}}>number</span>
53+
4954
### viewOffset
5055

5156
Offset scroll to the section

src/expandableCalendar/AgendaListsCommon.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ export interface AgendaListProps extends SectionListProps<any, DefaultSectionT>
2323
viewOffset?: number;
2424
/** enable scrolling the agenda list to the next date with content when pressing a day without content */
2525
scrollToNextEvent?: boolean;
26+
/** debounce in scroll to section. Default = 1000 */
27+
scrollToSectionDebounce?: number;
2628
/**
2729
* @experimental
2830
* If defined, uses InfiniteList instead of SectionList. This feature is experimental and subject to change.

src/expandableCalendar/agendaList.api.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@
4747
"type": "boolean",
4848
"description": "Whether to enable scrolling the agenda list to the next date with content when pressing a day without content"
4949
},
50+
{
51+
"name": "scrollToSectionDebounce",
52+
"type": "number",
53+
"description": "Delay applied when scrolling to the next date in the agenda after selecting a day, ensuring smooth navigation."
54+
},
5055
{
5156
"name": "viewOffset",
5257
"type": "number",

src/expandableCalendar/agendaList.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ const AgendaList = (props: AgendaListProps) => {
6464
useMoment,
6565
markToday = true,
6666
onViewableItemsChanged,
67+
scrollToSectionDebounce = 1000
6768
} = props;
6869

6970
const {date, updateSource, setDate, setDisabled} = useContext(Context);
@@ -159,7 +160,7 @@ const AgendaList = (props: AgendaListProps) => {
159160
viewOffset: (constants.isAndroid ? sectionHeight.current : 0) + viewOffset
160161
});
161162
}
162-
}, 1000, {leading: false, trailing: true}), [viewOffset, sections]);
163+
}, scrollToSectionDebounce, {leading: false, trailing: true}), [viewOffset, sections]);
163164

164165
const _onViewableItemsChanged = useCallback((info: {viewableItems: Array<ViewToken>; changed: Array<ViewToken>}) => {
165166
if (info?.viewableItems && !sectionScroll.current) {
@@ -256,5 +257,6 @@ AgendaList.propTypes = {
256257
useMoment: PropTypes.bool,
257258
markToday: PropTypes.bool,
258259
sectionStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.number, PropTypes.array]),
259-
avoidDateUpdates: PropTypes.bool
260+
avoidDateUpdates: PropTypes.bool,
261+
scrollToSectionDebounce: PropTypes.number
260262
};

src/expandableCalendar/infiniteAgendaList.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ const InfiniteAgendaList = ({
4646
renderItem,
4747
onEndReached,
4848
onEndReachedThreshold,
49+
scrollToSectionDebounce = 1000,
4950
...others
5051
}: Omit<AgendaListProps, 'viewOffset'>) => {
5152
const {date, updateSource, setDate} = useContext(Context);
@@ -145,7 +146,7 @@ const InfiniteAgendaList = ({
145146
_onMomentumScrollEnd(); // the RecyclerListView doesn't trigger onMomentumScrollEnd when calling scrollToSection
146147
}, 500);
147148
}
148-
}, 1000, {leading: false, trailing: true}), [sections]);
149+
}, scrollToSectionDebounce, {leading: false, trailing: true}), [sections]);
149150

150151
const layoutProvider = useMemo(
151152
() => new LayoutProvider(
@@ -261,5 +262,6 @@ InfiniteAgendaList.propTypes = {
261262
useMoment: PropTypes.bool,
262263
markToday: PropTypes.bool,
263264
sectionStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.number, PropTypes.array]),
264-
avoidDateUpdates: PropTypes.bool
265+
avoidDateUpdates: PropTypes.bool,
266+
scrollToSectionDebounce: PropTypes.number
265267
};

0 commit comments

Comments
 (0)