Skip to content

Commit 7a1c289

Browse files
authored
Merge pull request #176 from icerockdev/develop
Release 0.13.0
2 parents b4b2ed1 + 7e0623e commit 7a1c289

File tree

118 files changed

+5947
-23
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+5947
-23
lines changed

README.md

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,18 @@ allprojects {
4040
project build.gradle
4141
```groovy
4242
dependencies {
43-
commonMainApi("dev.icerock.moko:mvvm-core:0.12.0") // only ViewModel, EventsDispatcher, Dispatchers.UI
44-
commonMainApi("dev.icerock.moko:mvvm-livedata:0.12.0") // api mvvm-core, LiveData and extensions
45-
commonMainApi("dev.icerock.moko:mvvm-state:0.12.0") // api mvvm-livedata, ResourceState class and extensions
46-
commonMainApi("dev.icerock.moko:mvvm-livedata-resources:0.12.0") // api mvvm-core, moko-resources, extensions for LiveData with moko-resources
43+
commonMainApi("dev.icerock.moko:mvvm-core:0.13.0") // only ViewModel, EventsDispatcher, Dispatchers.UI
44+
commonMainApi("dev.icerock.moko:mvvm-livedata:0.13.0") // api mvvm-core, LiveData and extensions
45+
commonMainApi("dev.icerock.moko:mvvm-state:0.13.0") // api mvvm-livedata, ResourceState class and extensions
46+
commonMainApi("dev.icerock.moko:mvvm-livedata-resources:0.13.0") // api mvvm-core, moko-resources, extensions for LiveData with moko-resources
4747
48-
androidMainApi("dev.icerock.moko:mvvm-livedata-material:0.12.0") // api mvvm-livedata, Material library android extensions
49-
androidMainApi("dev.icerock.moko:mvvm-livedata-glide:0.12.0") // api mvvm-livedata, Glide library android extensions
50-
androidMainApi("dev.icerock.moko:mvvm-livedata-swiperefresh:0.12.0") // api mvvm-livedata, SwipeRefreshLayout library android extensions
51-
androidMainApi("dev.icerock.moko:mvvm-databinding:0.12.0") // api mvvm-livedata, DataBinding support for Android
52-
androidMainApi("dev.icerock.moko:mvvm-viewbinding:0.12.0") // api mvvm-livedata, ViewBinding support for Android
48+
androidMainApi("dev.icerock.moko:mvvm-livedata-material:0.13.0") // api mvvm-livedata, Material library android extensions
49+
androidMainApi("dev.icerock.moko:mvvm-livedata-glide:0.13.0") // api mvvm-livedata, Glide library android extensions
50+
androidMainApi("dev.icerock.moko:mvvm-livedata-swiperefresh:0.13.0") // api mvvm-livedata, SwipeRefreshLayout library android extensions
51+
androidMainApi("dev.icerock.moko:mvvm-databinding:0.13.0") // api mvvm-livedata, DataBinding support for Android
52+
androidMainApi("dev.icerock.moko:mvvm-viewbinding:0.13.0") // api mvvm-livedata, ViewBinding support for Android
5353
54-
commonTestImplementation("dev.icerock.moko:mvvm-test:0.12.0") // test utilities
54+
commonTestImplementation("dev.icerock.moko:mvvm-test:0.13.0") // test utilities
5555
}
5656
```
5757

@@ -61,10 +61,10 @@ kotlin {
6161
// export correct artifact to use all classes of library directly from Swift
6262
targets.withType(org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget::class.java).all {
6363
binaries.withType(org.jetbrains.kotlin.gradle.plugin.mpp.Framework::class.java).all {
64-
export("dev.icerock.moko:mvvm-core:0.12.0")
65-
export("dev.icerock.moko:mvvm-livedata:0.12.0")
66-
export("dev.icerock.moko:mvvm-livedata-resources:0.12.0")
67-
export("dev.icerock.moko:mvvm-state:0.12.0")
64+
export("dev.icerock.moko:mvvm-core:0.13.0")
65+
export("dev.icerock.moko:mvvm-livedata:0.13.0")
66+
export("dev.icerock.moko:mvvm-livedata-resources:0.13.0")
67+
export("dev.icerock.moko:mvvm-state:0.13.0")
6868
}
6969
}
7070
}
@@ -75,6 +75,14 @@ kotlin {
7575
For iOS we recommend use [moko-kswift](https://github.com/icerockdev/moko-kswift) with extensions
7676
generation enabled. All `LiveData` to `UIView` bindings is extensions for UI elements.
7777

78+
### SwiftUI additions
79+
80+
To use MOKO MVVM with SwiftUI set name of your kotlin framework to `MultiPlatformLibrary` and add
81+
dependency to CocoaPods:
82+
```ruby
83+
pod 'mokoMvvmFlowSwiftUI', :podspec => 'https://raw.githubusercontent.com/icerockdev/moko-mvvm/release/0.13.0/mokoMvvmFlowSwiftUI.podspec'
84+
```
85+
7886
## Documentation
7987
Documentation generated by Dokka and available at https://icerockdev.github.io/moko-mvvm/
8088

@@ -498,7 +506,8 @@ Please see more examples in the [sample directory](sample).
498506
- The [mvvm-databinding directory](mvvm-databinding) contains DataBinding support code for Android;
499507
- The [mvvm-viewbinding directory](mvvm-viewbinding) contains ViewBinding support code for Android;
500508
- The [mvvm-test directory](mvvm-test) contains the test utilities;
501-
- In [sample directory](sample) contains sample apps for Android and iOS; plus the mpp-library connected to the apps.
509+
- In [sample directory](sample) contains sample apps for Android and iOS; plus the mpp-library connected to the apps;
510+
- In [sample-declarative-ui directory](sample-declarative-ui) contains sample apps with Jetpack Compose and SwiftUI.
502511

503512
## Contributing
504513
All development (both new features and bug fixes) is performed in the `develop` branch. This way `master` always contains the sources of the most recently released version. Please send PRs with bug fixes to the `develop` branch. Documentation fixes in the markdown files are an exception to this rule. They are updated directly in `master`.

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ buildscript {
1212
dependencies {
1313
classpath(":mvvm-build-logic")
1414
classpath(libs.kswiftGradlePlugin)
15+
classpath(libs.composeJetBrainsGradlePlugin)
1516
}
1617
}
1718

gradle/libs.versions.toml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,26 @@ androidLifecycleVersion = "2.2.0"
44
coroutinesVersion = "1.6.0-native-mt"
55
mokoResourcesVersion = "0.18.0"
66
mokoTestVersion = "0.6.1"
7-
mokoMvvmVersion = "0.12.0"
7+
mokoMvvmVersion = "0.13.0"
88
mokoKSwiftVersion = "0.4.0"
9+
composeVersion = "1.1.1"
10+
composeJetBrainsVersion = "1.1.1"
911

1012
[libraries]
1113
# android
1214
appCompat = { module = "androidx.appcompat:appcompat", version = "1.2.0" }
1315
material = { module = "com.google.android.material:material", version = "1.2.1" }
1416
lifecycle = { module = "androidx.lifecycle:lifecycle-extensions", version.ref = "androidLifecycleVersion" }
17+
lifecycleKtx = { module = "androidx.lifecycle:lifecycle-runtime-ktx", version.ref = "androidLifecycleVersion" }
1518
androidViewModel = { module = "androidx.lifecycle:lifecycle-viewmodel-ktx", version.ref = "androidLifecycleVersion" }
1619
androidLiveData = { module = "androidx.lifecycle:lifecycle-livedata-ktx", version.ref = "androidLifecycleVersion" }
1720
glide = { module = "com.github.bumptech.glide:glide", version = "4.11.0" }
1821
swipeRefresh = { module = "androidx.swiperefreshlayout:swiperefreshlayout", version = "1.1.0" }
1922

23+
# compose
24+
composeFoundation = { module = "androidx.compose.foundation:foundation", version.ref = "composeVersion" }
25+
composeLiveData = { module = "androidx.compose.runtime:runtime-livedata", version.ref = "composeVersion" }
26+
2027
# coroutines
2128
coroutines = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "coroutinesVersion" }
2229
coroutinesTest = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "coroutinesVersion" }
@@ -37,6 +44,7 @@ mobileMultiplatformGradlePlugin = { module = "dev.icerock:mobile-multiplatform",
3744
androidGradlePlugin = { module = "com.android.tools.build:gradle", version = "7.0.4" }
3845
detektGradlePlugin = { module = "io.gitlab.arturbosch.detekt:detekt-gradle-plugin", version = "1.19.0" }
3946
kswiftGradlePlugin = { module = "dev.icerock.moko:kswift-gradle-plugin", version.ref = "mokoKSwiftVersion" }
47+
composeJetBrainsGradlePlugin = { module = "org.jetbrains.compose:compose-gradle-plugin", version.ref = "composeJetBrainsVersion" }
4048

4149
[plugins]
4250
nexusPublish = { id = "io.github.gradle-nexus.publish-plugin", version = "1.1.0" }

mokoMvvmFlowSwiftUI.podspec

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Pod::Spec.new do |s|
2+
s.name = 'mokoMvvmFlowSwiftUI'
3+
s.version = '0.13.0'
4+
s.summary = 'MOKO MVVM SwiftUI additions for Flow'
5+
s.description = 'some description here'
6+
s.homepage = 'localhost'
7+
s.license = { :type => 'Apache 2' }
8+
s.authors = 'IceRock Development'
9+
s.source = {
10+
:http => "https://repo1.maven.org/maven2/dev/icerock/moko/mvvm-flow-swiftui/#{s.version}/mvvm-flow-swiftui-#{s.version}.zip",
11+
:type => "zip"
12+
}
13+
14+
s.platform = :ios
15+
s.ios.deployment_target = '13.0'
16+
s.ios.vendored_framework = 'mokoMvvmFlowSwiftUI.xcframework'
17+
18+
s.requires_arc = true
19+
end

mvvm-core/src/androidMain/kotlin/dev/icerock/moko/mvvm/ViewModelFactory.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ inline fun <reified T : ViewModel> ViewModelStoreOwner.getViewModel(
2424
ViewModelFactory { viewModelBlock() }
2525
).get(T::class.java)
2626

27-
inline fun <reified T : ViewModel> ViewModelStoreOwner.createViewModelFactory(
27+
inline fun <reified T : ViewModel> createViewModelFactory(
2828
noinline viewModelBlock: () -> T
2929
): ViewModelFactory = ViewModelFactory {
3030
viewModelBlock()

mvvm-flow-compose/build.gradle.kts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2022 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
plugins {
6+
id("org.jetbrains.kotlin.multiplatform")
7+
id("detekt-convention")
8+
id("org.jetbrains.compose")
9+
id("javadoc-stub-convention")
10+
id("publication-convention")
11+
}
12+
13+
java {
14+
toolchain {
15+
languageVersion.set(JavaLanguageVersion.of(11))
16+
}
17+
}
18+
19+
kotlin {
20+
jvm()
21+
js(IR) {
22+
browser()
23+
}
24+
25+
sourceSets {
26+
commonMain {
27+
dependencies {
28+
api(projects.mvvmFlow)
29+
30+
api(compose.runtime)
31+
}
32+
}
33+
}
34+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright 2022 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
package dev.icerock.moko.mvvm.flow.compose
6+
7+
import androidx.compose.runtime.Composable
8+
import androidx.compose.runtime.LaunchedEffect
9+
import kotlinx.coroutines.flow.Flow
10+
import kotlinx.coroutines.flow.collect
11+
import kotlinx.coroutines.flow.onEach
12+
13+
@Composable
14+
fun <T> Flow<T>.observeAsActions(onEach: (T) -> Unit) {
15+
val flow = this
16+
LaunchedEffect(key1 = flow) {
17+
flow.onEach(onEach).collect()
18+
}
19+
}

mvvm-flow/apple/build.gradle.kts

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import org.jetbrains.kotlin.gradle.plugin.mpp.apple.XCFramework
2+
import org.jetbrains.kotlin.konan.target.HostManager
3+
4+
plugins {
5+
id("detekt-convention")
6+
id("org.jetbrains.kotlin.multiplatform")
7+
id("dev.icerock.mobile.multiplatform.apple-framework")
8+
id("publication-convention")
9+
}
10+
11+
kotlin {
12+
iosArm64()
13+
iosX64()
14+
iosSimulatorArm64()
15+
macosX64()
16+
17+
val xcf = XCFramework("MultiPlatformLibrary")
18+
targets.withType<org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget>()
19+
.configureEach {
20+
binaries.withType<org.jetbrains.kotlin.gradle.plugin.mpp.Framework>().configureEach {
21+
xcf.add(this)
22+
}
23+
}
24+
}
25+
26+
dependencies {
27+
commonMainImplementation(libs.coroutines)
28+
29+
commonMainApi(libs.mokoResources)
30+
commonMainApi(projects.mvvmFlow)
31+
commonMainApi(projects.mvvmCore)
32+
}
33+
34+
framework {
35+
export(projects.mvvmCore)
36+
export(projects.mvvmFlow)
37+
export(libs.mokoResources)
38+
}
39+
40+
val swiftXCFrameworkProject = File(projectDir, "xcode/mokoMvvmFlow.xcodeproj")
41+
val swiftXCFrameworkOutput = File(projectDir, "xcode/xcframework")
42+
val swiftXCFramework = File(swiftXCFrameworkOutput, "mokoMvvmFlowSwiftUI.xcframework")
43+
val swiftXCFrameworkArchive = File(swiftXCFrameworkOutput, "mokoMvvmFlowSwiftUI.xcframework.zip")
44+
45+
val compileTask = tasks.create("compileMokoFlowSwiftUIXCFramework", Exec::class) {
46+
group = "xcode"
47+
48+
commandLine = listOf(
49+
"xcodebuild",
50+
"-scheme",
51+
"mokoMvvmFlowSwiftUI",
52+
"-project",
53+
swiftXCFrameworkProject.absolutePath,
54+
"build"
55+
)
56+
57+
dependsOn("assembleMultiPlatformLibraryDebugXCFramework")
58+
59+
onlyIf { HostManager.hostIsMac }
60+
}
61+
62+
val archiveTask = tasks.create("archiveMokoFlowSwiftUIXCFramework", Zip::class) {
63+
group = "xcode"
64+
65+
from(swiftXCFramework)
66+
into(swiftXCFramework.name)
67+
68+
archiveFileName.set(swiftXCFrameworkArchive.name)
69+
destinationDirectory.set(swiftXCFrameworkOutput)
70+
71+
dependsOn(compileTask)
72+
73+
onlyIf { HostManager.hostIsMac }
74+
}
75+
76+
val publicationName = "swiftuiAdditions"
77+
78+
publishing {
79+
publications {
80+
create<MavenPublication>(publicationName) {
81+
artifactId = "mvvm-flow-swiftui"
82+
83+
artifact(archiveTask.archiveFile) {
84+
extension = "zip"
85+
}
86+
87+
pom {
88+
packaging = "zip"
89+
}
90+
}
91+
}
92+
}
93+
94+
tasks.withType<AbstractPublishToMaven>()
95+
.configureEach {
96+
if (publication.name != publicationName) enabled = false
97+
else onlyIf { HostManager.hostIsMac }
98+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/*
2+
* Copyright 2022 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
package dev.icerock.moko.mvvm.flow.apple
6+
7+
// just for compile this module
8+
fun helloWorld() = println("hello world")

mvvm-flow/apple/xcode/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
xcframework/

0 commit comments

Comments
 (0)