You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'd like to answer your question on SO, but it is still a bit unclear on what's happening in your case. So let me clarify here and if it turns out to be something the community on SO can take advantage from, I'll also post my answer there.
So from what I understand happens in your case is that you have a view that is outside of the scrollable area that you want to start animating (using Animated.spring with native driver enabled) while the scrollview is settling.
From you description on SO it appears that the button handler gets triggered, therefore the issue is not related to touch handling. I also understand that the button is not within the scrollable container, so tapping it should not "interfere" with the scrollview recognizer.
What I think happens in your case is that you have an Animated.event hooked to the scroll event and connected with an Animated value that is also used to start that spring animation. In Animated library implementation (with both native driver on or off) calling setValue on an Animated value will stop all the animations that has been started for that value. So since connecting a value to an event calls into setValue, the momentum scroll events would cancel the animation that you started.
To verify the above you could try to remove the Animated.event from the scrollview and see if the animation can run along with the momentum scroll happening.
Regardless, I'm afraid this is not something this library would be able to solve for you. The reason is that the issue is related to the animations that are happening on the screen rather than to gesture handling. E.g. your onPress handler gets called and even if we block scrollview from receiving touch when you click the button (that is what this library would allow you to do) it won't cancel momentum scrolling, as the momentum scrolling is just an animation that starts with your previous gesture (fling).
But don't give up. I have some ideas for you to try. Unfortunately I won't have time to try it out myself and some of the options may not work but I can give you some explanation on why I think some of the options can work.
When you'd like to momentum scroll animation to continue happening when you animate the navbar, you will need to have two separate Animated values: one that will be hooked to scroll events and another that you will use to run spring animation for. In this case running the animation on separate value will prevent momentum scroll events from cancelling it. Then, you will need to do some math to calculate the actual position of your navbar out of these two values. The simplest idea is to use the sum of these two (although this may not give you best results if they both are greater than 0, so you may consider e.g. multiplying the first one by 0 when the second one is non 0 by interpolating the second value such that it maps to 0 when its non zero and to 1 otherwise, I can elaborate on this further if you're interested)
You may try to stop momentum from happening before you start the animation. You should be able to achieve it by either calling scrollTo or setting scrollEnabled=false. The easiest to try is the former. So I understand you already have an Animated.ScrollView component. In which case you can use Animated.Value as scrollEnabled prop. Just set it to 1 at the beginning. Then prior to calling Animated.spring().start() just call scrollEnabledValue.setValue(0) and then scrollEnabledValue.setValue(1). The two calls will queue up and the scrollview should get disabled and re-enabled within a single frame, yet I'd expect the momentum scrolling to stop when the scrolling gets disabled.
Activity
kmagiera commentedon Oct 16, 2017
Thanks for reaching out @obibring !
I'd like to answer your question on SO, but it is still a bit unclear on what's happening in your case. So let me clarify here and if it turns out to be something the community on SO can take advantage from, I'll also post my answer there.
So from what I understand happens in your case is that you have a view that is outside of the scrollable area that you want to start animating (using
Animated.springwith native driver enabled) while the scrollview is settling.From you description on SO it appears that the button handler gets triggered, therefore the issue is not related to touch handling. I also understand that the button is not within the scrollable container, so tapping it should not "interfere" with the scrollview recognizer.
What I think happens in your case is that you have an
Animated.eventhooked to the scroll event and connected with an Animated value that is also used to start that spring animation. In Animated library implementation (with both native driver on or off) callingsetValueon an Animated value will stop all the animations that has been started for that value. So since connecting a value to an event calls intosetValue, the momentum scroll events would cancel the animation that you started.To verify the above you could try to remove the
Animated.eventfrom the scrollview and see if the animation can run along with the momentum scroll happening.Regardless, I'm afraid this is not something this library would be able to solve for you. The reason is that the issue is related to the animations that are happening on the screen rather than to gesture handling. E.g. your onPress handler gets called and even if we block scrollview from receiving touch when you click the button (that is what this library would allow you to do) it won't cancel momentum scrolling, as the momentum scrolling is just an animation that starts with your previous gesture (fling).
But don't give up. I have some ideas for you to try. Unfortunately I won't have time to try it out myself and some of the options may not work but I can give you some explanation on why I think some of the options can work.
When you'd like to momentum scroll animation to continue happening when you animate the navbar, you will need to have two separate Animated values: one that will be hooked to scroll events and another that you will use to run spring animation for. In this case running the animation on separate value will prevent momentum scroll events from cancelling it. Then, you will need to do some math to calculate the actual position of your navbar out of these two values. The simplest idea is to use the sum of these two (although this may not give you best results if they both are greater than 0, so you may consider e.g. multiplying the first one by 0 when the second one is non 0 by interpolating the second value such that it maps to 0 when its non zero and to 1 otherwise, I can elaborate on this further if you're interested)
You may try to stop momentum from happening before you start the animation. You should be able to achieve it by either calling
scrollToor settingscrollEnabled=false. The easiest to try is the former. So I understand you already have anAnimated.ScrollViewcomponent. In which case you can useAnimated.ValueasscrollEnabledprop. Just set it to1at the beginning. Then prior to callingAnimated.spring().start()just callscrollEnabledValue.setValue(0)and thenscrollEnabledValue.setValue(1). The two calls will queue up and the scrollview should get disabled and re-enabled within a single frame, yet I'd expect the momentum scrolling to stop when the scrolling gets disabled.kmagiera commentedon Oct 19, 2017
Hey @obibring I'm going to close this one. If you think there is anything else gesture-handler lib can do to help with your issue, feel free to reopen
[iOS] Fix callback crashes from detached gesture recognizers (#4679)
[iOS] Fix callback crashes from detached gesture recognizers (#4679)