From b871741888b8873d59a7209d41e6eeb73d986605 Mon Sep 17 00:00:00 2001 From: lukmccall Date: Wed, 6 Nov 2024 12:03:20 +0100 Subject: [PATCH] fix: Break circular reference in `LayoutAnimation` --- .../src/main/cpp/reanimated/android/LayoutAnimations.cpp | 4 ++++ .../src/main/cpp/reanimated/android/LayoutAnimations.h | 2 ++ .../android/src/main/cpp/reanimated/android/NativeProxy.cpp | 2 ++ 3 files changed, 8 insertions(+) diff --git a/packages/react-native-reanimated/android/src/main/cpp/reanimated/android/LayoutAnimations.cpp b/packages/react-native-reanimated/android/src/main/cpp/reanimated/android/LayoutAnimations.cpp index e777c010a25..7e62256ec58 100644 --- a/packages/react-native-reanimated/android/src/main/cpp/reanimated/android/LayoutAnimations.cpp +++ b/packages/react-native-reanimated/android/src/main/cpp/reanimated/android/LayoutAnimations.cpp @@ -115,6 +115,10 @@ jni::local_ref LayoutAnimations::getSharedGroup(const int tag) { return jGroup; } +void LayoutAnimations::invalidate() { + javaPart_ = nullptr; +} + void LayoutAnimations::registerNatives() { registerHybrid({ makeNativeMethod("initHybrid", LayoutAnimations::initHybrid), diff --git a/packages/react-native-reanimated/android/src/main/cpp/reanimated/android/LayoutAnimations.h b/packages/react-native-reanimated/android/src/main/cpp/reanimated/android/LayoutAnimations.h index 87e874ed9ed..aaaa5cf24b2 100644 --- a/packages/react-native-reanimated/android/src/main/cpp/reanimated/android/LayoutAnimations.h +++ b/packages/react-native-reanimated/android/src/main/cpp/reanimated/android/LayoutAnimations.h @@ -67,6 +67,8 @@ class LayoutAnimations : public jni::HybridClass { int findPrecedingViewTagForTransition(int tag); jni::local_ref getSharedGroup(const int tag); + void invalidate(); + private: friend HybridBase; jni::global_ref javaPart_; diff --git a/packages/react-native-reanimated/android/src/main/cpp/reanimated/android/NativeProxy.cpp b/packages/react-native-reanimated/android/src/main/cpp/reanimated/android/NativeProxy.cpp index be8e30c2a19..df7bcc3a5ed 100644 --- a/packages/react-native-reanimated/android/src/main/cpp/reanimated/android/NativeProxy.cpp +++ b/packages/react-native-reanimated/android/src/main/cpp/reanimated/android/NativeProxy.cpp @@ -110,6 +110,8 @@ NativeProxy::~NativeProxy() { // has already been destroyed when AnimatedSensorModule's // destructor is ran nativeReanimatedModule_->cleanupSensors(); + + layoutAnimations_->cthis()->invalidate(); } jni::local_ref NativeProxy::initHybrid(