11

In my Jetpack Compose app, I have an AndroidView wrapping a WebView. While debugging, I see that the WebView is drawn twice (a breakpoint at the composable hosting the AndroidView is hit twice). After inspecting the code, I don't see any state updates that could be triggering this update.

Is there any strategy or tool to identify the "event" that is triggering the redraw of a @Composable?

noe
  • 1,684
  • 1
  • 17
  • 35
  • This is not an answer but might help you: //To observe when a re-draw happens and other info do: private var I = 0 private var registerApplyObserver: ObserverHandle? = null registerApplyObserver = Snapshot.registerApplyObserver { mutatedObjects, snapshot -> Log.i("TEST_TAG", "[${I++}] applying snapshot") for (obj in mutatedObjects) { Log.d("TEST_TAG", "[${I++}] state $obj modified") } } – Gerardo Rodriguez Feb 25 '22 at 16:27
  • Do you have NavHost in your code? If you have it might be recomposed because of it. It gets twice, sometimes more. I had a question about it [here](https://stackoverflow.com/questions/69190119/jetpack-compose-recompose-with-success-state-twice-when-exiting-current-composab) – Thracian Jun 28 '22 at 16:10
  • No, I was not using navigation in that project. Thanks anyway for the hint – noe Jun 28 '22 at 16:12
  • This question was nearly 2 years ago, but Android Studio Dolphin (which is currently in Preview) has [Recomposition Counts](https://developer.android.com/studio/preview/features#li-compose-counter) in the Layout Inspector that might be able to help you debug further! – beyondtheteal Jul 30 '22 at 02:08

1 Answers1

1

Yes! Now you can to identify what changes might have caused the recomposition just by usual debugging process with breakpoints.

This feature already available in the latest version of Android Studio Hedgehog

You can read more about this feature here

tasjapr
  • 632
  • 4
  • 13