react-infinite-scroll-component icon indicating copy to clipboard operation
react-infinite-scroll-component copied to clipboard

Inverse scroll triggers next function on scroll down

Open valkurash opened this issue 5 years ago • 10 comments

https://codesandbox.io/s/trusting-frost-q6wjc?file=/src/index.js next function is triggered due to target.scrollTop === 0 condition in line 257 https://github.com/ankeetmaini/react-infinite-scroll-component/blob/9e5ac46ca55e94543b3ca4a1276a2d7ab96a8af5/src/index.tsx#L257 when you scroll to bottom.

When you use inverse scroll and scroll up to the page, target.scrollTop is negative value. I think target.scrollTop === 0 is not the right condition for the check, I should be something like target.scrollHeight + target.scrollTop === 0

valkurash avatar Nov 03 '20 13:11 valkurash

Same problem here

valdirviana avatar Nov 12 '20 17:11 valdirviana

Same problem here

You found any fix for this?

shreeyansh-b avatar Nov 14 '20 18:11 shreeyansh-b

I have some problem, OMG the package has weekly Downloads 114 055, and fix the problem is so ease just add corrections for method isElementAtTop

  isElementAtTop(target: HTMLElement, scrollThreshold: string | number = 0.8) {
    const isInverseMode = this.props.inverse;
    const clientHeight =
      target === document.body || target === document.documentElement
        ? window.screen.availHeight
        : target.clientHeight;

    const threshold = parseThreshold(scrollThreshold);

    if (threshold.unit === ThresholdUnits.Pixel) {
      return (
        target.scrollTop <= threshold.value + clientHeight - target.scrollHeight + 1 ||
        (!isInverseMode && target.scrollTop === 0)
      );
    }

    return (
      target.scrollTop <=
        threshold.value / 100 + clientHeight - target.scrollHeight + 1 ||
      (!isInverseMode && target.scrollTop === 0)
    );
  }

vrg-success avatar Nov 19 '20 11:11 vrg-success

any update?

guilhermecastro-hotmart avatar Nov 24 '20 19:11 guilhermecastro-hotmart

Same problem.

luchn49 avatar Nov 27 '20 06:11 luchn49

Facing the same problem on version ^5.1.0 :disappointed:

AlaDouagi avatar Dec 16 '20 08:12 AlaDouagi

@ankeetmaini I just opened a PR to fix this issue, please review it and merge it if everything is OK :pray:

AlaDouagi avatar Dec 16 '20 14:12 AlaDouagi

Still have issues with the inverse scrolling, I copied the example from the main page of this repo and it doesn't work: https://codesandbox.io/s/zealous-hellman-e6ug0

No trigger for fetching more items

hanrok avatar Apr 19 '21 09:04 hanrok

@hanrok you are using an old version of react-infinite-scroll-component (4.1.0) in CodeSandbox example, try to upgrade to latest version (it should work after that) :wink:

AlaDouagi avatar Apr 22 '21 16:04 AlaDouagi

@hanrok you are using an old version of react-infinite-scroll-component (4.1.0) in CodeSandbox example, try to upgrade to latest version (it should work after that) 😉

you are right.. shame on me. Thanks!

hanrok avatar Apr 23 '21 06:04 hanrok