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

fix: Break circular reference in LayoutAnimation #6671

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ jni::local_ref<JArrayInt> LayoutAnimations::getSharedGroup(const int tag) {
return jGroup;
}

void LayoutAnimations::invalidate() {
javaPart_ = nullptr;
}

void LayoutAnimations::registerNatives() {
registerHybrid({
makeNativeMethod("initHybrid", LayoutAnimations::initHybrid),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ class LayoutAnimations : public jni::HybridClass<LayoutAnimations> {
int findPrecedingViewTagForTransition(int tag);
jni::local_ref<JArrayInt> getSharedGroup(const int tag);

void invalidate();

private:
friend HybridBase;
jni::global_ref<LayoutAnimations::javaobject> javaPart_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ NativeProxy::~NativeProxy() {
// has already been destroyed when AnimatedSensorModule's
// destructor is ran
nativeReanimatedModule_->cleanupSensors();

layoutAnimations_->cthis()->invalidate();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been dealing a lot with missing invalidations in #6850 and I have some thoughts.

Shouldn't we call it from Java when Native Modules are invalidated, for a more transparent flow?

(java)ReanimatedModule.invalidate() -> ... -> (java)NativeProxy.invalidate() -> (hybrid)LayoutAnimations->invalidate()

I don't think that relying on Native Proxy's destructor is the best choice here. On the other hand, this is safer since NativeProxy can be "safely" used until it's destroyed.

What do you think?

}

jni::local_ref<NativeProxy::jhybriddata> NativeProxy::initHybrid(
Expand Down
Loading