-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
83 changed files
with
1,342 additions
and
578 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
compose/src/androidMain/kotlin/pro/respawn/flowmvi/compose/android/AndroidInterop.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package pro.respawn.flowmvi.compose.android | ||
|
||
import androidx.compose.runtime.Stable | ||
import androidx.lifecycle.Lifecycle | ||
import androidx.lifecycle.LifecycleOwner | ||
import androidx.lifecycle.repeatOnLifecycle | ||
import pro.respawn.flowmvi.compose.api.SubscriberLifecycle | ||
import pro.respawn.flowmvi.compose.api.SubscriptionMode | ||
|
||
/** | ||
* Converts this Android [LifecycleOwner] to a [SubscriberLifecycle]. | ||
*/ | ||
@Stable | ||
public fun Lifecycle.asSubscriberOwner(): SubscriberLifecycle = SubscriberLifecycle { mode, block -> | ||
repeatOnLifecycle(mode.asLifecycleState, block) | ||
} | ||
|
||
/** | ||
* Converts this [SubscriptionMode] to a [Lifecycle.State] | ||
*/ | ||
@Stable | ||
public val SubscriptionMode.asLifecycleState: Lifecycle.State | ||
get() = when (this) { | ||
SubscriptionMode.Immediate -> Lifecycle.State.CREATED | ||
SubscriptionMode.Started -> Lifecycle.State.STARTED | ||
SubscriptionMode.Visible -> Lifecycle.State.RESUMED | ||
} | ||
|
||
/** | ||
* Converts the [Lifecycle.State] to a [SubscriptionMode] | ||
* | ||
* [Lifecycle.State.DESTROYED] and [Lifecycle.State.INITIALIZED] **cannot** be used as valid subscription modes as | ||
* it is not supported by Android | ||
*/ | ||
@Stable | ||
public val Lifecycle.State.asSubscriptionMode: SubscriptionMode | ||
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") | ||
} |
10 changes: 10 additions & 0 deletions
10
...rc/androidMain/kotlin/pro/respawn/flowmvi/compose/dsl/LocalSubscriberLifecycle.android.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package pro.respawn.flowmvi.compose.dsl | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.ReadOnlyComposable | ||
import androidx.compose.ui.platform.LocalLifecycleOwner | ||
import pro.respawn.flowmvi.compose.android.asSubscriberOwner | ||
import pro.respawn.flowmvi.compose.api.SubscriberLifecycle | ||
|
||
internal actual val PlatformLifecycle: SubscriberLifecycle? | ||
@Composable @ReadOnlyComposable get() = LocalLifecycleOwner.current.lifecycle.asSubscriberOwner() |
Oops, something went wrong.