Skip to content
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

Animated.sequence undefined is not an object (evaluating 'animations[current].start') #43120

Closed
Jackman3005 opened this issue Feb 21, 2024 · 5 comments
Labels
API: Animated Needs: Attention Issues where the author has responded to feedback. Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. Needs: Triage 🔍 Newer Patch Available

Comments

@Jackman3005
Copy link

Description

From what I can tell, I am essentially running into the same problem as a prior closed issue. Which had a PR created to "fix" the issue, but was eventually closed without being merged.

I too (think) am running into the issue described before. I receive the following error in an unknown situation:

undefined is not an object (evaluating 'animations[current].start')

I am not certain of the root cause of it. Quite possibly it is as @hansencj06 described on the PR in 2020.

It is challenging to extract a minimal reproduction. But I can tell you that I essentially am animating a button to full width (normal) or a circle (loading state).

However, I am stopping and starting the two different animation sequences (animateToCircle, animateToButton) in a useEffect based on incoming states. i.e. If the incoming prop is loading=true and I'm in the process of animating from a button to a circle when I receive updated props loading=false I will then interrupt the animation to a circle and begin the animation back to a button again.

The animation related code is as follows:

const borderColorAnim = useRef(
    new Animated.Value(loading || success ? 0 : 1)
  ).current;
  const widthAnim = useRef(
    new Animated.Value(loading || success ? 0 : 1)
  ).current;
  const buttonTextOpacityAnim = useRef(
    new Animated.Value(loading || success ? 0 : 1)
  ).current;

  const animateToCircle = useRef(
    Animated.sequence([
      Animated.parallel([
        Animated.timing(widthAnim, {
          toValue: 0,
          duration: 300,
          easing: Easing.in(Easing.ease),
          useNativeDriver: false,
        }),
        Animated.timing(buttonTextOpacityAnim, {
          toValue: 0,
          useNativeDriver: false,
        }),
      ]),
      Animated.timing(borderColorAnim, {
        toValue: 0,
        duration: 300,
        useNativeDriver: false,
        easing: Easing.in(Easing.ease),
      }),
    ])
  ).current;
  const animateToButton = useRef(
    Animated.sequence([
      Animated.parallel([
        Animated.timing(borderColorAnim, {
          toValue: 1,
          duration: 300,
          useNativeDriver: false,
          easing: Easing.in(Easing.ease),
        }),
        Animated.timing(widthAnim, {
          toValue: 1,
          duration: 300,
          easing: Easing.in(Easing.ease),
          useNativeDriver: false,
        }),
      ]),
      Animated.timing(buttonTextOpacityAnim, {
        toValue: 1,
        duration: 100,
        easing: Easing.in(Easing.ease),
        useNativeDriver: false,
      }),
    ])
  ).current;

  const previousButtonStateRef = useRef(buttonState);
  useEffect(() => {
    const previousButtonState = previousButtonStateRef.current;
    previousButtonStateRef.current = buttonState;

    if (
      ["ANIMATING_TO_SUCCESS", "ANIMATING_TO_LOADING"].includes(buttonState)
    ) {
      if (
        !["ANIMATING_TO_SUCCESS", "ANIMATING_TO_LOADING"].includes(
          previousButtonState
        )
      ) {
        animateToButton.stop();
        animateToCircle.start(({ finished }) => {
          if (finished) {
            setState(
              previousButtonStateRef.current === "ANIMATING_TO_LOADING"
                ? "LOADING"
                : "SUCCESS"
            );
          }
        });
      }
    } else if (buttonState === "ANIMATING_TO_NORMAL") {
      animateToCircle.stop();
      animateToButton.start(({ finished }) => {
        if (finished) {
          setState("NORMAL");
        }
      });
    } else {
      animateToCircle.reset();
      animateToButton.reset();
      widthAnim.setValue(loading || success ? 0 : 1);
      borderColorAnim.setValue(loading || success ? 0 : 1);
      buttonTextOpacityAnim.setValue(loading || success ? 0 : 1);
    }
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [buttonState]);

Possibly I am misusing animations here and would welcome any suggestions on the "correct" way to accomplish this.

Steps to reproduce

Again, not 100% certain how to do this reliably, although a reproduction was provided in the original issue that should suffice hitting this scenario.

React Native Version

0.72.4

Affected Platforms

Runtime - Web

Output of npx react-native info

System:
  OS: macOS 14.2.1
  CPU: (10) arm64 Apple M1 Pro
  Memory: 127.67 MB / 16.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 18.17.1
    path: ~/.nvm/versions/node/v18.17.1/bin/node
  Yarn:
    version: 1.22.19
    path: ~/workspace/qm-universe/node_modules/.bin/yarn
  npm:
    version: 9.6.7
    path: ~/.nvm/versions/node/v18.17.1/bin/npm
  Watchman: Not Found
Managers:
  CocoaPods:
    version: 1.14.3
    path: /Users/jack/.asdf/shims/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.2
      - iOS 17.2
      - macOS 14.2
      - tvOS 17.2
      - visionOS 1.0
      - watchOS 10.2
  Android SDK: Not Found
IDEs:
  Android Studio: 2022.2 AI-222.4459.24.2221.10121639
  Xcode:
    version: 15.2/15C500b
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 18.0.2
    path: /Users/jack/.sdkman/candidates/java/current/bin/javac
  Ruby:
    version: 3.2.2
    path: /Users/jack/.asdf/shims/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react: Not Found
  react-native: Not Found
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: true
  newArchEnabled: false

Stacktrace or Logs

TypeError

undefined is not an object (evaluating 'animations[current].start')

Reproducer

#17699

Screenshots and Videos

No response

Copy link

⚠️ Newer Version of React Native is Available!
ℹ️ You are on a supported minor version, but it looks like there's a newer patch available - 0.72.10. Please upgrade to the highest patch for your minor or latest and verify if the issue persists (alternatively, create a new project and repro the issue in it). If it does not repro, please let us know so we can close out this issue. This helps us ensure we are looking at issues that still exist in the most recent releases.

@github-actions github-actions bot added Needs: Author Feedback Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. labels Feb 21, 2024
Copy link

⚠️ Missing Reproducible Example
ℹ️ We could not detect a reproducible example in your issue report. Please provide either:
  • If your bug is UI related: a Snack
  • If your bug is build/update related: use our Reproducer Template. A reproducer needs to be in a GitHub repository under your username.

@Jackman3005
Copy link
Author

The PR that was closed does not seem like it would be a "bad" thing to include, as it is only a check that only avoids throwing error in an unexpected scenario.

@github-actions github-actions bot added Needs: Attention Issues where the author has responded to feedback. and removed Needs: Author Feedback labels Feb 21, 2024
facebook-github-bot pushed a commit that referenced this issue May 28, 2024
Summary:
Currently, if the `Animated.sequence` animation is finished, and then the `start()` method is called without a `reset()` method being invoked beforehand, the failure happens: ```undefined is not an object (evaluating 'animations[current].start')```.
Use cases:
- sequence animation started, finished, and then started again
- sequence animation is used in `Animation.loop` with `resetBeforeIteration` set to `false`, which essentially does the same as the previous case

Related issues:
- #43120
- #37611

## Changelog:

[General] [Fixed] - Fix sequence restart failure

Pull Request resolved: #44031

Test Plan: Test cases are included: 1 for regression and 2 for mentioned use cases in the summary

Reviewed By: cipolleschi

Differential Revision: D56015346

Pulled By: dmytrorykun

fbshipit-source-id: 8b0f46c8a33397fece807634463ce630c89d28af
kosmydel pushed a commit to kosmydel/react-native that referenced this issue Jun 11, 2024
Summary:
Currently, if the `Animated.sequence` animation is finished, and then the `start()` method is called without a `reset()` method being invoked beforehand, the failure happens: ```undefined is not an object (evaluating 'animations[current].start')```.
Use cases:
- sequence animation started, finished, and then started again
- sequence animation is used in `Animation.loop` with `resetBeforeIteration` set to `false`, which essentially does the same as the previous case

Related issues:
- facebook#43120
- facebook#37611

## Changelog:

[General] [Fixed] - Fix sequence restart failure

Pull Request resolved: facebook#44031

Test Plan: Test cases are included: 1 for regression and 2 for mentioned use cases in the summary

Reviewed By: cipolleschi

Differential Revision: D56015346

Pulled By: dmytrorykun

fbshipit-source-id: 8b0f46c8a33397fece807634463ce630c89d28af
@react-native-bot
Copy link
Collaborator

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@react-native-bot react-native-bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Aug 20, 2024
@react-native-bot
Copy link
Collaborator

This issue was closed because it has been stalled for 7 days with no activity.

@react-native-bot react-native-bot closed this as not planned Won't fix, can't repro, duplicate, stale Aug 27, 2024
@react-native-bot react-native-bot removed the Stale There has been a lack of activity on this issue and it may be closed soon. label Aug 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API: Animated Needs: Attention Issues where the author has responded to feedback. Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. Needs: Triage 🔍 Newer Patch Available
Projects
None yet
Development

No branches or pull requests

2 participants