Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ScrollView: momentum scroll events #1021

Open
necolas opened this issue Jul 7, 2018 · 8 comments
Open

ScrollView: momentum scroll events #1021

necolas opened this issue Jul 7, 2018 · 8 comments
Labels
needs: help project:react-native-web Issue associated with react-native-web

Comments

@necolas
Copy link
Owner

necolas commented Jul 7, 2018

Look into supporting momentum scroll events.

Repository owner deleted a comment from hushicai Jul 26, 2018
@kristerkari
Copy link
Contributor

I guess that to add support for the scroll momentum callbacks there needs to be a way to detect if the scroll is done with momentum.

You could always check for the scroll speed, but that is not really the same thing as you call do a scroll movement fast without it having momentum.

Is anyone aware of any existing Javascript implementations where such gesture would be detected?

@necolas
Copy link
Owner Author

necolas commented Dec 17, 2018

My initial thought is that if a scroll is initiated by a touch, and scroll events are still firing while there is no active touch, we're in a "momentum" phase of the scroll. I don't think momentum events can exist for mouse/wheel-triggered scrolls. And the drag start event would fire when touch-scrolling starts, and drag end would fire when touch-scrolling ends. But would have to check when the events fire for native to confirm.

@MoOx
Copy link
Contributor

MoOx commented Dec 31, 2018

I don't think momentum events can exist for mouse/wheel-triggered scrolls

At least on macos with a trackpad you can experience them in all browsers.


Might this help to finish touchable support as some issues with those might be related to some missing events (eg: for scroll responder?)

@RichardLindhout

This comment has been minimized.

@zxymgl
Copy link

zxymgl commented Sep 25, 2020

me too

@MorganTrudeau
Copy link

MorganTrudeau commented Dec 1, 2021

For anyone needing a temp workaround I made a hook...

// hooks.js

export const useWebOnScroll = ({ onScroll, onScrollEnd }) => {
  const lastScrollEvent = useRef(null);
  const scrollEndTimeout = useRef(null);

  const handleWebScroll = event => {
    onScroll(event);

    const timestamp = Date.now();

    if (scrollEndTimeout.current) {
      clearTimeout(scrollEndTimeout.current);
    }

    if (lastScrollEvent.current) {
      // Scroll ended
      scrollEndTimeout.current = setTimeout(() => {
        if (lastScrollEvent.current === timestamp) {
          lastScrollEvent.current = null;
          onScrollEnd && onScrollEnd(event);
        }
      }, 500);
    }

    lastScrollEvent.current = timestamp;
  };

  useEffect(() => {
    return () => {
      scrollEndTimeout.current && clearTimeout(scrollEndTimeout.current);
    };
  }, []);

  return handleWebScroll;
};

// Component.js


const Component = ({onScroll, onScrollEnd}) => {
    const handleWebScroll = useWebOnScroll({ onScroll, onScrollEnd })

    <ScrollView onScroll={Platform.select({ web: handleWebScroll, default: onScroll })} />
}

@necolas necolas added the project:react-native-web Issue associated with react-native-web label Jul 2, 2022
@Ryanjso
Copy link

Ryanjso commented Aug 8, 2022

Anyone know if this has been fixed or if there's another way of achieving this effect on RN web?

@nandorojo
Copy link
Contributor

Here's my solution: #2249 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs: help project:react-native-web Issue associated with react-native-web
Projects
None yet
Development

No branches or pull requests

8 participants