Skip to content

Commit 00bbd32

Browse files
authored
mvi-compose to KMP (#36)
* Migrated mvi-compose to kmp * Updated gitignore * Bumped mvi-compose to 0.1.0 * Reformat code with the new guidelines
1 parent 7144ea3 commit 00bbd32

File tree

13 files changed

+93
-45
lines changed

13 files changed

+93
-45
lines changed

.editorconfig

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
root = true
2+
3+
# Disable ktlint on generated source code, see
4+
# https://github.com/JLLeitschuh/ktlint-gradle/issues/746
5+
[**/build/generated/**]
6+
ktlint = disabled
7+
8+
[*.{kt,kts}]
9+
insert_final_newline = true
10+
max_line_length = 250
11+
ij_kotlin_imports_layout = *, ^
12+
ij_kotlin_allow_trailing_comma = true
13+
ij_kotlin_allow_trailing_comma_on_call_site = true
14+
ktlint_compose_preview-public-check = disabled
15+
ktlint_function_naming_ignore_when_annotated_with = Composable

.gitignore

+11-9
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@
4242
# When using Gradle or Maven with auto-import, you should exclude module files,
4343
# since they will be recreated, and may cause churn. Uncomment if using
4444
# auto-import.
45-
# .idea/artifacts
46-
# .idea/compiler.xml
47-
# .idea/jarRepositories.xml
48-
# .idea/modules.xml
49-
# .idea/*.iml
50-
# .idea/modules
51-
# *.iml
52-
# *.ipr
45+
.idea/artifacts
46+
.idea/compiler.xml
47+
.idea/jarRepositories.xml
48+
.idea/modules.xml
49+
.idea/*.iml
50+
.idea/modules
51+
*.iml
52+
*.ipr
5353

5454
# CMake
5555
cmake-build-*/
@@ -187,4 +187,6 @@ gradle-app.setting
187187

188188
.DS_Store
189189

190-
local.properties
190+
local.properties
191+
192+
.kotlin

gradle/libs.versions.toml

+6-6
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ koin-android = "3.5.6"
77
koin-compose = "3.5.6"
88
kotlin = "2.0.0"
99
coroutines = "1.8.1"
10-
kotest = "5.9.0"
11-
material = "1.7.0"
12-
mvi = "1.7.0"
10+
kotest = "5.9.1"
11+
material = "1.7.1"
12+
mvi = "1.8.2-alpha01"
1313
mvi-compose = "0.0.3"
1414
activity = "1.9.2"
15-
lifecycle = "2.8.5"
15+
androidx-lifecycle = "2.8.0"
1616
ktlint-gradle = "12.1.0"
1717
android-library = "8.3.2"
1818
maven-publish = "0.29.0"
19-
ui = "1.7.0"
19+
ui = "1.7.1"
2020
mockk = "1.13.11"
2121
mvi-kotest = "0.0.2"
2222

@@ -35,7 +35,7 @@ mvi = { module = "com.adidas.mvi:mvi", version.ref = "mvi" }
3535
mviCompose = { module = "com.adidas.mvi:mvi-compose", version.ref = "mvi-compose" }
3636
mviKotest = { module = "com.adidas.mvi:mvi-kotest", version.ref = "mvi-kotest" }
3737
activityCompose = { module = "androidx.activity:activity-compose", version.ref = "activity" }
38-
lifecycleRuntimeCompose = { module = "androidx.lifecycle:lifecycle-runtime-compose", version.ref = "lifecycle" }
38+
androidx-lifecycle-runtime-compose = { group = "org.jetbrains.androidx.lifecycle", name = "lifecycle-runtime-compose", version.ref = "androidx-lifecycle" }
3939
material = { module = "androidx.compose.material:material", version.ref = "material" }
4040
ui = { module = "androidx.compose.ui:ui", version.ref = "ui" }
4141
koinCore = { module = "io.insert-koin:koin-core", version.ref = "koin" }

mvi-compose/build.gradle.kts

+51-14
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,56 @@
1+
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
2+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
3+
import org.jlleitschuh.gradle.ktlint.KtlintExtension
4+
15
plugins {
2-
alias(libs.plugins.android.library)
3-
alias(libs.plugins.kotlin.android)
6+
alias(libs.plugins.kotlinMultiplatform)
7+
alias(libs.plugins.ktlint)
48
alias(libs.plugins.mavenPublish)
59
alias(libs.plugins.compose.compiler)
10+
alias(libs.plugins.android.library)
611
}
712

813
kotlin {
914
explicitApi()
15+
16+
jvm()
17+
androidTarget {
18+
@OptIn(ExperimentalKotlinGradlePluginApi::class)
19+
compilerOptions {
20+
jvmTarget.set(JvmTarget.JVM_17)
21+
}
22+
}
23+
24+
listOf(
25+
iosX64(),
26+
iosArm64(),
27+
iosSimulatorArm64(),
28+
macosX64(),
29+
macosArm64(),
30+
watchosArm32(),
31+
watchosArm64(),
32+
watchosSimulatorArm64(),
33+
watchosX64(),
34+
tvosArm64(),
35+
tvosSimulatorArm64(),
36+
tvosX64(),
37+
).forEach {
38+
it.binaries.framework {
39+
baseName = "mvi-compose"
40+
isStatic = true
41+
}
42+
}
43+
44+
sourceSets {
45+
commonMain.dependencies {
46+
implementation(libs.mvi)
47+
implementation(libs.androidx.lifecycle.runtime.compose)
48+
}
49+
50+
androidMain.dependencies {
51+
implementation(libs.activityCompose)
52+
}
53+
}
1054
}
1155

1256
android {
@@ -25,27 +69,20 @@ android {
2569
isMinifyEnabled = false
2670
proguardFiles(
2771
getDefaultProguardFile("proguard-android-optimize.txt"),
28-
"proguard-rules.pro"
72+
"proguard-rules.pro",
2973
)
3074
}
3175
}
3276
compileOptions {
33-
sourceCompatibility = JavaVersion.VERSION_1_8
34-
targetCompatibility = JavaVersion.VERSION_1_8
35-
}
36-
kotlinOptions {
37-
jvmTarget = JavaVersion.VERSION_1_8.toString()
77+
sourceCompatibility = JavaVersion.VERSION_17
78+
targetCompatibility = JavaVersion.VERSION_17
3879
}
3980

4081
buildFeatures {
4182
compose = true
4283
}
4384
}
4485

45-
dependencies {
46-
47-
implementation(platform(libs.kotlinBom))
48-
implementation(libs.mvi)
49-
implementation(libs.activityCompose)
50-
implementation(libs.lifecycleRuntimeCompose)
86+
configure<KtlintExtension> {
87+
version.set(libs.versions.ktlint.lib.get())
5188
}

mvi-compose/gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
POM_ARTIFACT_ID=mvi-compose
22
GROUP=com.adidas.mvi
33
VERSION_CODE=1
4-
VERSION_NAME=0.0.3
4+
VERSION_NAME=0.1.0
55
POM_NAME=Adidas MVI Compose
66
POM_DESCRIPTION=Adidas MVI Compose
77
POM_PACKAGING=aar

mvi-compose/src/main/AndroidManifest.xml

-2
This file was deleted.

mvi-sample/build.gradle.kts

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ dependencies {
7979
implementation(libs.material)
8080

8181
implementation(libs.mvi)
82-
implementation(libs.mviCompose)
82+
implementation(project(":mvi-compose"))
8383

8484
implementation(libs.koinCore)
8585
implementation(libs.koinAndroid)
@@ -90,4 +90,4 @@ dependencies {
9090
testImplementation(libs.kotestRunner)
9191
testImplementation(libs.mockk)
9292
testImplementation(libs.mviKotest)
93-
}
93+
}

mvi/src/commonMain/kotlin/com/adidas/mvi/Reducer.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.adidas.mvi
22

33
import com.adidas.mvi.transform.StateTransform
4+
import kotlin.coroutines.coroutineContext
5+
import kotlin.reflect.KClass
46
import kotlinx.coroutines.CoroutineDispatcher
57
import kotlinx.coroutines.CoroutineScope
68
import kotlinx.coroutines.Dispatchers
@@ -13,8 +15,6 @@ import kotlinx.coroutines.flow.scan
1315
import kotlinx.coroutines.flow.stateIn
1416
import kotlinx.coroutines.isActive
1517
import kotlinx.coroutines.launch
16-
import kotlin.coroutines.coroutineContext
17-
import kotlin.reflect.KClass
1818

1919
public class Reducer<TIntent, TState>(
2020
private val coroutineScope: CoroutineScope,

mvi/src/commonMain/kotlin/com/adidas/mvi/requirements/ReduceExtensions.kt

+1-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ public inline fun <TState : LoggableState, reified TRequiredState : TState> requ
99
return StateReduceRequirement(TRequiredState::class, reduce).reduce(state)
1010
}
1111

12-
public inline fun <TState : LoggableState, reified TRequiredState : TState> requireState(
13-
noinline reduce: (TRequiredState) -> TState,
14-
): ReduceRequirement<TState> {
12+
public inline fun <TState : LoggableState, reified TRequiredState : TState> requireState(noinline reduce: (TRequiredState) -> TState): ReduceRequirement<TState> {
1513
return StateReduceRequirement(TRequiredState::class, reduce)
1614
}
1715

mvi/src/jvmTest/kotlin/com/adidas/mvi/reducer/ReducerTests.kt

+1-3
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,7 @@ internal class ReducerTests : BehaviorSpec({
189189
}
190190
})
191191

192-
private fun createIntentExecutorContainer(
193-
executedIntents: MutableList<TestIntent> = mutableListOf(),
194-
): (TestIntent) -> Flow<StateTransform<State<TestState, TestSideEffect>>> =
192+
private fun createIntentExecutorContainer(executedIntents: MutableList<TestIntent> = mutableListOf()): (TestIntent) -> Flow<StateTransform<State<TestState, TestSideEffect>>> =
195193
{
196194
executedIntents.add(it)
197195
flowOf(TestTransform.Transform1)

mvi/src/jvmTest/kotlin/com/adidas/mvi/sideeffects/SideEffectsTest.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ import io.kotest.matchers.booleans.shouldBeFalse
55
import io.kotest.matchers.collections.shouldBeEmpty
66
import io.kotest.matchers.collections.shouldContain
77
import io.kotest.matchers.collections.shouldContainInOrder
8-
import kotlinx.coroutines.Dispatchers
9-
import kotlinx.coroutines.launch
10-
import kotlinx.coroutines.sync.Semaphore
118
import kotlin.time.DurationUnit
129
import kotlin.time.ExperimentalTime
1310
import kotlin.time.toDuration
11+
import kotlinx.coroutines.Dispatchers
12+
import kotlinx.coroutines.launch
13+
import kotlinx.coroutines.sync.Semaphore
1414

1515
@ExperimentalTime
1616
internal class SideEffectsTest : BehaviorSpec({

0 commit comments

Comments
 (0)