Skip to content

Commit

Permalink
feat : base fragment 에 repeatOnStarted 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
youlalala committed Nov 16, 2023
1 parent c8c3478 commit 06db8c8
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ import androidx.annotation.LayoutRes
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.fragment.app.Fragment
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch


abstract class BaseFragment<VB : ViewDataBinding>(
Expand All @@ -31,4 +37,10 @@ abstract class BaseFragment<VB : ViewDataBinding>(
super.onDestroyView()
_binding = null
}

fun LifecycleOwner.repeatOnStarted(block: suspend CoroutineScope.() -> Unit) {
viewLifecycleOwner.lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED, block)
}
}
}

0 comments on commit 06db8c8

Please sign in to comment.