Skip to content

Commit

Permalink
fix: layout animation NPE crash (#6897)
Browse files Browse the repository at this point in the history
## Summary

After update to Reanimated 3.16.x we started to have hundreds of crashes
due to this error:
```
Exception java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object java.lang.ref.WeakReference.get()' on a null object reference.
```
More info could be found in this issue #4472 

## Test plan

I am not able to reproduce issue locally since it's happening for some
small percentage of users. According to stack trace I am pretty sure it
will help but I am not sure if it's proper fix because I don't have
deeper understanding of surrounding code.

---------

Co-authored-by: Krzysztof Piaskowy <[email protected]>
  • Loading branch information
Nodonisko and piaskowyk authored Jan 30, 2025
1 parent f4b07be commit 66f9d1b
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import javax.annotation.Nullable;

public class AnimationsManager implements ViewHierarchyObserver {
private WeakReference<AndroidUIScheduler> mWeakAndroidUIScheduler;
private WeakReference<AndroidUIScheduler> mWeakAndroidUIScheduler = new WeakReference<>(null);
private ReactContext mContext;
private UIManager mUIManager;
private NativeMethodsHolder mNativeMethodsHolder;
Expand Down Expand Up @@ -105,6 +105,8 @@ public void onViewCreate(View view, ViewGroup parent, Snapshot after) {
AndroidUIScheduler androidUIScheduler = mWeakAndroidUIScheduler.get();
if (androidUIScheduler != null) {
androidUIScheduler.triggerUI();
} else {
return;
}
int tag = view.getId();
HashMap<String, Object> targetValues = after.toTargetMap();
Expand Down

0 comments on commit 66f9d1b

Please sign in to comment.