Created
October 8, 2021 01:23
-
-
Save takahirom/c961ed62b49a9126ef215f25e787caa9 to your computer and use it in GitHub Desktop.
DumpSlotTable from Jetpack Compose
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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