Skip to content

Commit

Permalink
fix: fix computed error with MAX/MIN
Browse files Browse the repository at this point in the history
  • Loading branch information
dohooo committed Dec 5, 2021
1 parent 7494522 commit e9a3007
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions src/hooks/useOffsetX.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,36 @@ export const useOffsetX = (opts: IOpts) => {
function getDefaultPos(
_type: 'positive' | 'negative',
_count: number
) {
let boundary = null;
): {
MAX: number;
MIN: number;
startPos: number;
} {
let MAX = null;
let MIN = null;

let startPos: number = defaultPos;

if (_type === 'positive') {
boundary = _count * width;
MAX = _count * width;
MIN = -(VALID_LENGTH - _count) * width;
} else {
boundary = (VALID_LENGTH - _count) * width;
MAX = (VALID_LENGTH - _count) * width;
MIN = -_count * width;
}

if (defaultPos > boundary) {
return boundary - defaultPos;
if (defaultPos > MAX) {
startPos = MAX - defaultPos;
}
return defaultPos;

return {
startPos,
MAX,
MIN,
};
}

const startPos = getDefaultPos(type, viewCount);
const MAX = viewCount * width;
const MIN = -((VALID_LENGTH - viewCount) * width);
const { startPos, MAX, MIN } = getDefaultPos(type, viewCount);

const inputRange = [
-TOTAL_WIDTH,
Expand Down

0 comments on commit e9a3007

Please sign in to comment.