Skip to content

Instantly share code, notes, and snippets.

@saqib-github-commits
Last active January 18, 2024 19:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saqib-github-commits/4aa8d7b941d294b31a58b1357940a387 to your computer and use it in GitHub Desktop.
Save saqib-github-commits/4aa8d7b941d294b31a58b1357940a387 to your computer and use it in GitHub Desktop.
// compositionLocal created for AnalyticsLogger
val LocalAnalyticsLogger = staticCompositionLocalOf<AnalyticsLogger> {
DummyAnalyticsLogger()
}
//a helper compsable function created which is using compositionLocal LocalAnalyticsLogger
// created above and assigning default value
// ocalAnalyticsLogger.current gets current assigned value of AnalyticsLogger which will be
// DummyAnalyticsLogger unless a new implementation is provided
@Composable
fun LogScreenVisited(
screenName: String,
analyticsLogger: AnalyticsLogger = LocalAnalyticsLogger.current
) = LaunchedEffect(Unit) {
analyticsLogger.logScreenVisited(screenName)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment