Skip to content

Conversation

@ACHP
Copy link

@ACHP ACHP commented Mar 30, 2024

The goal of this hook is to be able to compose multiple scrollHandler, and therefore "hide" the fact that a custom scrollView already use a scrollHandler.

why

Let's say I want to create a Fancy ScrollView that use useAnimatedScrollHandler internally to do some animation, on the background color for example.
I want to expose this new component to the team and let them use their own animations (in addition to mines) using reanimated primitives.

Maybe I missed something in the documentation, but as of today it seems that there is no easy way to do it.
We have to provide a custom API for our FancyScrollView to handle onScroll, onMomentumScrollEnd etc ...
This is not ideal because now the implementation details of our FancyScrollView have somehow leaked outside our component.

Existing discussion

#3611

Status

This is still a work in progress, I would really appreciate some feedback on this:

  • Would it actually make sense to add this API in reanimated ? (Or should it be an external lib ?)
  • Is this the right way to do it ?
  • How to type the handlerList params properly ?

The goal of this hook is
to be able to compose multiple scrollHandler,
and therefore "hide"
the fact that a custom scrollView already use a scrollHandler.
@tjzel
Copy link
Collaborator

tjzel commented Apr 3, 2024

Hi @ACHP, thanks for your contribution! We were discussing how to implement event handler merging in Reanimated for a while now and soon we will come to some conclusions. We have a couple of approaches here to choose from and we will include your, with adding a new hook, in the process.

@szydlovsky
Copy link
Contributor

Hey @ACHP ! Great thanks for suggesting the hook - we have undertaken this approach and are currently working on it in #5890 - feel free to join the discussion as well!

@szydlovsky szydlovsky closed this Apr 18, 2024
github-merge-queue bot pushed a commit that referenced this pull request May 14, 2024
## Summary

There have already been some requests for a way to merge our event
handlers. Inspired by
#5854, I
created a hook that can work with any handlers made using `useEvent`. I
will happily accept any comments and suggestions regarding typing since
I am not so sure about it.


https://github.com/software-mansion/react-native-reanimated/assets/77503811/9c295325-28ce-4ec2-8490-1a7431e8fafd

The PR can be merged only ater
#5845
(it is also based on it).

## Test plan

Open `useComposedEventHandler` example from Example app and watch event
callbacks in console.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants