Skip to content

Commit 3d12d81

Browse files
lunaleapsfacebook-github-bot
authored andcommitted
VirtualViewExperimental - opt out of update if no rect changes (#53255)
Summary: Pull Request resolved: #53255 Avoid updates to VirtualViewContainer if the rect dimensions haven't changed. This is an attempt to simulate what ReactVirtualView does with `checkRectChange`. Changelog: [Internal] Reviewed By: yungsters Differential Revision: D80182750 fbshipit-source-id: f0f45ac508c1f93e6dbb64ea11c0b44b80d6c3b3
1 parent b75031f commit 3d12d81

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/virtual/viewexperimental/ReactVirtualViewExperimental.kt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ public class ReactVirtualViewExperimental(context: Context) :
3232
internal var renderState: VirtualViewRenderState = VirtualViewRenderState.Unknown
3333

3434
private var scrollView: VirtualViewContainer? = null
35+
36+
private val lastContainerRelativeRect: Rect = Rect()
3537
override val containerRelativeRect: Rect = Rect()
3638
private var offsetX: Int = 0
3739
private var offsetY: Int = 0
@@ -52,7 +54,7 @@ public class ReactVirtualViewExperimental(context: Context) :
5254
// after. If called after, we need to report the updated layout to the VirtualViewContainer
5355
if (hadLayout) {
5456
updateParentOffset()
55-
reportChangeToContainer()
57+
reportRectChangeToContainer()
5658
}
5759
}
5860

@@ -68,7 +70,7 @@ public class ReactVirtualViewExperimental(context: Context) :
6870
right + offsetX,
6971
bottom + offsetY,
7072
)
71-
reportChangeToContainer()
73+
reportRectChangeToContainer()
7274
}
7375
}
7476

@@ -86,7 +88,7 @@ public class ReactVirtualViewExperimental(context: Context) :
8688
) {
8789
if (oldLeft != left || oldTop != top) {
8890
updateParentOffset()
89-
reportChangeToContainer()
91+
reportRectChangeToContainer()
9092
}
9193
}
9294

@@ -102,6 +104,7 @@ public class ReactVirtualViewExperimental(context: Context) :
102104
mode = null
103105
modeChangeEmitter = null
104106
hadLayout = false
107+
lastContainerRelativeRect.setEmpty()
105108
containerRelativeRect.setEmpty()
106109
}
107110

@@ -170,8 +173,13 @@ public class ReactVirtualViewExperimental(context: Context) :
170173
)
171174
}
172175

173-
private fun reportChangeToContainer() {
176+
private fun reportRectChangeToContainer() {
177+
if (lastContainerRelativeRect == containerRelativeRect) {
178+
debugLog("reportRectChangeToContainer") { "no rect change" }
179+
return
180+
}
174181
scrollView?.virtualViewContainerState?.onChange(this)
182+
lastContainerRelativeRect.set(containerRelativeRect)
175183
}
176184

177185
private fun getScrollView(): VirtualViewContainer? = traverseParentStack(true)

0 commit comments

Comments
 (0)