Skip to content

Commit a6b9ae2

Browse files
committed
fix
1 parent fa29c5f commit a6b9ae2

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

core/src/main/java/com/hoc/flowmvi/core/CollectIn.kt

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,23 @@ inline fun <T> Flow<T>.collectIn(
1616
minActiveState: Lifecycle.State = Lifecycle.State.STARTED,
1717
crossinline action: suspend (value: T) -> Unit,
1818
): Job = owner.lifecycleScope.launch {
19-
owner.lifecycle.repeatOnLifecycle(state = minActiveState) {
19+
owner.repeatOnLifecycle(state = minActiveState) {
2020
Log.d("collectIn", "Start collecting $owner $minActiveState...")
2121
collect { action(it) }
2222
}
2323
}
2424

25+
/**
26+
* Launches a new coroutine and repeats `block` every time the Fragment's viewLifecycleOwner
27+
* is in and out of `minActiveState` lifecycle state.
28+
*/
2529
@Suppress("unused")
26-
inline fun <T> Flow<T>.collectIn(
30+
inline fun <T> Flow<T>.collectInViewLifecycle(
2731
fragment: Fragment,
2832
minActiveState: Lifecycle.State = Lifecycle.State.STARTED,
2933
crossinline action: suspend (value: T) -> Unit,
30-
): Job = fragment.lifecycleScope.launch {
31-
fragment.viewLifecycleOwner.repeatOnLifecycle(state = minActiveState) {
32-
Log.d("collectIn", "Start collecting $fragment $minActiveState...")
33-
collect { action(it) }
34-
}
35-
}
34+
): Job = collectIn(
35+
owner = fragment.viewLifecycleOwner,
36+
minActiveState = minActiveState,
37+
action = action,
38+
)

0 commit comments

Comments
 (0)