Created
September 23, 2021 23:23
-
-
Save jD4rk/ec4e60c9b48230a6a0015c72ac0615a6 to your computer and use it in GitHub Desktop.
Helper class for debug composable function (Understand recomposition)
This file contains 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
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