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

Move execution of ReactNativeFeatureFlags::enableDeletionOfUnmountedViews() out of destructor #46993

Closed
wants to merge 2 commits into from
Closed
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 @@ -8,6 +8,7 @@
package com.facebook.systrace

import androidx.tracing.Trace
import java.lang.Runnable
import kotlin.text.StringBuilder

/**
Expand All @@ -32,12 +33,12 @@ public object Systrace {
@JvmStatic public fun traceInstant(tag: Long, title: String?, scope: EventScope?): Unit = Unit

@JvmStatic
public fun traceSection(tag: Long, sectionName: String, block: () -> T) {
beginSection(sectionName)
public fun traceSection(tag: Long, sectionName: String, block: Runnable) {
beginSection(tag, sectionName)
try {
return block()
block.run()
} finally {
endSection(sectionName)
endSection(tag)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ ShadowNodeFamily::ShadowNodeFamily(
eventEmitter_(std::move(eventEmitter)),
componentDescriptor_(componentDescriptor),
componentHandle_(componentDescriptor.getComponentHandle()),
componentName_(componentDescriptor.getComponentName()) {}
componentName_(componentDescriptor.getComponentName()),
isDeletionOfUnmountedViewsEnabled_(
ReactNativeFeatureFlags::enableDeletionOfUnmountedViews()) {}

void ShadowNodeFamily::setParent(const ShadowNodeFamily::Shared& parent) const {
react_native_assert(parent_.lock() == nullptr || parent_.lock() == parent);
Expand Down Expand Up @@ -77,8 +79,8 @@ Tag ShadowNodeFamily::getTag() const {
}

ShadowNodeFamily::~ShadowNodeFamily() {
if (ReactNativeFeatureFlags::enableDeletionOfUnmountedViews() &&
!hasBeenMounted_ && onUnmountedFamilyDestroyedCallback_ != nullptr) {
if (isDeletionOfUnmountedViewsEnabled_ && !hasBeenMounted_ &&
onUnmountedFamilyDestroyedCallback_ != nullptr) {
onUnmountedFamilyDestroyedCallback_(*this);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,12 @@ class ShadowNodeFamily final {
* Determines if the ShadowNodeFamily was ever mounted on the screen.
*/
mutable bool hasBeenMounted_{false};

/*
* Determines if Views that were never mounted on the screen should be deleted
* when the shadow node family is destroyed.
*/
const bool isDeletionOfUnmountedViewsEnabled_;
};

} // namespace facebook::react
Loading