Last active
March 21, 2022 14:40
-
-
Save kibotu/8211a2dfc8ea0f41fcb7f9a79a87b1ff to your computer and use it in GitHub Desktop.
Jetpack Compose get activity in Composable from LocalContext.
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
// val activity = LocalContext.current.findActivity() | |
tailrec fun Context.findActivity(): AppCompatActivity? = when (this) { | |
is AppCompatActivity -> this | |
is ContextWrapper -> baseContext.findActivity() | |
else -> null | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you prefer non recursive