Hi Team, I am planning to create a tool that will display the names of the functions from which composables were created, in real time as the user navigates through the app. So far I have not come across any libraries which can do this.
1. Radiography on github creates a tree structure for the compose hierarchy, but I am not sure it can get the name of the functions that created the composables.
2. https://github.com/YvesCheung/UInspector this lib can get the source code information for the compose views.
The second option seems to be the most viable one. Both libraries use reflection to accesss private compose tooling methods/variables. But before I am start working on my lib, I wanted to know if there are better and easier options to get the information that I need.
o
orangy
11/01/2022, 9:13 AM
I couldn’t find complete solution, but I was able to dump composition hierarchy with function names by copying SlotTree.kt from AOSP and tweaking it to my needs.
s
Sushobh
11/01/2022, 9:32 AM
How did you replace SlotTree with your custom SlotTree?
Sushobh
11/01/2022, 9:33 AM
Did you use any library to get access to the compose hirearchy?
Sushobh
11/01/2022, 9:35 AM
Are you referring to var name: String? = null on line 427
o
orangy
11/01/2022, 9:37 AM
Just copied source :) I’m doing it in desktop, so can’t use libs directly due to Android dependencies.
s
Sushobh
11/01/2022, 9:38 AM
You mean create a new file in your project but with same package name? And then modify?
o
orangy
11/01/2022, 9:38 AM
You can get the roots from “currentComposer.compositionData” (don’t remember exactly), but not sure how it works in Android.
orangy
11/01/2022, 9:39 AM
I think there is SourceInfo or something in the data
s
Sushobh
11/01/2022, 9:40 AM
Thanks. I will have a look
o
orangy
11/01/2022, 9:40 AM
Afk currently, can’t check the source. Yeah, explore it