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

Crash on Android with LayoutAnimationController.shouldAnimateLayout #29919

Closed
jocoders opened this issue Sep 10, 2020 · 3 comments
Closed

Crash on Android with LayoutAnimationController.shouldAnimateLayout #29919

jocoders opened this issue Sep 10, 2020 · 3 comments
Labels
API: LayoutAnimation Needs: Triage 🔍 Platform: Android Android applications. Stale There has been a lack of activity on this issue and it may be closed soon.

Comments

@jocoders
Copy link

jocoders commented Sep 10, 2020

Good day! Every week my app crashes in the production mode on android devices. Basically it is happening on Android 10(Samsung, Xiaomi, Huawei, LGE).

Description

      Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.ViewParent android.view.View.getParent()' on a null object reference
       at com.facebook.react.uimanager.layoutanimation.LayoutAnimationController.shouldAnimateLayout (LayoutAnimationController.java:91)
       at com.facebook.react.uimanager.NativeViewHierarchyManager.manageChildren(NativeViewHierarchyManager.java:453)
atcom.facebook.react.uimanager.UIViewOperationQueue$ManageChildrenOperation.execute(UIViewOperationQueue.java:206)
       at com.facebook.react.uimanager.UIViewOperationQueue$1.run(UIViewOperationQueue.java:792)
       at com.facebook.react.uimanager.UIViewOperationQueue.flushPendingBatches(UIViewOperationQueue.java:903)
       at com.facebook.react.uimanager.UIViewOperationQueue.access$2400(UIViewOperationQueue.java:43)
       at com.facebook.react.uimanager.UIViewOperationQueue$DispatchUIFrameCallback.doFrameGuarded(UIViewOperationQueue.java:963)
       at com.facebook.react.uimanager.GuardedFrameCallback.doFrame(GuardedFrameCallback.java:29)
       at com.facebook.react.modules.core.ReactChoreographer$ReactChoreographerDispatcher.doFrame(ReactChoreographer.java:175)
       at com.facebook.react.modules.core.ChoreographerCompat$FrameCallback$1.doFrame(ChoreographerCompat.java:85)
       at android.view.Choreographer$CallbackRecord.run(Choreographer.java:997)
       at android.view.Choreographer.doCallbacks(Choreographer.java:797)
       at android.view.Choreographer.doFrame(Choreographer.java:728)
       at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:984)
       at android.os.Handler.handleCallback(Handler.java:883)
       at android.os.Handler.dispatchMessage(Handler.java:100)
       at android.os.Looper.loop(Looper.java:237)
       at android.app.ActivityThread.main(ActivityThread.java:8016)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1076)

React Native version:

System:
    OS: macOS 10.15.4
    CPU: (4) x64 Intel(R) Core(TM) i5-6267U CPU @ 2.90GHz
    Memory: 405.76 MB / 8.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 13.13.0 - /usr/local/bin/node
    Yarn: 1.22.4 - /usr/local/bin/yarn
    npm: 6.14.5 - /usr/local/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.9.1 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: iOS 13.7, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2
    Android SDK:
      API Levels: 28, 29
      Build Tools: 28.0.3, 29.0.0, 29.0.2, 29.0.3
      System Images: android-22 | Google APIs Intel x86 Atom, android-24 | Google APIs Intel x86 Atom, android-24 | Google Play Intel x86 Atom, android-26 | Google Play Intel x86 Atom, android-29 | Google Play Intel x86 Atom, android-30 | Google APIs Intel x86 Atom
      Android NDK: Not Found
  IDEs:
    Android Studio: 4.0 AI-193.6911.18.40.6514223
    Xcode: 11.7/11E801a - /usr/bin/xcodebuild
  Languages:
    Java: 1.8.0_242-release - /usr/bin/javac
    Python: 2.7.16 - /usr/bin/python
  npmPackages:
    @react-native-community/cli: Not Found
    react: 16.11.0 => 16.11.0 
    react-native: 0.62.0 => 0.62.0 
  npmGlobalPackages:
    *react-native*: Not Found

Steps To Reproduce

It is not possible to reproduce the issue, because it is happening in the production mode. I have just a crash report. During the test on emulator/real device could not catch the error.

Expected Results

The app is not crashes

Snack, code example, screenshot, or link to a repository:

I have the file with animation vars:

import { LayoutAnimation, LayoutAnimationConfig } from 'react-native';

export const AnimationVars = {
  layoutAnimation: {
    keyboard,
    expandCollapse: { ...LayoutAnimation.Presets.easeInEaseOut, duration: expandCollapseDuration } as LayoutAnimationConfig,
    inputField: { ...LayoutAnimation.Presets.easeInEaseOut, duration: inputFieldDuration } as LayoutAnimationConfig,
    dialogTransform: { ...LayoutAnimation.Presets.easeInEaseOut, duration: expandCollapseDuration } as LayoutAnimationConfig,
    navBarTransform: { ...LayoutAnimation.Presets.easeInEaseOut, duration: navBarDuration } as LayoutAnimationConfig,
  },
};

And after use the var in different places of my app, for example in TitleExpanding component in toggle method:

  private _onToggle(nextValue: boolean, animate: boolean = true) {
    const rotateValue = !nextValue ? 1 : 0;
    if (animate) {
      requestAnimationFrame(() => {
        timing(this._rotateValue, {
          toValue: rotateValue,
          duration: AnimationVars.expandCollapseDuration,
          easing: Easing.linear,
        }).start();
      });
      LayoutAnimation.configureNext(AnimationVars.layoutAnimation.expandCollapse);
    } else {
      this._rotateValue.setValue(rotateValue);
    }
    this._toggle.toggle();

    const preferencesKey = this.props.preferencesKey;
    if (preferencesKey) {
      this._preferences.set(preferencesKey, nextValue ? 'false' : 'true').then();
    }
  }

I think it is the similar issue #25832

@Strate
Copy link

Strate commented Nov 11, 2020

I can confirm, this is my stacktrace of similar crash

Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.ViewParent android.view.View.getParent()' on a null object reference
       at com.facebook.react.uimanager.layoutanimation.LayoutAnimationController.shouldAnimateLayout(LayoutAnimationController.java:91)
       at com.facebook.react.uimanager.NativeViewHierarchyManager.manageChildren(NativeViewHierarchyManager.java:453)
       at com.facebook.react.uimanager.UIViewOperationQueue$ManageChildrenOperation.execute(UIViewOperationQueue.java:206)
       at com.facebook.react.uimanager.UIViewOperationQueue$1.run(UIViewOperationQueue.java:792)
       at com.facebook.react.uimanager.UIViewOperationQueue.flushPendingBatches(UIViewOperationQueue.java:903)
       at com.facebook.react.uimanager.UIViewOperationQueue.access$2400(UIViewOperationQueue.java:43)
       at com.facebook.react.uimanager.UIViewOperationQueue$DispatchUIFrameCallback.doFrameGuarded(UIViewOperationQueue.java:963)
       at com.facebook.react.uimanager.GuardedFrameCallback.doFrame(GuardedFrameCallback.java:29)
       at com.facebook.react.modules.core.ReactChoreographer$ReactChoreographerDispatcher.doFrame(ReactChoreographer.java:175)
       at com.facebook.react.modules.core.ChoreographerCompat$FrameCallback$1.doFrame(ChoreographerCompat.java:85)
       at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1055)
       at android.view.Choreographer.doCallbacks(Choreographer.java:875)
       at android.view.Choreographer.doFrame(Choreographer.java:772)
       at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1042)
       at android.os.Handler.handleCallback(Handler.java:888)
       at android.os.Handler.dispatchMessage(Handler.java:100)
       at android.os.Looper.loop(Looper.java:213)
       at android.app.ActivityThread.main(ActivityThread.java:8178)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1101)

Looks like this code:

View viewToRemove = viewManager.getChildAt(viewToManage, normalizedIndexToRemove);

        if (mLayoutAnimationEnabled
            && mLayoutAnimator.shouldAnimateLayout(viewToRemove)
            && arrayContains(tagsToDelete, viewToRemove.getId())) {
          // The view will be removed and dropped by the 'delete' layout animation
          // instead, so do nothing
        } else {
          viewManager.removeViewAt(viewToManage, normalizedIndexToRemove);
        }

viewManager.getChildAt(viewToManage, normalizedIndexToRemove); returns null, so mLayoutAnimator.shouldAnimateLayout(viewToRemove) crashes because call to getParent without null check.

@github-actions
Copy link

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.

@github-actions github-actions bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Jul 15, 2023
@github-actions
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API: LayoutAnimation Needs: Triage 🔍 Platform: Android Android applications. Stale There has been a lack of activity on this issue and it may be closed soon.
Projects
None yet
Development

No branches or pull requests

3 participants