Skip to content

Instantly share code, notes, and snippets.

@Jeff-Soares
Created March 4, 2022 01:00
Show Gist options
  • Save Jeff-Soares/efa6493cae1afc1c8680395107395e3d to your computer and use it in GitHub Desktop.
Save Jeff-Soares/efa6493cae1afc1c8680395107395e3d to your computer and use it in GitHub Desktop.
inline fun Fragment.launchAndRepeatWithViewLifecycle(
minActiveState: Lifecycle.State = Lifecycle.State.STARTED,
crossinline block: suspend CoroutineScope.() -> Unit
) {
viewLifecycleOwner.lifecycleScope.launch {
viewLifecycleOwner.lifecycle.repeatOnLifecycle(minActiveState) {
block()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment