Skip to content

Commit

Permalink
fix: up move fast, will up bottom
Browse files Browse the repository at this point in the history
  • Loading branch information
little-buddy committed Sep 13, 2023
1 parent 246411c commit 337588f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 14 deletions.
45 changes: 32 additions & 13 deletions src/MrPullRefresh.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,13 @@ const MrRefreshWrapper: React.FC<PropsWithChildren<MrRefreshWrapperProps>> = ({
pulldownState.value = newStatus;
}

panTranslateY.value = event.translationY - recordValue.value;
const move = event.translationY - recordValue.value;

if (move < 0) {
pulldownState.value = PullingRefreshStatus.IDLE;
} else {
panTranslateY.value = move;
}
}
}

Expand All @@ -173,11 +179,14 @@ const MrRefreshWrapper: React.FC<PropsWithChildren<MrRefreshWrapperProps>> = ({
pulldownState.value = PullingRefreshStatus.IDLE;
}

console.log(
'onChangeBottom',
scrollerOffsetY.value >=
contentY.value - containerY.value - SystemOffset
);
// eslint-disable-next-line @typescript-eslint/no-unused-expressions, @typescript-eslint/no-unnecessary-condition
LogFlag &&
// eslint-disable-next-line no-console
console.log(
'onChangeBottom',
scrollerOffsetY.value >=
contentY.value - containerY.value - SystemOffset
);

if (
scrollerOffsetY.value >=
Expand All @@ -190,14 +199,23 @@ const MrRefreshWrapper: React.FC<PropsWithChildren<MrRefreshWrapperProps>> = ({
: PullingRefreshStatus.PULLING;

if (newStatus !== pullupState.value) {
// TODO: 个人感觉是这个值记录得有问题
if (pullupState.value === PullingRefreshStatus.IDLE) {
recordValue.value = event.translationY;
}

pullupState.value = newStatus;
}

panTranslateY.value = event.translationY - recordValue.value;
console.log('panGesture', recordValue.value);

const move = event.translationY - recordValue.value;

if (move > 0) {
pullupState.value = PullingRefreshStatus.IDLE;
} else {
panTranslateY.value = move;
}
}
}

Expand Down Expand Up @@ -232,10 +250,13 @@ const MrRefreshWrapper: React.FC<PropsWithChildren<MrRefreshWrapperProps>> = ({
return;
}

console.log(
scrollerOffsetY.value >=
contentY.value - containerY.value - SystemOffset
);
// eslint-disable-next-line @typescript-eslint/no-unused-expressions, @typescript-eslint/no-unnecessary-condition
LogFlag &&
// eslint-disable-next-line no-console
console.log(
scrollerOffsetY.value >=
contentY.value - containerY.value - SystemOffset
);

if (scrollerOffsetY.value <= SystemOffset) {
if (pulldownState.value !== PullingRefreshStatus.IDLE) {
Expand Down Expand Up @@ -263,8 +284,6 @@ const MrRefreshWrapper: React.FC<PropsWithChildren<MrRefreshWrapperProps>> = ({
scrollerOffsetY.value >=
contentY.value - containerY.value - SystemOffset
) {
console.log('pullupState', pullupState.value);

if (pullupState.value !== PullingRefreshStatus.IDLE) {
pullupState.value =
-panTranslateY.value >= pullupHeight * pullingFactor
Expand Down
2 changes: 1 addition & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const SystemOffset = 1;

// true -> dev
// eslint-disable-next-line @typescript-eslint/naming-convention
export const LogFlag = true;
export const LogFlag = false;

export const FnNull = () => {
/* */
Expand Down

0 comments on commit 337588f

Please sign in to comment.