Skip to content

NavigationExperimental is broken when native animations are used #11377

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

Closed
bendman opened this issue Dec 8, 2016 · 10 comments
Closed

NavigationExperimental is broken when native animations are used #11377

bendman opened this issue Dec 8, 2016 · 10 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@bendman
Copy link

bendman commented Dec 8, 2016

Description

NavigationExperimental always renders the last card in a stack after completing the first transition, even if the last card wasn't the target. It only (and always) occurs if enableGestures={false}, which is required if you want to take advantage of native animations.

Expected:

  1. Render a CardStack with two cards, 0 and 1, starting on 1
  2. Trigger a transition to card 0
  3. Card 0 is animated into frame
  4. After animation, card 0 is shown

Actual:

  1. Render a CardStack with two cards, 0 and 1, starting on 1
  2. Trigger a transition to card 0
  3. Card 0 is animated into frame
  4. After animation, card 1 is shown

nav-animation

Reproduction

RNPlay uses an old version of React Native, so it can't be used to reproduce this bug. The bug is visible by running the reduced case in this repository: https://github.com/bendman/rn-navigator-bug

Solution

A temporary fix for library consumers is to remove enableGestures="false", thereby not taking advantage of native animation optimizations that were made available in this commit. This also prevents consumers from disabling gestures.

That solution isn't great because it forces a fallback to JS animation, which is slower. A more permanent solution would be to fix the native animation to render the correct card after a transition.

A middle-ground solution would be to add a separate flag for enableNativeAnimation={bool}, allowing consumers to set:

enableNativeAnimation={false}
enableGestures={false}

This would make it possible to disable gestures while still having a working navigator.

Additional Information

@janicduplessis
Copy link
Contributor

There were quite a few bugs with native animations on iOS that were fixed by c858420. Can you try 0.40 which includes this commit to see if that solves this issue?

@denisw
Copy link

denisw commented Jan 22, 2017

@janicduplessis I can confirm that the bug is unfortunately not fixed in 0.40. Also, trying to pop a card with a vertical animation results in an "attempting to run JS driven animation" error, but only if enableGestures is false.

@janicduplessis
Copy link
Contributor

janicduplessis commented Jan 22, 2017

@denisw Could you try with this PR #11819 (react-native@janicduplessis/react-native#native-animations-default-values)?

@denisw
Copy link

denisw commented Jan 23, 2017

@janicduplessis Yes, this fixes the problem described in this issue! Thanks. :) However, the vertical pop animation of NavigationCardStack still gives me the "Attempting to run JS driven animation" error, but perhaps I should open a separate issue for that.

@janicduplessis
Copy link
Contributor

Cool, I'll have a look at that other issue next week.

@denisw
Copy link

denisw commented Jan 23, 2017

I found the other issue, which is (partly) in my code: because useNativeDriver is set to false if gestures are disabled, there is a seems to be a mix of native and JS animations if you disable them conditionally (we only disable them for vertically transitioned screens, i.e. modals). I guess we need to change this behavior on our side until native animations are also possible with gestures enabled.

@janicduplessis
Copy link
Contributor

You can use the private api animatedValue.__isNative to know if an animated value is native if that can help in your case.

@nihgwu
Copy link
Contributor

nihgwu commented Jan 23, 2017

@denisw FYI, you can turning on Native Animation manually by modify the source code or extend from NavigationCardStack, not only when disabled gestures

@asciiman
Copy link

I need to programmatically switch enableGestures and kept getting the "attempting to run js driven animation on animation node" error. Here's how I solved it.

    const enableGestures = currentNavigationState.showBackButton || false;
    // Adding props here is a hack that avoids an "attempting to run js driven 
    // animation on animation node" error when enableGestures is set to false.
    // So we just use the enableGestures property when we need to.
    const props = enableGestures ? { enableGestures } : {};
    return (
      <NavigationCardStack
        {...props}
      />
    );

@hramos
Copy link
Contributor

hramos commented Mar 31, 2017

Navigation Experimental has been deprecated in favor of the react-navigation library.

@hramos hramos closed this as completed Mar 31, 2017
@facebook facebook locked as resolved and limited conversation to collaborators May 24, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

7 participants