Skip to content

Commit ecce694

Browse files
authored
Merge pull request #3 from rickclephas/feature/kotlin-1.8.0
Kotlin 1.8.0
2 parents cead02d + a086dc9 commit ecce694

13 files changed

Lines changed: 60 additions & 23 deletions

File tree

.idea/kotlinc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,30 @@ open class TimeTravelViewModel: KMMViewModel() {
5151
You need to use `viewModelScope` wherever possible to propagate state changes to iOS.
5252
In other cases you can access the `ViewModelScope.coroutineScope` property directly.
5353

54+
### KMP-NativeCoroutines
55+
56+
Use the `@NativeCoroutinesState` annotation from [KMP-NativeCoroutines](https://github.com/rickclephas/KMP-NativeCoroutines)
57+
to turn your `StateFlow`s into properties in Swift:
58+
59+
```kotlin
60+
@NativeCoroutinesState
61+
val travelEffect = _travelEffect.asStateFlow()
62+
```
63+
64+
Checkout the [README](https://github.com/rickclephas/KMP-NativeCoroutines/blob/dev-1.0/README.md)
65+
for more information and installation instructions for KMP-NativeCoroutines.
66+
67+
<details><summary>Alternative</summary>
68+
<p>
69+
70+
Alternatively you can create extension properties in your iOS source-set yourself:
71+
```kotlin
72+
val TimeTravelViewModel.travelEffectValue: TravelEffect?
73+
get() = travelEffect.value
74+
```
75+
</p>
76+
</details>
77+
5478
## Android
5579

5680
Add the library to your Android module:

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ buildscript {
88

99
allprojects {
1010
group = "com.rickclephas.kmm"
11-
version = "1.0.0-ALPHA-2"
11+
version = "1.0.0-ALPHA-2-kotlin-1.8.0-RC2"
1212

1313
repositories {
1414
mavenCentral()

gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
kotlin.code.style=official
2+
kotlin.mpp.androidSourceSetLayoutVersion=2
23
kotlin.mpp.enableCInteropCommonization=true
34
kotlin.native.binary.memoryModel=experimental
45
android.useAndroidX=true

gradle/libs.versions.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
[versions]
2-
kotlin = "1.7.21"
2+
kotlin = "1.8.0"
33
kotlinx-coroutines = "1.6.4"
44
android = "7.3.1"
55
androidx-lifecycle = "2.5.1"
66

77
# Sample versions
88
androidx-compose = "2022.11.00"
99
androidx-fragment = "1.5.4"
10+
ksp = "1.8.0-RC2-1.0.8"
11+
nativecoroutines = "1.0.0-ALPHA-3"
1012

1113
[libraries]
1214
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }
@@ -30,3 +32,5 @@ android-library = { id = "com.android.library", version.ref = "android" }
3032
# Sample plugins
3133
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
3234
android-application = { id = "com.android.application", version.ref = "android" }
35+
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
36+
nativecoroutines = { id = "com.rickclephas.kmp.nativecoroutines", version.ref = "nativecoroutines" }

sample/androidApp/build.gradle.kts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ android {
1919
compose = true
2020
}
2121
composeOptions {
22-
kotlinCompilerExtensionVersion = "1.4.0-alpha02"
22+
kotlinCompilerExtensionVersion = "1.4.0-dev-k1.8.0-RC-4c1865595ed"
2323
}
2424
packagingOptions {
2525
resources {
@@ -33,6 +33,13 @@ android {
3333
}
3434
}
3535

36+
// Ignore Compose Kotlin version compatibility check
37+
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile::class.java).configureEach {
38+
kotlinOptions {
39+
freeCompilerArgs += listOf("-P", "plugin:androidx.compose.compiler.plugins.kotlin:suppressKotlinVersionCompatibilityCheck=true")
40+
}
41+
}
42+
3643
dependencies {
3744
implementation(project(":shared"))
3845
implementation(platform(libs.androidx.compose.bom))

sample/build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ allprojects {
1010
repositories {
1111
mavenCentral()
1212
google()
13+
maven("https://androidx.dev/storage/compose-compiler/repository/")
1314
}
14-
}
15+
}

sample/gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ android.useAndroidX=true
99
android.nonTransitiveRClass=true
1010

1111
#MPP
12+
kotlin.mpp.androidSourceSetLayoutVersion=2
1213
kotlin.mpp.enableCInteropCommonization=true
1314
kotlin.native.binary.memoryModel=experimental

sample/iosApp/KMMViewModelSample/ContentView.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ struct ContentView: View {
1313
@StateViewModel var viewModel = TimeTravelViewModel()
1414

1515
private var isFixedTimeBinding: Binding<Bool> {
16-
Binding { viewModel.isFixedTimeValue } set: { isFixedTime in
16+
Binding { viewModel.isFixedTime } set: { isFixedTime in
1717
if isFixedTime {
1818
viewModel.stopTime()
1919
} else {
@@ -27,19 +27,19 @@ struct ContentView: View {
2727
Spacer()
2828
Group {
2929
Text("Actual time:")
30-
Text(viewModel.actualTimeValue)
30+
Text(viewModel.actualTime)
3131
.font(.system(size: 20))
3232
}
3333
Group {
3434
Spacer().frame(height: 24)
3535
Text("Travel effect:")
36-
Text(viewModel.travelEffectValue?.description ?? "nil")
36+
Text(viewModel.travelEffect?.description ?? "nil")
3737
.font(.system(size: 20))
3838
}
3939
Group {
4040
Spacer().frame(height: 24)
4141
Text("Current time:")
42-
Text(viewModel.currentTimeValue)
42+
Text(viewModel.currentTime)
4343
.font(.system(size: 20))
4444
}
4545
Group {

sample/settings.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ dependencyResolutionManagement {
1010
repositories {
1111
google()
1212
mavenCentral()
13+
maven("https://androidx.dev/storage/compose-compiler/repository/")
1314
}
1415
}
1516

0 commit comments

Comments
 (0)