Skip to content

Commit

Permalink
Merge pull request #34 from respawn-app/2.2.0-rc
Browse files Browse the repository at this point in the history
2.2.0
  • Loading branch information
Nek-12 authored Dec 2, 2023
2 parents 2e44af1 + a671dc1 commit afc3526
Show file tree
Hide file tree
Showing 29 changed files with 604 additions and 175 deletions.
1 change: 1 addition & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 17 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,20 @@ flowmvi = "< Badge above 👆🏻 >"
flowmvi-core = { module = "pro.respawn.flowmvi:core", version.ref = "flowmvi" } # multiplatform
flowmvi-test = { module = "pro.respawn.flowmvi:test", version.ref = "flowmvi" } # test DSL

flowmvi-compose = { module = "pro.respawn.flowmvi:compose", version.ref = "flowmvi" } # compose multiplatform
flowmvi-android = { module = "pro.respawn.flowmvi:android", version.ref = "flowmvi" } # common android
flowmvi-view = { module = "pro.respawn.flowmvi:android-view", version.ref = "flowmvi" } # view-based android
flowmvi-compose = { module = "pro.respawn.flowmvi:android-compose", version.ref = "flowmvi" } # compose
```
### Kotlin DSL
```kotlin
dependencies {
val flowmvi = "< Badge above 👆🏻 >"
commonMainImplementation("pro.respawn.flowmvi:core:$flowmvi")
commonMainImplementation("pro.respawn.flowmvi:compose:$flowmvi")
commonTestImplementation("pro.respawn.flowmvi:test:$flowmvi")

androidMainImplementation("pro.respawn.flowmvi:android:$flowmvi")
androidMainImplementation("pro.respawn.flowmvi:android-view:$flowmvi")
androidMainImplementation("pro.respawn.flowmvi:android-compose:$flowmvi")
}
```

Expand Down Expand Up @@ -79,6 +79,7 @@ class CounterContainer(
val store = store<CounterState, CounterIntent, CounterAction>(initial = Loading) {
name = "CounterStore"
parallelIntents = true
coroutineContext = Dispatchers.Default // run all operations on background threads if needed
actionShareBehavior = ActionShareBehavior.Distribute() // disable, share, distribute or consume side effects
intentCapacity = 64

Expand Down Expand Up @@ -171,21 +172,17 @@ val counterPlugin = plugin<CounterState, CounterIntent, CounterAction> {
}
```

### Android support (Compose):
### Compose Multiplatform:

```kotlin
val module = module {
// No more subclassing. Use StoreViewModel for everything and inject containers or stores directly.
factoryOf(::CounterContainer)
viewModel(qualifier<CounterContainer>()) { StoreViewModel(get<CounterContainer>()) }
}
![badge][badge-android] ![badge][badge-ios] ![badge][badge-mac] ![badge][badge-jvm]

// collect the store efficiently based on composable's lifecycle
```kotlin
@Composable
fun CounterScreen() {
val store = getViewModel(qualifier<CounterContainer>())
val store = remember { CounterContainer() } // or use a DI framework

val state by store.subscribe { action -> // collect actions/states from composables
// collect the state and handle events efficiently based on system lifecycle, whether it's iOS or Desktop
val state by store.subscribe { action ->
when (action) {
is ShowMessage -> {
/* ... */
Expand All @@ -203,17 +200,23 @@ fun CounterScreen() {
}
```

### Android support (View):
### Android support:

```kotlin
val module = module {
// No more subclassing. Use StoreViewModel for everything and inject containers or stores directly.
factoryOf(::CounterContainer)
viewModel(qualifier<CounterContainer>()) { StoreViewModel(get<CounterContainer>()) }
}

class ScreenFragment : Fragment() {

private val vm by viewModel(qualifier<CounterContainer>())

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
// One-liner for store subscription. Lifecycle-aware and efficient.
subscribe(vm, ::consume, ::render)
subscribe(vm, ::consume, ::render)
}

private fun render(state: CounterState) {
Expand Down
26 changes: 6 additions & 20 deletions android-compose/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,25 @@ plugins {
id("pro.respawn.android-library")
}

private val PluginPrefix = "plugin:androidx.compose.compiler.plugins.kotlin:reportsDestination"

android {
namespace = "${Config.artifactId}.android.compose"
namespace = "${Config.namespace}.android.compose"

buildFeatures {
compose = true
}

composeOptions {
kotlinCompilerExtensionVersion = libs.versions.compose.compiler.get()
useLiveLiterals = true
}

kotlinOptions {
freeCompilerArgs += buildList {
if (project.findProperty("enableComposeCompilerReports") == "true") {
add("-P")
add("$PluginPrefix=${layout.buildDirectory.get()}/compose_metrics")
add("-P")
add("$PluginPrefix=${layout.buildDirectory.get()}/compose_metrics")
}
}
jvmTarget = Config.jvmTarget.target
languageVersion = Config.kotlinVersion.version
freeCompilerArgs += listOf(
"-P",
"plugin:androidx.compose.compiler.plugins.kotlin:stabilityConfigurationPath=" +
rootProject.rootDir.absolutePath + "/stability_definitions.txt"
)
}
}

dependencies {
api(projects.core)
api(projects.android)

implementation(libs.compose.ui)
implementation(libs.compose.foundation)
implementation(libs.compose.preview)
implementation(libs.compose.lifecycle.viewmodel)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ import pro.respawn.flowmvi.dsl.subscribe
import kotlin.experimental.ExperimentalTypeInference

private const val Package = "pro.respawn.flowmvi.android.compose.dsl"
internal const val ComposeArtifactMessage = """
android-compose module is redundant, because new "compose" module has been made which supports Compose Multiplatform.
Please just replace android-compose with just "compose" and change the package name to "pro.respawn.flowmvi.compose"
"""

/**
* An interface for the scope that provides [send] and [consume] functions inside your composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import androidx.lifecycle.repeatOnLifecycle
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import pro.respawn.flowmvi.android.compose.ComposeArtifactMessage
import pro.respawn.flowmvi.api.DelicateStoreApi
import pro.respawn.flowmvi.api.FlowMVIDSL
import pro.respawn.flowmvi.api.ImmutableStore
Expand Down Expand Up @@ -40,6 +41,7 @@ import pro.respawn.flowmvi.dsl.subscribe
@Suppress("NOTHING_TO_INLINE", "ComposableParametersOrdering")
@Composable
@FlowMVIDSL
@Deprecated(ComposeArtifactMessage)
public inline fun <S : MVIState, I : MVIIntent, A : MVIAction> ImmutableStore<S, I, A>.subscribe(
lifecycleState: Lifecycle.State = Lifecycle.State.STARTED,
noinline consume: suspend CoroutineScope.(action: A) -> Unit,
Expand Down Expand Up @@ -77,6 +79,7 @@ public inline fun <S : MVIState, I : MVIIntent, A : MVIAction> ImmutableStore<S,
@Suppress("NOTHING_TO_INLINE")
@Composable
@FlowMVIDSL
@Deprecated(ComposeArtifactMessage)
public inline fun <S : MVIState, I : MVIIntent, A : MVIAction> ImmutableStore<S, I, A>.subscribe(
lifecycleState: Lifecycle.State = Lifecycle.State.STARTED,
): State<S> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package pro.respawn.flowmvi.android.compose.preview

import androidx.compose.runtime.Composable
import androidx.compose.runtime.Immutable
import pro.respawn.flowmvi.android.compose.ComposeArtifactMessage
import pro.respawn.flowmvi.api.IntentReceiver
import pro.respawn.flowmvi.api.MVIIntent

@Deprecated(ComposeArtifactMessage)
@Immutable
private object EmptyReceiver : IntentReceiver<MVIIntent> {

Expand All @@ -16,6 +18,7 @@ private object EmptyReceiver : IntentReceiver<MVIIntent> {
* An [IntentReceiver] that does nothing and ignores all intents. Most often used for Composable previews.
*/
@Composable
@Deprecated(ComposeArtifactMessage)
public fun <I : MVIIntent> EmptyReceiver(
@BuilderInference call: @Composable IntentReceiver<I>.() -> Unit,
): Unit = call(EmptyReceiver as IntentReceiver<I>)
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package pro.respawn.flowmvi.android.compose.preview

import androidx.compose.ui.tooling.preview.datasource.CollectionPreviewParameterProvider
import pro.respawn.flowmvi.android.compose.ComposeArtifactMessage
import pro.respawn.flowmvi.api.MVIState

/**
* A collection preview param provider that provides [MVIState]
* Created to avoid boilerplate related to Preview parameters.
*/
@Deprecated(ComposeArtifactMessage)
public open class StateProvider<S>(
vararg states: S,
) : CollectionPreviewParameterProvider<S>(states.toList())
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ android {

dependencies {
implementation(projects.android)
implementation(projects.androidCompose)
implementation(projects.compose)
implementation(projects.androidView)

implementation(libs.bundles.koin)
implementation(libs.koin.compose)
implementation(libs.koin.android.compose)

implementation(libs.androidx.core)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import androidx.compose.ui.unit.dp
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
import org.koin.core.parameter.parametersOf
import pro.respawn.flowmvi.android.compose.dsl.subscribe
import pro.respawn.flowmvi.android.compose.preview.EmptyReceiver
import pro.respawn.flowmvi.android.compose.preview.StateProvider
import pro.respawn.flowmvi.api.IntentReceiver
import pro.respawn.flowmvi.compose.preview.StateProvider
import pro.respawn.flowmvi.compose.dsl.subscribe
import pro.respawn.flowmvi.compose.preview.EmptyReceiver
import pro.respawn.flowmvi.sample.CounterAction.GoBack
import pro.respawn.flowmvi.sample.CounterAction.ShowErrorMessage
import pro.respawn.flowmvi.sample.CounterAction.ShowLambdaMessage
Expand Down
34 changes: 18 additions & 16 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnLockMismatchReport
import org.jetbrains.kotlin.gradle.targets.js.yarn.YarnRootExtension
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

@Suppress("DSL_SCOPE_VIOLATION")
private val PluginPrefix = "plugin:androidx.compose.compiler.plugins.kotlin:reportsDestination"

plugins {
alias(libs.plugins.detekt)
alias(libs.plugins.gradleDoctor)
Expand All @@ -12,15 +13,11 @@ plugins {
alias(libs.plugins.dokka)
alias(libs.plugins.atomicfu)
alias(libs.plugins.dependencyAnalysis)
}

buildscript {
dependencies {
classpath(libs.android.gradle)
classpath(libs.kotlin.gradle)
classpath(libs.version.gradle)
classpath(libs.detekt.gradle)
}
alias(libs.plugins.jetbrainsCompose) apply false
// plugins already on a classpath (conventions)
// alias(libs.plugins.androidApplication) apply false
// alias(libs.plugins.androidLibrary) apply false
// alias(libs.plugins.kotlinMultiplatform) apply false
}

allprojects {
Expand All @@ -30,12 +27,17 @@ allprojects {
compilerOptions {
jvmTarget.set(Config.jvmTarget)
languageVersion.set(Config.kotlinVersion)
freeCompilerArgs.addAll(Config.jvmCompilerArgs)
freeCompilerArgs.addAll(
"-P",
"plugin:androidx.compose.compiler.plugins.kotlin:stabilityConfigurationPath=" +
rootProject.rootDir.absolutePath + "/stability_definitions.txt"
)
freeCompilerArgs.apply {
addAll(Config.jvmCompilerArgs)
if (project.findProperty("enableComposeCompilerReports") == "true") {
addAll(
"-P",
"$PluginPrefix=${layout.buildDirectory.get()}/compose_metrics",
"-P",
"$PluginPrefix=${layout.buildDirectory.get()}/compose_metrics",
)
}
}
optIn.addAll(Config.optIns.map { "-opt-in=$it" })
}
}
Expand Down
4 changes: 2 additions & 2 deletions buildSrc/src/main/kotlin/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ object Config {
const val artifactId = "$group.$artifact"

const val majorRelease = 2
const val minorRelease = 1
const val minorRelease = 2
const val patch = 0
const val postfix = "rc03"
const val postfix = "rc"
const val versionName = "$majorRelease.$minorRelease.$patch-$postfix"
const val url = "https://github.com/respawn-app/FlowMVI"
const val licenseName = "The Apache Software License, Version 2.0"
Expand Down
11 changes: 5 additions & 6 deletions buildSrc/src/main/kotlin/ConfigureAndroid.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,11 @@ fun Project.configureAndroid(
}

packaging {
resources {
excludes += setOf(
"DebugProbesKt.bin",
"/META-INF/{AL2.0,LGPL2.1}",
)
}
resources.excludes += listOf(
"/META-INF/{AL2.0,LGPL2.1}",
"DebugProbesKt.bin",
"META-INF/versions/9/previous-compilation-data.bin"
)
}

testOptions {
Expand Down
Loading

0 comments on commit afc3526

Please sign in to comment.