-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
…outside
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package pro.respawn.flowmvi.compose.android | ||
|
||
import androidx.lifecycle.Lifecycle | ||
import androidx.lifecycle.LifecycleOwner | ||
import androidx.lifecycle.repeatOnLifecycle | ||
import pro.respawn.flowmvi.compose.api.SubscriberLifecycleOwner | ||
import pro.respawn.flowmvi.compose.api.SubscriptionMode | ||
|
||
public fun LifecycleOwner.asSubscriberOwner(): SubscriberLifecycleOwner = SubscriberLifecycleOwner { mode, block -> | ||
Check warning on line 9 in compose/src/androidMain/kotlin/pro/respawn/flowmvi/compose/android/AndroidInterop.kt Codacy Production / Codacy Static Code Analysiscompose/src/androidMain/kotlin/pro/respawn/flowmvi/compose/android/AndroidInterop.kt#L9
|
||
repeatOnLifecycle(mode.asLifecycleState, block) | ||
} | ||
|
||
public val SubscriptionMode.asLifecycleState: Lifecycle.State | ||
Check warning on line 13 in compose/src/androidMain/kotlin/pro/respawn/flowmvi/compose/android/AndroidInterop.kt Codacy Production / Codacy Static Code Analysiscompose/src/androidMain/kotlin/pro/respawn/flowmvi/compose/android/AndroidInterop.kt#L13
|
||
get() = when (this) { | ||
SubscriptionMode.Immediate -> Lifecycle.State.CREATED | ||
SubscriptionMode.Started -> Lifecycle.State.STARTED | ||
SubscriptionMode.Visible -> Lifecycle.State.RESUMED | ||
} | ||
|
||
public val Lifecycle.State.asSubscriptionMode: SubscriptionMode | ||
Check warning on line 20 in compose/src/androidMain/kotlin/pro/respawn/flowmvi/compose/android/AndroidInterop.kt Codacy Production / Codacy Static Code Analysiscompose/src/androidMain/kotlin/pro/respawn/flowmvi/compose/android/AndroidInterop.kt#L20
|
||
get() = when (this) { | ||
Lifecycle.State.CREATED -> SubscriptionMode.Immediate | ||
Lifecycle.State.STARTED -> SubscriptionMode.Started | ||
Lifecycle.State.RESUMED -> SubscriptionMode.Visible | ||
Lifecycle.State.DESTROYED, | ||
Lifecycle.State.INITIALIZED -> error("Android lifecycle does not support $this as subscription mode") | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package pro.respawn.flowmvi.compose.dsl | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.platform.LocalLifecycleOwner | ||
import pro.respawn.flowmvi.compose.android.asSubscriberOwner | ||
import pro.respawn.flowmvi.compose.api.SubscriberLifecycleOwner | ||
|
||
internal actual val PlatformLifecycle: SubscriberLifecycleOwner? | ||
@Composable get() = LocalLifecycleOwner.current.asSubscriberOwner() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package pro.respawn.flowmvi.compose.api | ||
|
||
import kotlinx.coroutines.CoroutineScope | ||
|
||
public fun interface SubscriberLifecycleOwner { | ||
Check warning on line 5 in compose/src/commonMain/kotlin/pro/respawn/flowmvi/compose/api/SubscriberLifecycleOwner.kt Codacy Production / Codacy Static Code Analysiscompose/src/commonMain/kotlin/pro/respawn/flowmvi/compose/api/SubscriberLifecycleOwner.kt#L5
|
||
|
||
public suspend fun repeatOnLifecycle(mode: SubscriptionMode, block: suspend CoroutineScope.() -> Unit) | ||
Check warning on line 7 in compose/src/commonMain/kotlin/pro/respawn/flowmvi/compose/api/SubscriberLifecycleOwner.kt Codacy Production / Codacy Static Code Analysiscompose/src/commonMain/kotlin/pro/respawn/flowmvi/compose/api/SubscriberLifecycleOwner.kt#L7
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package pro.respawn.flowmvi.compose.api | ||
|
||
public enum class SubscriptionMode { | ||
Immediate, | ||
Started, | ||
Visible, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package pro.respawn.flowmvi.compose.dsl | ||
|
||
import kotlinx.coroutines.coroutineScope | ||
import pro.respawn.flowmvi.compose.api.SubscriberLifecycleOwner | ||
|
||
@PublishedApi | ||
internal val ImmediateLifecycleOwner: SubscriberLifecycleOwner = SubscriberLifecycleOwner { _, block -> | ||
coroutineScope(block) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package pro.respawn.flowmvi.compose.dsl | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.ProvidableCompositionLocal | ||
import androidx.compose.runtime.staticCompositionLocalOf | ||
import pro.respawn.flowmvi.compose.api.SubscriberLifecycleOwner | ||
|
||
public val LocalSubscriberLifecycle: ProvidableCompositionLocal<SubscriberLifecycleOwner?> = staticCompositionLocalOf { | ||
Check warning on line 8 in compose/src/commonMain/kotlin/pro/respawn/flowmvi/compose/dsl/LocalSubscriberLifecycle.kt Codacy Production / Codacy Static Code Analysiscompose/src/commonMain/kotlin/pro/respawn/flowmvi/compose/dsl/LocalSubscriberLifecycle.kt#L8
|
||
null | ||
} | ||
|
||
@PublishedApi | ||
internal val CurrentLifecycle: SubscriberLifecycleOwner | ||
@Composable get() = LocalSubscriberLifecycle.current ?: PlatformLifecycle ?: ImmediateLifecycleOwner | ||
|
||
@get:Composable | ||
internal expect val PlatformLifecycle: SubscriberLifecycleOwner? |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package pro.respawn.flowmvi.compose.dsl | ||
|
||
import androidx.compose.runtime.Composable | ||
import pro.respawn.flowmvi.compose.api.SubscriberLifecycleOwner | ||
|
||
internal actual val PlatformLifecycle: SubscriberLifecycleOwner? @Composable get() = null |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package pro.respawn.flowmvi.compose.dsl | ||
|
||
import androidx.compose.runtime.Composable | ||
import pro.respawn.flowmvi.compose.api.SubscriberLifecycleOwner | ||
|
||
internal actual val PlatformLifecycle: SubscriberLifecycleOwner? @Composable get() = null |