Created
March 13, 2026 20:10
-
-
Save LethalMaus/46c71aa74756b2c9deb8d2b9602b5838 to your computer and use it in GitHub Desktop.
Recomposition overlay snippet for Android app startup article
This file contains hidden or 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
| @Composable | |
| private fun RecomposeDebugOverlay(modifier: Modifier = Modifier) { | |
| if (!BuildConfig.DEBUG) return | |
| val counts by RecomposeDebugTracker.counts.collectAsStateWithLifecycle() | |
| var expanded by rememberSaveable { mutableStateOf(false) } | |
| Surface(modifier = modifier.clickable { expanded = !expanded }) { | |
| Column(modifier = Modifier.padding(horizontal = 12.dp, vertical = 8.dp)) { | |
| Text(text = "Recompose ${if (expanded) "hide" else "show"}") | |
| if (expanded) { | |
| counts.toList().sortedBy { it.first }.forEach { (name, count) -> | |
| Text(text = "$name: $count") | |
| } | |
| TextButton(onClick = { RecomposeDebugTracker.reset() }) { | |
| Text(text = stringResource(id = R.string.clear)) | |
| } | |
| } | |
| } | |
| } | |
| } | |
| @Composable | |
| private fun DebugRecomposeCounter(section: String) { | |
| if (!BuildConfig.DEBUG) return | |
| SideEffect { | |
| val count = RecomposeDebugTracker.increment(section) | |
| if (count % 25 == 0) { | |
| Log.d("Recompose", "$section recomposed $count times") | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment