Skip to content

Commit a8e7905

Browse files
adityasharatfacebook-github-bot
authored andcommitted
Checks if the MountState will remount with the RenderTree before calling before mount
Summary: Checks if the MountState will remount with a given RenderTree before calling before mount in Litho Reviewed By: pentiumao Differential Revision: D75218907 fbshipit-source-id: ca9550a388306d36fa2ed437b19e1f1f5be729d1
1 parent e1f133b commit a8e7905

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,9 @@ constructor(context: ComponentContext, attrs: AttributeSet? = null) :
499499
val renderTree = layoutState.toRenderTree()
500500
setupMountExtensions()
501501
val coordinator = requireNotNull(lithoHostListenerCoordinator)
502-
coordinator.beforeMount(layoutState, visibleRect)
502+
if (mountState.willRemountWith(renderTree)) {
503+
coordinator.beforeMount(layoutState, visibleRect)
504+
}
503505
mountState.mount(renderTree)
504506
incrementComponentMountCount()
505507
drawDebugOverlay(this, layoutState.componentTreeId)

litho-rendercore/src/main/java/com/facebook/rendercore/MountState.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,10 +404,14 @@ constructor(
404404
}
405405
}
406406

407+
fun willRemountWith(renderTree: RenderTree): Boolean {
408+
return this.renderTree != renderTree || _needsRemount
409+
}
410+
407411
/** Updates the extensions of this [MountState] from the new [RenderTree]. */
408412
private fun updateRenderTree(renderTree: RenderTree): Boolean {
409413
// If the trees are same or if no remount is required, then no update is required.
410-
if (renderTree == this.renderTree && !_needsRemount) {
414+
if (!willRemountWith(renderTree)) {
411415
return false
412416
}
413417

0 commit comments

Comments
 (0)