Skip to content

Commit f304580

Browse files
committed
Properly handle recycling of RecomposeHighlighterModifier
After migrating to be Node based, it's possible the Modifier node can be reused. For example, when scrolling in a LazyColumn the nodes of items scrolled off the viewport may be recycled and used with items scrolling into the viewport. When this occurs, the composition count needs to be reset. Otherwise, it may look like the item scrolling into the viewport has recomposed more than it actually has.
1 parent da3ebb8 commit f304580

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

compose/recomposehighlighter/src/main/java/com/example/android/compose/recomposehighlighter/RecomposeHighlighter.kt

+4
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ private class RecomposeHighlighterModifier : Modifier.Node(), DrawModifierNode {
8989

9090
override val shouldAutoInvalidate: Boolean = false
9191

92+
override fun onReset() {
93+
totalCompositions = 0
94+
timerJob?.cancel()
95+
}
9296
override fun onDetach() {
9397
timerJob?.cancel()
9498
}

0 commit comments

Comments
 (0)