Closed ythomop closed 10 months ago
Thanks for opening this PR! I will review this and add an example usage to the example
application to ensure it works for all the scroll containers.
Sorry, I made this PR in haste, without reason, without cross-checking this implementation with the one that I actually use in my project.
Your implementation is ok, although I would prefer to either have the original ScrollView API with onScroll
actually working as expected or remove onScroll
altogether from the available props and only keep onScrollWorklet
. However, it's not that big of a problem, so if you're ok, I'm ok with this PR.
The actual code that I use and works is the following:
const scrollHandler = useAnimatedScrollHandler((event) => {
scrollY.value = event.contentOffset.y;
// user-provided onScroll of the type "(evt: NativeScrollEvent) => void;"
if (onScroll) runOnJS(onScroll)(event);
});
Sorry, I made this PR in haste, without reason, without cross-checking this implementation with the one that I actually use in my project. Your implementation is ok, although I would prefer to either have the original ScrollView API with
onScroll
actually working as expected or removeonScroll
altogether from the available props and only keeponScrollWorklet
. However, it's not that big of a problem, so if you're ok, I'm ok with this PR.The actual code that I use and works is the following:
const scrollHandler = useAnimatedScrollHandler((event) => { scrollY.value = event.contentOffset.y; // user-provided onScroll of the type "(evt: NativeScrollEvent) => void;" if (onScroll) runOnJS(onScroll)(event); });
The code here is executing the onScroll method on the JS thread - I would prefer to stick with worklets
and allow the developer to do a runOnJs
call explicitly if they need to do so.
You made a good point earlier and I will adjust the implementation to remove the onScroll
property altogether.
I think it's good to go! 😀
@ythomop It's merged and released under version 0.11.0 now. Thanks for the PR!
Description
Runs the user-provided onScroll function after react-native-header's scrollHandler
Motivation and Context
Issue
Types of changes
Checklist: