File tree Expand file tree Collapse file tree 1 file changed +11
-8
lines changed
core/src/main/java/com/hoc/flowmvi/core Expand file tree Collapse file tree 1 file changed +11
-8
lines changed Original file line number Diff line number Diff line change @@ -16,20 +16,23 @@ inline fun <T> Flow<T>.collectIn(
16
16
minActiveState : Lifecycle .State = Lifecycle .State .STARTED ,
17
17
crossinline action : suspend (value: T ) -> Unit ,
18
18
): Job = owner.lifecycleScope.launch {
19
- owner.lifecycle. repeatOnLifecycle(state = minActiveState) {
19
+ owner.repeatOnLifecycle(state = minActiveState) {
20
20
Log .d(" collectIn" , " Start collecting $owner $minActiveState ..." )
21
21
collect { action(it) }
22
22
}
23
23
}
24
24
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
+ */
25
29
@Suppress(" unused" )
26
- inline fun <T > Flow<T>.collectIn (
30
+ inline fun <T > Flow<T>.collectInViewLifecycle (
27
31
fragment : Fragment ,
28
32
minActiveState : Lifecycle .State = Lifecycle .State .STARTED ,
29
33
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
+ )
You can’t perform that action at this time.
0 commit comments