Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
DumpSlotTable from Jetpack Compose
Handler().post {
(window.decorView
.findViewById<ViewGroup>(android.R.id.content)
.getChildAt(0) as? ComposeView)
?.let {
val wrappedComposition = AbstractComposeView::class.java
.getDeclaredField("composition")
.apply {
isAccessible = true
}
.get(it)
val composition = (Class.forName("androidx.compose.ui.platform" +
".WrappedComposition")
.getDeclaredField("original")
.apply {
isAccessible = true
}
.get(wrappedComposition) as Composition)
val slotTable = Class.forName("androidx.compose.runtime.CompositionImpl")
.getDeclaredField("slotTable")
.apply {
isAccessible = true
}
.get(composition)
GlobalScope.launch {
delay(100)
var lastSlotTableString = ""
while (true) {
val slotTableString =
Class.forName("androidx.compose.runtime.SlotTable")
.getMethod("asString")
.apply {
isAccessible = true
}
.invoke(slotTable) as String
if (slotTableString != lastSlotTableString) {
lastSlotTableString = slotTableString
println("slotTable:")
println(slotTableString)
}
yield()
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment