Skip to content

Commit

Permalink
fix: LoadMore support the prop "getDataWhenNoScrollAtFirst" (#170)
Browse files Browse the repository at this point in the history
  • Loading branch information
huangguang1999 authored Sep 12, 2023
1 parent 37eb28a commit 7a4881d
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions packages/arcodesign/components/load-more/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ export interface LoadMoreProps {
* @default true
*/
getDataAtFirst?: boolean;
/**
* 当 getDataAtFirst === false 且数据不满一屏时是否触发一次请求,trigger=scroll时有效
* @en Whether to trigger a request when getDataAtFirst === false and the data is not full of one screen, valid when trigger=scroll
* @default false
*/
getDataWhenNoScrollAtFirst?: boolean;
/**
* 状态改变时回调
* @en Callback when state changes
Expand Down Expand Up @@ -189,6 +195,7 @@ const LoadMore = forwardRef((props: LoadMoreProps, ref: Ref<LoadMoreRef>) => {
onStatusChange,
onClick,
onEndReached,
getDataWhenNoScrollAtFirst = false,
} = props;
const domRef = useRef<HTMLDivElement | null>(null);
const requestAtFirst = trigger === 'scroll' ? getDataAtFirst : false;
Expand Down Expand Up @@ -238,10 +245,20 @@ const LoadMore = forwardRef((props: LoadMoreProps, ref: Ref<LoadMoreRef>) => {
}, [nowStatus]);

useEffect(() => {
if (requestAtFirst && !disabled) {
if (statusRef.current === 'prepare') {
if (requestAtFirst) {
if (statusRef.current === 'prepare' && !disabled) {
triggerGetData('requestAtFirst');
}
} else {
if (
trigger === 'scroll' &&
nowStatus === 'prepare' &&
checkNeedTrigger(0, threshold) &&
!disabled &&
getDataWhenNoScrollAtFirst
) {
triggerGetData('pageEnd');
}
}
}, [trigger, disabled]);

Expand Down

0 comments on commit 7a4881d

Please sign in to comment.