Skip to content

Commit

Permalink
Clear event handlers and triggers
Browse files Browse the repository at this point in the history
Summary: Adding QE for clearing event handlers and triggers when we release component tree.

Reviewed By: adityasharat

Differential Revision: D63632467

fbshipit-source-id: ac1d6344db06f0917850814a3e16bf620d88d0e8
  • Loading branch information
Anna Powolny authored and facebook-github-bot committed Oct 1, 2024
1 parent 9d58f21 commit 5778398
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2466,6 +2466,9 @@ public void release() {

if (mTreeState != null) {
effectsHandler = mTreeState.getEffectsHandler();
if (ComponentsConfiguration.clearEventHandlersAndTriggers) {
mTreeState.clearEventHandlersAndTriggers();
}
} else {
effectsHandler = null;
}
Expand All @@ -2488,7 +2491,7 @@ public void release() {
}
mOnReleaseListeners = null;
}
if (mTreeState != null) {
if (mTreeState != null && !ComponentsConfiguration.clearEventHandlersAndTriggers) {
mTreeState.clearUnusedTriggerHandlers();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,9 @@ class EventHandlersController {
class DispatchInfoWrapper(val dispatchInfo: EventDispatchInfo) {
var usedInCurrentTree: Boolean = false
}

@Synchronized
fun clear() {
_dispatchInfos.clear()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import android.view.View
import androidx.annotation.UiThread
import com.facebook.kotlin.compilerplugins.dataclassgenerate.annotation.DataClassGenerate
import com.facebook.kotlin.compilerplugins.dataclassgenerate.annotation.Mode
import com.facebook.litho.config.ComponentsConfiguration
import com.facebook.rendercore.SizeConstraints
import com.facebook.rendercore.utils.ThreadUtils.assertMainThread

Expand Down Expand Up @@ -111,7 +112,11 @@ object NestedLithoTree {

fun LayoutState.cleanup() {
treeState.effectsHandler.onDetached()
treeState.clearUnusedTriggerHandlers()
if (ComponentsConfiguration.clearEventHandlersAndTriggers) {
treeState.clearEventHandlersAndTriggers()
} else {
treeState.clearUnusedTriggerHandlers()
}
}

fun TreeState.enqueue(updates: List<PendingStateUpdate>): TreeState {
Expand Down
5 changes: 5 additions & 0 deletions litho-core/src/main/java/com/facebook/litho/TreeState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,11 @@ class TreeState {
}
}

fun clearEventHandlersAndTriggers() {
synchronized(eventTriggersContainer) { eventTriggersContainer.clear() }
eventHandlersController.clear()
}

fun clearUnusedTriggerHandlers() {
synchronized(eventTriggersContainer) { eventTriggersContainer.clear() }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,9 @@ internal constructor(
/** This config will enable logging of interactable components with 0 alpha */
@JvmField var isZeroAlphaLoggingEnabled: Boolean = false

/** This flag is used to enable clearing event handlers and triggers */
@JvmField var clearEventHandlersAndTriggers: Boolean = false

/**
* This method is only used so that Java clients can have a builder like approach to override a
* configuration.
Expand Down

0 comments on commit 5778398

Please sign in to comment.