hi, is there a way to use an annotation to add mor...
# compose
a
hi, is there a way to use an annotation to add more composable code to a composable function, for example a particular LaunchedEffect?
a
no. what are you trying to achieve?
a
i'd like to be able to write
Copy code
@TrackPageView
@Composable 
fun SomethingScreen() {
    // etc
}
and have some autogenerated code that fires some analytic event when the screen comes into the composable hierarchy
because the tracking code that i have would like to run off a
LifecycleEffect
i'd want to basically have an extra composable glommed on via this annotation, if possible
a
I think it is doable, but I dont have any experience on it. I would have a look at projects that use ksp as a starting point
m
You can't use ksp for your usecase. ksp can't modify an existing code(functions, classes..etc). You will need to dig a bit deeper and write a compiler plugin for this usecase.
a
v well, doesnt sound worth the effort at all then 😅
thanks both
z
It’s not very idiomatic to do this with an annotation in kotlin anyway. I would suggest just writing a PageViewTracker wrapper composable that you wrap the body of SomethingScreen inside. It’s not much more code than an annotation, but much easier and way less magic.
☝️ 3