Skip to content

Instantly share code, notes, and snippets.

@benigumocom
Last active April 14, 2022 05:08

Revisions

  1. chanzmao revised this gist Sep 7, 2021. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions UiUtils.kt
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,3 @@
    // https://sourcegraph.com/github.com/google/iosched/-/blob/mobile/src/main/java/com/google/samples/apps/iosched/util/UiUtils.kt?L56-69

    /**
    * Launches a new coroutine and repeats `block` every time the Fragment's viewLifecycleOwner
    * is in and out of `minActiveState` lifecycle state.
  2. chanzmao revised this gist Sep 6, 2021. No changes.
  3. chanzmao revised this gist Sep 6, 2021. No changes.
  4. chanzmao revised this gist Sep 6, 2021. No changes.
  5. chanzmao created this gist Sep 6, 2021.
    16 changes: 16 additions & 0 deletions UiUtils.kt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    // https://sourcegraph.com/github.com/google/iosched/-/blob/mobile/src/main/java/com/google/samples/apps/iosched/util/UiUtils.kt?L56-69

    /**
    * Launches a new coroutine and repeats `block` every time the Fragment's viewLifecycleOwner
    * is in and out of `minActiveState` lifecycle state.
    */
    inline fun Fragment.launchAndRepeatWithViewLifecycle(
    minActiveState: Lifecycle.State = Lifecycle.State.STARTED,
    crossinline block: suspend CoroutineScope.() -> Unit
    ) {
    viewLifecycleOwner.lifecycleScope.launch {
    viewLifecycleOwner.lifecycle.repeatOnLifecycle(minActiveState) {
    block()
    }
    }
    }