Skip to content

Commit 09be5d9

Browse files
lunaleapsfacebook-github-bot
authored andcommitted
Listen to onSizeChanged and update debugLogs (#53518)
Summary: Pull Request resolved: #53518 Changelog: [Internal] - Listen to `onSizeChanged` for VirtualViewExperimental and VirtualViewContainer (ScrollView) and add more debug logs and format the virtualViewID consistently for easier grepping Reviewed By: yungsters Differential Revision: D81184013 fbshipit-source-id: a4314ab0f94a87e97a7d9b74696726803525c698
1 parent 0808af3 commit 09be5d9

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollView.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,9 @@ protected void onSizeChanged(int w, int h, int oldw, int oldh) {
440440
if (mRemoveClippedSubviews) {
441441
updateClippingRect();
442442
}
443+
if (mVirtualViewContainerState != null) {
444+
mVirtualViewContainerState.updateState();
445+
}
443446
}
444447

445448
@Override

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public class ReactVirtualViewExperimental(context: Context) :
5656
updateParentOffset()
5757
reportRectChangeToContainer()
5858
}
59+
debugLog("doAttachedToWindow")
5960
}
6061

6162
/** From [View#onLayout] */
@@ -70,6 +71,7 @@ public class ReactVirtualViewExperimental(context: Context) :
7071
right + offsetX,
7172
bottom + offsetY,
7273
)
74+
debugLog("onLayout") { "containerRelativeRect=$containerRelativeRect" }
7375
reportRectChangeToContainer()
7476
}
7577
}
@@ -88,10 +90,23 @@ public class ReactVirtualViewExperimental(context: Context) :
8890
) {
8991
if (oldLeft != left || oldTop != top) {
9092
updateParentOffset()
93+
debugLog("onLayoutChange") { "containerRelativeRect=$containerRelativeRect" }
9194
reportRectChangeToContainer()
9295
}
9396
}
9497

98+
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
99+
super.onSizeChanged(w, h, oldw, oldh)
100+
containerRelativeRect.set(
101+
left + offsetX,
102+
top + offsetY,
103+
right + offsetX,
104+
bottom + offsetY,
105+
)
106+
debugLog("onSizeChanged") { "container=$containerRelativeRect" }
107+
reportRectChangeToContainer()
108+
}
109+
95110
override fun onDetachedFromWindow() {
96111
super.onDetachedFromWindow()
97112
recycleView()
@@ -110,7 +125,7 @@ public class ReactVirtualViewExperimental(context: Context) :
110125

111126
override val virtualViewID: String
112127
get() {
113-
return "${nativeId ?: "unknown"}:${id}"
128+
return "${nativeId ?: "unknown"}:::${id}"
114129
}
115130

116131
override fun onModeChange(newMode: VirtualViewMode, thresholdRect: Rect) {
@@ -191,7 +206,7 @@ public class ReactVirtualViewExperimental(context: Context) :
191206

192207
private fun reportRectChangeToContainer() {
193208
if (lastContainerRelativeRect == containerRelativeRect) {
194-
debugLog("reportRectChangeToContainer") { "no rect change" }
209+
debugLog("reportRectChangeToContainer") { "no rect change $containerRelativeRect" }
195210
return
196211
}
197212
scrollView?.virtualViewContainerState?.onChange(this)
@@ -228,7 +243,7 @@ public class ReactVirtualViewExperimental(context: Context) :
228243

229244
internal inline fun debugLog(subtag: String, block: () -> String = { "" }) {
230245
if (IS_DEBUG_BUILD && ReactNativeFeatureFlags.enableVirtualViewDebugFeatures()) {
231-
FLog.d("$DEBUG_TAG:$subtag", "${block()} [$id][$nativeId]")
246+
FLog.d("$DEBUG_TAG:[$virtualViewID]:$subtag", "${block()}")
232247
}
233248
}
234249
}

0 commit comments

Comments
 (0)