Skip to content

Instantly share code, notes, and snippets.

@takahirom
Created October 8, 2021 01:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takahirom/c961ed62b49a9126ef215f25e787caa9 to your computer and use it in GitHub Desktop.
Save takahirom/c961ed62b49a9126ef215f25e787caa9 to your computer and use it in GitHub Desktop.
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