Skip to content

Instantly share code, notes, and snippets.

@jD4rk
Created September 23, 2021 23:23
Show Gist options
  • Save jD4rk/ec4e60c9b48230a6a0015c72ac0615a6 to your computer and use it in GitHub Desktop.
Save jD4rk/ec4e60c9b48230a6a0015c72ac0615a6 to your computer and use it in GitHub Desktop.
Helper class for debug composable function (Understand recomposition)
class Ref(var value: Int)
// Note the inline function below which ensures that this function is essentially
// copied at the call site to ensure that its logging only recompositions from the
// original call site.
@Composable
inline fun LogCompositions(tag: String, msg: String) {
if (BuildConfig.DEBUG) {
val ref = remember { Ref(0) }
SideEffect { ref.value++ }
Log.d(tag, "Compositions: $msg ${ref.value}")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment