Skip to content

Commit

Permalink
feat: loadmore组件在未满一屏内容且getDataAtFirst为false情况下不加载内容的case处理
Browse files Browse the repository at this point in the history
  • Loading branch information
huangguang1999 committed Sep 12, 2023
1 parent 37eb28a commit 29027dd
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
*/
triggerGetDataWhenNoGetDataAtFirst?: 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,
triggerGetDataWhenNoGetDataAtFirst = false,
} = props;
const domRef = useRef<HTMLDivElement | null>(null);
const requestAtFirst = trigger === 'scroll' ? getDataAtFirst : false;
Expand Down Expand Up @@ -238,8 +245,18 @@ 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 &&
triggerGetDataWhenNoGetDataAtFirst
) {
triggerGetData('requestAtFirst');
}
}
Expand Down

0 comments on commit 29027dd

Please sign in to comment.