Skip to content

Commit

Permalink
Merge branch 'master' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanshar committed Aug 30, 2023
2 parents ee7e05f + 0f503e0 commit b1f5441
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
4 changes: 1 addition & 3 deletions src/expandableCalendar/agendaList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ import {
NativeScrollEvent,
LayoutChangeEvent,
ViewToken,
TextProps,
StyleProp
TextProps
} from 'react-native';

import {useDidUpdate} from '../hooks';
Expand Down Expand Up @@ -70,7 +69,6 @@ export interface AgendaListProps extends SectionListProps<any, DefaultSectionT>
titleHeight?: number;
visibleIndicesChangedDebounce?: number;
renderFooter?: () => React.ReactElement | null;
style?: StyleProp<ViewStyle>;
};
}

Expand Down
25 changes: 16 additions & 9 deletions src/expandableCalendar/infiniteAgendaList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import PropTypes from 'prop-types';

import isUndefined from 'lodash/isUndefined';
import debounce from 'lodash/debounce';
import InfiniteList, {InfiniteListProps} from '../infinite-list';
import InfiniteList from '../infinite-list';

import XDate from 'xdate';

Expand Down Expand Up @@ -58,12 +58,14 @@ const InfiniteAgendaList = (props: AgendaListProps) => {
const didScroll = useRef(false);
const sectionScroll = useRef(false);
const [data, setData] = useState([] as any[]);
const dataRef = useRef(data);

useEffect(() => {
const items = sections.reduce((acc: any, cur: any) => {
return [...acc, {title: cur.title, isTitle: true}, ...cur.data];
}, []);
setData(items);
dataRef.current = items;

if (date !== _topSection.current) {
setTimeout(() => {
Expand Down Expand Up @@ -128,29 +130,34 @@ const InfiniteAgendaList = (props: AgendaListProps) => {
return sectionTitle;
}, []);

const scrollToSection = useCallback(debounce((d) => {
const sectionIndex = scrollToNextEvent ? getNextSectionIndex(d) : getSectionIndex(d);
const scrollToSection = useCallback(debounce((requestedDate) => {
const sectionIndex = scrollToNextEvent ? getNextSectionIndex(requestedDate) : getSectionIndex(requestedDate);
if (isUndefined(sectionIndex)) {
return;
}

if (list?.current && sectionIndex !== undefined) {
sectionScroll.current = true; // to avoid setDate() in _onVisibleIndicesChanged
_topSection.current = sections[findItemTitleIndex(sectionIndex)]?.title;
if (requestedDate !== _topSection.current) {
_topSection.current = sections[findItemTitleIndex(sectionIndex)]?.title;
list.current?.scrollToIndex(sectionIndex, true);
}

list.current?.scrollToIndex(sectionIndex, true);
setTimeout(() => {
_onMomentumScrollEnd(); // the RecyclerListView doesn't trigger onMomentumScrollEnd when calling scrollToSection
}, 500);
}
}, 1000, {leading: false, trailing: true}), [ sections]);
}, 1000, {leading: false, trailing: true}), [sections]);

const layoutProvider = useMemo(
() => new LayoutProvider(
(index) => data[index]?.isTitle ? 'title': 'page',
(index) => dataRef.current[index]?.isTitle ? 'title': 'page',
(type, dim) => {
dim.width = constants.screenWidth;
dim.height = type === 'title' ? infiniteListProps?.titleHeight ?? 60 : infiniteListProps?.itemHeight ?? 80;
}
),
[data]
[]
);

const _onScroll = useCallback((rawEvent: any) => {
Expand Down Expand Up @@ -233,7 +240,7 @@ const InfiniteAgendaList = (props: AgendaListProps) => {
ref={list}
renderItem={_renderItem}
data={data}
style={infiniteListProps?.style as InfiniteListProps['style']}
style={style.current.container}
layoutProvider={layoutProvider}
onScroll={_onScroll}
onVisibleIndicesChanged={_onVisibleIndicesChanged}
Expand Down
9 changes: 4 additions & 5 deletions src/infinite-list/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ const InfiniteList = (props: InfiniteListProps, ref: any) => {
onScroll,
onEndReached,
renderFooter,
style,
} = props;

const dataProvider = useMemo(() => {
Expand Down Expand Up @@ -161,9 +160,9 @@ const InfiniteList = (props: InfiniteListProps, ref: any) => {
};
}, [onScrollBeginDrag, onMomentumScrollEnd, scrollViewProps, isHorizontal]);

const _style = useMemo(() => {
return [{height: pageHeight}, style];
}, [pageHeight, style]);
const style = useMemo(() => {
return {height: pageHeight};
}, [pageHeight]);

return (
<RecyclerListView
Expand All @@ -177,7 +176,7 @@ const InfiniteList = (props: InfiniteListProps, ref: any) => {
initialRenderIndex={initialPageIndex}
renderAheadOffset={5 * pageWidth}
onScroll={_onScroll}
style={_style}
style={style}
scrollViewProps={scrollViewPropsMemo}
onEndReached={onEndReached}
onEndReachedThreshold={onEndReachedThreshold}
Expand Down

0 comments on commit b1f5441

Please sign in to comment.