Skip to content

Commit

Permalink
Merge pull request #202 from icerockdev/develop
Browse files Browse the repository at this point in the history
Release 0.14.0
  • Loading branch information
anton6tak committed Sep 13, 2022
2 parents cae693d + 8bca036 commit 1e9d4bc
Show file tree
Hide file tree
Showing 14 changed files with 366 additions and 19 deletions.
37 changes: 19 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,22 @@ allprojects {
project build.gradle
```groovy
dependencies {
commonMainApi("dev.icerock.moko:mvvm-core:0.13.1") // only ViewModel, EventsDispatcher, Dispatchers.UI
commonMainApi("dev.icerock.moko:mvvm-flow:0.13.1") // api mvvm-core, CFlow for native and binding extensions
commonMainApi("dev.icerock.moko:mvvm-livedata:0.13.1") // api mvvm-core, LiveData and extensions
commonMainApi("dev.icerock.moko:mvvm-state:0.13.1") // api mvvm-livedata, ResourceState class and extensions
commonMainApi("dev.icerock.moko:mvvm-livedata-resources:0.13.1") // api mvvm-core, moko-resources, extensions for LiveData with moko-resources
commonMainApi("dev.icerock.moko:mvvm-core:0.14.0") // only ViewModel, EventsDispatcher, Dispatchers.UI
commonMainApi("dev.icerock.moko:mvvm-flow:0.14.0") // api mvvm-core, CFlow for native and binding extensions
commonMainApi("dev.icerock.moko:mvvm-livedata:0.14.0") // api mvvm-core, LiveData and extensions
commonMainApi("dev.icerock.moko:mvvm-state:0.14.0") // api mvvm-livedata, ResourceState class and extensions
commonMainApi("dev.icerock.moko:mvvm-livedata-resources:0.14.0") // api mvvm-core, moko-resources, extensions for LiveData with moko-resources
commonMainApi("dev.icerock.moko:mvvm-flow-resources:0.14.0") // api mvvm-core, moko-resources, extensions for Flow with moko-resources
androidMainApi("dev.icerock.moko:mvvm-flow-compose:0.13.1") // api mvvm-flow, binding extensions for Jetpack Compose (jvm, js, android)
androidMainApi("dev.icerock.moko:mvvm-livedata-compose:0.13.1") // api mvvm-livedata, binding extensions for Jetpack Compose (jvm, js, android)
androidMainApi("dev.icerock.moko:mvvm-livedata-material:0.13.1") // api mvvm-livedata, Material library android extensions
androidMainApi("dev.icerock.moko:mvvm-livedata-glide:0.13.1") // api mvvm-livedata, Glide library android extensions
androidMainApi("dev.icerock.moko:mvvm-livedata-swiperefresh:0.13.1") // api mvvm-livedata, SwipeRefreshLayout library android extensions
androidMainApi("dev.icerock.moko:mvvm-databinding:0.13.1") // api mvvm-livedata, DataBinding support for Android
androidMainApi("dev.icerock.moko:mvvm-viewbinding:0.13.1") // api mvvm-livedata, ViewBinding support for Android
androidMainApi("dev.icerock.moko:mvvm-flow-compose:0.14.0") // api mvvm-flow, binding extensions for Jetpack Compose (jvm, js, android)
androidMainApi("dev.icerock.moko:mvvm-livedata-compose:0.14.0") // api mvvm-livedata, binding extensions for Jetpack Compose (jvm, js, android)
androidMainApi("dev.icerock.moko:mvvm-livedata-material:0.14.0") // api mvvm-livedata, Material library android extensions
androidMainApi("dev.icerock.moko:mvvm-livedata-glide:0.14.0") // api mvvm-livedata, Glide library android extensions
androidMainApi("dev.icerock.moko:mvvm-livedata-swiperefresh:0.14.0") // api mvvm-livedata, SwipeRefreshLayout library android extensions
androidMainApi("dev.icerock.moko:mvvm-databinding:0.14.0") // api mvvm-livedata, DataBinding support for Android
androidMainApi("dev.icerock.moko:mvvm-viewbinding:0.14.0") // api mvvm-livedata, ViewBinding support for Android
commonTestImplementation("dev.icerock.moko:mvvm-test:0.13.1") // test utilities
commonTestImplementation("dev.icerock.moko:mvvm-test:0.14.0") // test utilities
}
```

Expand All @@ -74,10 +75,10 @@ kotlin {
// export correct artifact to use all classes of library directly from Swift
targets.withType(org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget::class.java).all {
binaries.withType(org.jetbrains.kotlin.gradle.plugin.mpp.Framework::class.java).all {
export("dev.icerock.moko:mvvm-core:0.13.1")
export("dev.icerock.moko:mvvm-livedata:0.13.1")
export("dev.icerock.moko:mvvm-livedata-resources:0.13.1")
export("dev.icerock.moko:mvvm-state:0.13.1")
export("dev.icerock.moko:mvvm-core:0.14.0")
export("dev.icerock.moko:mvvm-livedata:0.14.0")
export("dev.icerock.moko:mvvm-livedata-resources:0.14.0")
export("dev.icerock.moko:mvvm-state:0.14.0")
}
}
}
Expand All @@ -93,7 +94,7 @@ generation enabled. All `LiveData` to `UIView` bindings is extensions for UI ele
To use MOKO MVVM with SwiftUI set name of your kotlin framework to `MultiPlatformLibrary` and add
dependency to CocoaPods:
```ruby
pod 'mokoMvvmFlowSwiftUI', :podspec => 'https://raw.githubusercontent.com/icerockdev/moko-mvvm/release/0.13.1/mokoMvvmFlowSwiftUI.podspec'
pod 'mokoMvvmFlowSwiftUI', :podspec => 'https://raw.githubusercontent.com/icerockdev/moko-mvvm/release/0.14.0/mokoMvvmFlowSwiftUI.podspec'
```
required export of `mvvm-core` and `mvvm-flow`.

Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ androidLifecycleVersion = "2.2.0"
coroutinesVersion = "1.6.0-native-mt"
mokoResourcesVersion = "0.18.0"
mokoTestVersion = "0.6.1"
mokoMvvmVersion = "0.13.1"
mokoMvvmVersion = "0.14.0"
mokoKSwiftVersion = "0.4.0"
composeVersion = "1.1.1"
composeJetBrainsVersion = "1.1.1"
Expand Down
14 changes: 14 additions & 0 deletions mvvm-flow-resources/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright 2022 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license.
*/

plugins {
id("kmm-library-convention")
id("detekt-convention")
id("publication-convention")
}

dependencies {
commonMainApi(projects.mvvmFlow)
commonMainApi(libs.mokoResources)
}
2 changes: 2 additions & 0 deletions mvvm-flow-resources/src/androidMain/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="dev.icerock.moko.mvvm.flow.resources" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright 2022 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license.
*/

package dev.icerock.moko.mvvm.flow.resources

import android.widget.TextView
import androidx.lifecycle.LifecycleOwner
import dev.icerock.moko.mvvm.flow.CStateFlow
import dev.icerock.moko.mvvm.flow.binding.bind
import dev.icerock.moko.resources.desc.StringDesc
import kotlinx.coroutines.DisposableHandle

fun <T : StringDesc?> TextView.bindText(
lifecycleOwner: LifecycleOwner,
flow: CStateFlow<T>
): DisposableHandle {
return flow.bind(lifecycleOwner) { this.text = it?.toString(this.context) }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright 2022 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license.
*/

package dev.icerock.moko.mvvm.flow.resources

import dev.icerock.moko.mvvm.flow.CStateFlow
import dev.icerock.moko.mvvm.flow.DisposableHandle
import dev.icerock.moko.mvvm.flow.binding.bind
import dev.icerock.moko.resources.desc.StringDesc
import platform.UIKit.UIButton
import platform.UIKit.UIControlStateNormal

fun <T : StringDesc?> UIButton.bindTitle(
flow: CStateFlow<T>
): DisposableHandle {
return bind(flow) {
this.setTitle(
it?.localized(),
forState = UIControlStateNormal
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright 2022 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license.
*/

package dev.icerock.moko.mvvm.flow.resources

import dev.icerock.moko.mvvm.flow.CStateFlow
import dev.icerock.moko.mvvm.flow.DisposableHandle
import dev.icerock.moko.mvvm.flow.binding.bind
import dev.icerock.moko.resources.desc.StringDesc
import platform.UIKit.UILabel

fun <T : StringDesc?> UILabel.bindText(
flow: CStateFlow<T>
): DisposableHandle {
return bind(flow) { this.text = it?.localized() }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright 2022 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license.
*/

package dev.icerock.moko.mvvm.flow.resources

import dev.icerock.moko.mvvm.flow.CStateFlow
import dev.icerock.moko.mvvm.flow.DisposableHandle
import dev.icerock.moko.mvvm.flow.binding.bind
import dev.icerock.moko.resources.desc.StringDesc
import platform.UIKit.UITextField

fun <T : StringDesc?> UITextField.bindText(
flow: CStateFlow<T>
): DisposableHandle {
return bind(flow) { value ->
val newValue = value?.localized().orEmpty()
if (this.text == newValue) return@bind
this.text = newValue
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright 2022 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license.
*/

package dev.icerock.moko.mvvm.flow.resources

import dev.icerock.moko.mvvm.flow.CStateFlow
import dev.icerock.moko.mvvm.flow.DisposableHandle
import dev.icerock.moko.mvvm.flow.binding.bind
import dev.icerock.moko.resources.desc.StringDesc
import platform.UIKit.UITextView

fun <T : StringDesc?> UITextView.bindText(
flow: CStateFlow<T>
): DisposableHandle {
return bind(flow) { value ->
val newValue = value?.localized().orEmpty()
if (this.text == newValue) return@bind
this.text = newValue
}
}
57 changes: 57 additions & 0 deletions mvvm-flow-resources/src/iosTest/kotlin/UIButtonBindingsTests.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright 2021 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license.
*/

import dev.icerock.moko.mvvm.flow.cStateFlow
import dev.icerock.moko.mvvm.flow.resources.bindTitle
import dev.icerock.moko.resources.desc.StringDesc
import dev.icerock.moko.resources.desc.desc
import kotlinx.cinterop.readValue
import kotlinx.coroutines.flow.MutableStateFlow
import platform.CoreGraphics.CGRectZero
import platform.UIKit.UIButton
import kotlin.test.BeforeTest
import kotlin.test.Ignore
import kotlin.test.Test
import kotlin.test.assertEquals

@Ignore
class UIButtonBindingsTests {

private lateinit var destination: UIButton

@BeforeTest
fun setup() {
destination = UIButton(frame = CGRectZero.readValue())
}

@Test
fun `nonnullable stringdesc title`() {
val source: MutableStateFlow<StringDesc> = MutableStateFlow("init".desc())
destination.bindTitle(source.cStateFlow())
assertEquals(
expected = "init",
actual = destination.currentTitle
)
source.value = "second".desc()
assertEquals(
expected = "second",
actual = destination.currentTitle
)
}

@Test
fun `nullable stringdesc title`() {
val source: MutableStateFlow<StringDesc?> = MutableStateFlow(null)
destination.bindTitle(source.cStateFlow())
assertEquals(
expected = null,
actual = destination.currentTitle
)
source.value = "value".desc()
assertEquals(
expected = "value",
actual = destination.currentTitle
)
}
}
57 changes: 57 additions & 0 deletions mvvm-flow-resources/src/iosTest/kotlin/UILabelBindingsTests.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright 2021 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license.
*/

import dev.icerock.moko.mvvm.flow.cStateFlow
import dev.icerock.moko.mvvm.flow.resources.bindText
import dev.icerock.moko.resources.desc.StringDesc
import dev.icerock.moko.resources.desc.desc
import kotlinx.cinterop.readValue
import kotlinx.coroutines.flow.MutableStateFlow
import platform.CoreGraphics.CGRectZero
import platform.UIKit.UILabel
import kotlin.test.BeforeTest
import kotlin.test.Ignore
import kotlin.test.Test
import kotlin.test.assertEquals

@Ignore
class UILabelBindingsTests {

private lateinit var destination: UILabel

@BeforeTest
fun setup() {
destination = UILabel(frame = CGRectZero.readValue())
}

@Test
fun `nonnullable stringdesc text`() {
val source: MutableStateFlow<StringDesc> = MutableStateFlow("init".desc())
destination.bindText(source.cStateFlow())
assertEquals(
expected = "init",
actual = destination.text
)
source.value = "second".desc()
assertEquals(
expected = "second",
actual = destination.text
)
}

@Test
fun `nullable stringdesc text`() {
val source: MutableStateFlow<StringDesc?> = MutableStateFlow(null)
destination.bindText(source.cStateFlow())
assertEquals(
expected = null,
actual = destination.text
)
source.value = "value".desc()
assertEquals(
expected = "value",
actual = destination.text
)
}
}
57 changes: 57 additions & 0 deletions mvvm-flow-resources/src/iosTest/kotlin/UITextFieldBindingsTests.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright 2021 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license.
*/

import dev.icerock.moko.mvvm.flow.cStateFlow
import dev.icerock.moko.mvvm.flow.resources.bindText
import dev.icerock.moko.resources.desc.StringDesc
import dev.icerock.moko.resources.desc.desc
import kotlinx.cinterop.readValue
import kotlinx.coroutines.flow.MutableStateFlow
import platform.CoreGraphics.CGRectZero
import platform.UIKit.UITextField
import kotlin.test.BeforeTest
import kotlin.test.Ignore
import kotlin.test.Test
import kotlin.test.assertEquals

@Ignore
class UITextFieldBindingsTests {

private lateinit var destination: UITextField

@BeforeTest
fun setup() {
destination = UITextField(frame = CGRectZero.readValue())
}

@Test
fun `nonnullable stringdesc text`() {
val source: MutableStateFlow<StringDesc> = MutableStateFlow("init".desc())
destination.bindText(source.cStateFlow())
assertEquals(
expected = "init",
actual = destination.text
)
source.value = "second".desc()
assertEquals(
expected = "second",
actual = destination.text
)
}

@Test
fun `nullable stringdesc text`() {
val source: MutableStateFlow<StringDesc?> = MutableStateFlow(null)
destination.bindText(source.cStateFlow())
assertEquals(
expected = "",
actual = destination.text
)
source.value = "value".desc()
assertEquals(
expected = "value",
actual = destination.text
)
}
}
Loading

0 comments on commit 1e9d4bc

Please sign in to comment.