Skip to content

Is this a use case? #43

Closed
Closed

Description

@obibring

Hey there, thanks for the great work :). I'm trying to wrap my head around when, exactly, I can use this library to solve issues in my app. Is this question a potential use case?: https://stackoverflow.com/questions/46749179/animating-during-momentum-scroll-in-react-native

Appreciate any clarificaiton while you guys work on the docs. Thanks!

Activity

  1. kmagiera commented on Oct 16, 2017

    @kmagiera
    Member

    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.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.

    1. 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)

    2. 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.

  2. kmagiera commented on Oct 19, 2017

    @kmagiera
    Member

    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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions