Skip to content

Commit d0cf0a4

Browse files
Andrew Wangfacebook-github-bot
authored andcommitted
Clean up ComponentHost
Summary: As per title Reviewed By: zielinskimz Differential Revision: D61979330 fbshipit-source-id: a535d88c6d5d611591aa17e98600a5c3cf75349b
1 parent 3097a92 commit d0cf0a4

File tree

2 files changed

+46
-22
lines changed

2 files changed

+46
-22
lines changed

litho-core/src/main/java/com/facebook/litho/ComponentHost.kt

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ open class ComponentHost(
7676
attrs: AttributeSet?,
7777
private val unsafeModificationPolicy: UnsafeModificationPolicy?
7878
) : Host(context, attrs), DisappearingHost, SupportsPivotTransform {
79+
7980
private val mountItems: SparseArrayCompat<MountItem> = SparseArrayCompat()
8081
private var scrapMountItemsArray: SparseArrayCompat<MountItem>? = null
8182
private val viewMountItems = SparseArrayCompat<MountItem>()
@@ -93,6 +94,21 @@ open class ComponentHost(
9394
private var componentAccessibilityDelegate: ComponentAccessibilityDelegate? = null
9495
private var isComponentAccessibilityDelegateSet = false
9596
private var onLongClickListener: ComponentLongClickListener? = null
97+
private var onInterceptTouchEventHandler: EventHandler<InterceptTouchEvent>? = null
98+
private var pivotXPercent = UNSET
99+
private var pivotYPercent = UNSET
100+
/**
101+
* Is `true` if and only if any accessible mounted child content has extra A11Y nodes. This is
102+
* `false` by default, and is set for every mount, unmount, and update call.
103+
*/
104+
private var implementsVirtualViews = false
105+
/**
106+
* This flag is used to understand if a view property (e.g, click listener) was modified under the
107+
* context of a Litho operation or not. It is used to detect unsafe modifications and log them.
108+
*
109+
* @see {@link LithoViewAttributesExtension}
110+
*/
111+
private var isSafeViewModificationsEnabled = false
96112

97113
/**
98114
* Sets a focus change listener on this host.
@@ -212,28 +228,6 @@ open class ComponentHost(
212228
return drawables
213229
}
214230

215-
private var onInterceptTouchEventHandler: EventHandler<InterceptTouchEvent>? = null
216-
private var pivotXPercent = UNSET
217-
private var pivotYPercent = UNSET
218-
219-
internal interface ExceptionLogMessageProvider {
220-
val logMessage: StringBuilder?
221-
}
222-
223-
/**
224-
* Is `true` if and only if any accessible mounted child content has extra A11Y nodes. This is
225-
* `false` by default, and is set for every mount, unmount, and update call.
226-
*/
227-
private var implementsVirtualViews = false
228-
229-
/**
230-
* This flag is used to understand if a view property (e.g, click listener) was modified under the
231-
* context of a Litho operation or not. It is used to detect unsafe modifications and log them.
232-
*
233-
* @see {@link LithoViewAttributesExtension}
234-
*/
235-
private var isSafeViewModificationsEnabled = false
236-
237231
constructor(
238232
context: Context,
239233
unsafeModificationPolicy: UnsafeModificationPolicy?
@@ -1374,6 +1368,33 @@ open class ComponentHost(
13741368
super.setOnFocusChangeListener(l)
13751369
}
13761370

1371+
/** Clean up all fields to avoid being reused with an incorrect state. */
1372+
fun cleanup() {
1373+
mountItems.clear()
1374+
viewMountItems.clear()
1375+
drawableMountItems.clear()
1376+
scrapViewMountItemsArray = null
1377+
scrapMountItemsArray = null
1378+
scrapDrawableMountItems = null
1379+
disappearingItems = null
1380+
contentDescription = null
1381+
viewTags = null
1382+
childDrawingOrder = IntArray(0)
1383+
isChildDrawingOrderDirty = false
1384+
inLayout = false
1385+
hadChildWithDuplicateParentState = false
1386+
componentAccessibilityDelegate = null
1387+
isComponentAccessibilityDelegateSet = false
1388+
onLongClickListener = null
1389+
onInterceptTouchEventHandler = null
1390+
pivotXPercent = UNSET
1391+
pivotYPercent = UNSET
1392+
implementsVirtualViews = false
1393+
isSafeViewModificationsEnabled = false
1394+
componentTouchListener = null
1395+
touchExpansionDelegate = null
1396+
}
1397+
13771398
/**
13781399
* This determines what is the actions to take if we detected an invalid modification of a
13791400
* [ComponentHost].

litho-core/src/main/java/com/facebook/litho/host/HostViewAttributesCleanupBinder.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ class HostViewAttributesCleanupBinder : RenderUnit.Binder<Any?, Host, Any> {
4949
bindData: Any?
5050
) {
5151
unsetAllViewAttributes(content)
52+
if (content is ComponentHost) {
53+
content.cleanup()
54+
}
5255
}
5356
}
5457

0 commit comments

Comments
 (0)