Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(AgendaList): Allow user to control delay in scrollToSection #2503

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docsRNC/docs/Components/AgendaList.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ Whether to block the date change in calendar (and calendar context provider) whe
Whether to enable scrolling the agenda list to the next date with content when pressing a day without content
<span style={{color: 'grey'}}>boolean</span>

### scrollToSectionDebounce

Delay applied when scrolling to the next date in the agenda after selecting a day, ensuring smooth navigation
<span style={{color: 'grey'}}>number</span>

### viewOffset

Offset scroll to the section
Expand Down
2 changes: 2 additions & 0 deletions src/expandableCalendar/AgendaListsCommon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export interface AgendaListProps extends SectionListProps<any, DefaultSectionT>
viewOffset?: number;
/** enable scrolling the agenda list to the next date with content when pressing a day without content */
scrollToNextEvent?: boolean;
/** debounce in scroll to section. Default = 1000 */
scrollToSectionDebounce?: number;
/**
* @experimental
* If defined, uses InfiniteList instead of SectionList. This feature is experimental and subject to change.
Expand Down
5 changes: 5 additions & 0 deletions src/expandableCalendar/agendaList.api.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@
"type": "boolean",
"description": "Whether to enable scrolling the agenda list to the next date with content when pressing a day without content"
},
{
"name": "scrollToSectionDebounce",
"type": "number",
"description": "Delay applied when scrolling to the next date in the agenda after selecting a day, ensuring smooth navigation."
},
{
"name": "viewOffset",
"type": "number",
Expand Down
6 changes: 4 additions & 2 deletions src/expandableCalendar/agendaList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const AgendaList = (props: AgendaListProps) => {
useMoment,
markToday = true,
onViewableItemsChanged,
scrollToSectionDebounce = 1000
} = props;

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

const _onViewableItemsChanged = useCallback((info: {viewableItems: Array<ViewToken>; changed: Array<ViewToken>}) => {
if (info?.viewableItems && !sectionScroll.current) {
Expand Down Expand Up @@ -256,5 +257,6 @@ AgendaList.propTypes = {
useMoment: PropTypes.bool,
markToday: PropTypes.bool,
sectionStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.number, PropTypes.array]),
avoidDateUpdates: PropTypes.bool
avoidDateUpdates: PropTypes.bool,
scrollToSectionDebounce: PropTypes.number
};
6 changes: 4 additions & 2 deletions src/expandableCalendar/infiniteAgendaList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const InfiniteAgendaList = ({
renderItem,
onEndReached,
onEndReachedThreshold,
scrollToSectionDebounce = 1000,
...others
}: Omit<AgendaListProps, 'viewOffset'>) => {
const {date, updateSource, setDate} = useContext(Context);
Expand Down Expand Up @@ -145,7 +146,7 @@ const InfiniteAgendaList = ({
_onMomentumScrollEnd(); // the RecyclerListView doesn't trigger onMomentumScrollEnd when calling scrollToSection
}, 500);
}
}, 1000, {leading: false, trailing: true}), [sections]);
}, scrollToSectionDebounce, {leading: false, trailing: true}), [sections]);

const layoutProvider = useMemo(
() => new LayoutProvider(
Expand Down Expand Up @@ -261,5 +262,6 @@ InfiniteAgendaList.propTypes = {
useMoment: PropTypes.bool,
markToday: PropTypes.bool,
sectionStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.number, PropTypes.array]),
avoidDateUpdates: PropTypes.bool
avoidDateUpdates: PropTypes.bool,
scrollToSectionDebounce: PropTypes.number
};