Skip to content

Commit 30a0d91

Browse files
authored
dev: add debugging logs (#127)
* add more debugging logs to ReactViewGroup * more methods * omg
1 parent 57cc311 commit 30a0d91

File tree

1 file changed

+133
-0
lines changed
  • packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/view

1 file changed

+133
-0
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/view/ReactViewGroup.kt

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ import java.util.ArrayList
6969
import kotlin.concurrent.Volatile
7070
import kotlin.math.max
7171

72+
import com.facebook.react.bridge.UiThreadUtil
73+
7274
/**
7375
* Backing for a React View. Has support for borders, but since borders aren't common, lazy
7476
* initializes most of the storage needed for them.
@@ -1027,6 +1029,137 @@ public open class ReactViewGroup public constructor(context: Context?) :
10271029
}
10281030

10291031
//#region debug helper
1032+
override fun removeView(view: View?) {
1033+
UiThreadUtil.assertOnUiThread()
1034+
getNativeId()?.let { nativeId ->
1035+
val viewClass = view?.javaClass?.simpleName ?: "null"
1036+
val viewIndex = indexOfChild(view)
1037+
val stack = getStack()
1038+
val hierarchy = viewHierarchyDescription()
1039+
FLog.w(
1040+
"ReactViewGroup",
1041+
"[$nativeId] removeView called for view of class $viewClass at index $viewIndex\nStack trace:\n$stack\nHierarchy:\n$hierarchy",
1042+
)
1043+
}
1044+
1045+
super.removeView(view)
1046+
}
1047+
1048+
override fun removeViewAt(index: Int) {
1049+
UiThreadUtil.assertOnUiThread()
1050+
getNativeId()?.let { nativeId ->
1051+
val view = getChildAt(index)
1052+
val viewClass = view?.javaClass?.simpleName ?: "null"
1053+
val stack = getStack()
1054+
val hierarchy = viewHierarchyDescription()
1055+
FLog.w(
1056+
"ReactViewGroup",
1057+
"[$nativeId] removeViewAt called for view of class $viewClass at index $index\nStack trace:\n$stack\nHierarchy:\n$hierarchy",
1058+
)
1059+
}
1060+
1061+
super.removeViewAt(index)
1062+
}
1063+
1064+
override fun removeViews(start: Int, count: Int) {
1065+
UiThreadUtil.assertOnUiThread()
1066+
getNativeId()?.let { nativeId ->
1067+
val views = (start until start + count).map { getChildAt(it) }
1068+
val viewClasses = views.map { it?.javaClass?.simpleName ?: "null" }
1069+
val stack = getStack()
1070+
val hierarchy = viewHierarchyDescription()
1071+
FLog.w(
1072+
"ReactViewGroup",
1073+
"[$nativeId] removeViews called for views of classes $viewClasses starting at index $start count $count\nStack trace:\n$stack\nHierarchy:\n$hierarchy",
1074+
)
1075+
}
1076+
1077+
super.removeViews(start, count)
1078+
}
1079+
1080+
override fun removeViewInLayout(view: View?) {
1081+
UiThreadUtil.assertOnUiThread()
1082+
getNativeId()?.let { nativeId ->
1083+
val viewClass = view?.javaClass?.simpleName ?: "null"
1084+
val viewIndex = indexOfChild(view)
1085+
val stack = getStack()
1086+
FLog.w(
1087+
"ReactViewGroup",
1088+
"[$nativeId] removeViewInLayout called for view of class $viewClass at index $viewIndex\nStack trace:\n$stack",
1089+
)
1090+
}
1091+
1092+
super.removeViewInLayout(view)
1093+
}
1094+
1095+
override fun removeViewsInLayout(start: Int, count: Int) {
1096+
UiThreadUtil.assertOnUiThread()
1097+
getNativeId()?.let { nativeId ->
1098+
val views = (start until start + count).map { getChildAt(it) }
1099+
val viewClasses = views.map { it?.javaClass?.simpleName ?: "null" }
1100+
val stack = getStack()
1101+
val hierarchy = viewHierarchyDescription()
1102+
FLog.w(
1103+
"ReactViewGroup",
1104+
"[$nativeId] removeViewsInLayout called for views of classes $viewClasses starting at index $start count $count\nStack trace:\n$stack\nHierarchy:\n$hierarchy",
1105+
)
1106+
}
1107+
1108+
super.removeViewsInLayout(start, count)
1109+
}
1110+
1111+
override fun removeAllViewsInLayout() {
1112+
UiThreadUtil.assertOnUiThread()
1113+
getNativeId()?.let { nativeId ->
1114+
val views = (0 until childCount).map { getChildAt(it) }
1115+
val viewClasses = views.map { it?.javaClass?.simpleName ?: "null" }
1116+
val stack = getStack()
1117+
val hierarchy = viewHierarchyDescription()
1118+
FLog.w(
1119+
"ReactViewGroup",
1120+
"[$nativeId] removeAllViewsInLayout called for views of classes $viewClasses\nStack trace:\n$stack\nHierarchy:\n$hierarchy",
1121+
)
1122+
}
1123+
1124+
super.removeAllViewsInLayout()
1125+
}
1126+
1127+
override fun removeAllViews() {
1128+
UiThreadUtil.assertOnUiThread()
1129+
getNativeId()?.let { nativeId ->
1130+
val views = (0 until childCount).map { getChildAt(it) }
1131+
val viewClasses = views.map { it?.javaClass?.simpleName ?: "null" }
1132+
val stack = getStack()
1133+
val hierarchy = viewHierarchyDescription()
1134+
FLog.w(
1135+
"ReactViewGroup",
1136+
"[$nativeId] removeAllViews called for views of classes $viewClasses\nStack trace:\n$stack\nHierarchy:\n$hierarchy",
1137+
)
1138+
}
1139+
1140+
super.removeAllViews()
1141+
}
1142+
1143+
public fun getNativeId(): String? = getTag(com.facebook.react.R.id.view_tag_native_id) as? String
1144+
1145+
public fun getStack(): String = Thread
1146+
.currentThread()
1147+
.stackTrace
1148+
.drop(2) // Skip the call itself
1149+
.joinToString("\n") { " at ${it.className}.${it.methodName}(${it.fileName}:${it.lineNumber})" }
1150+
1151+
private fun viewHierarchyDescription(): String {
1152+
val childrenViewInfo = describeChildren()
1153+
val childrenCountInfo = "children count info: getChildCount: $childCount"
1154+
val ancestry = try {
1155+
describeViewAncestry(this)
1156+
} catch (_: Exception) {
1157+
null
1158+
}
1159+
1160+
return "View ancestry:\n$ancestry\n$childrenCountInfo\n$childrenViewInfo"
1161+
}
1162+
10301163
public fun describeViewAncestry(start: View): String {
10311164
val sb = StringBuilder()
10321165
var v: View? = start

0 commit comments

Comments
 (0)