Skip to content

Commit

Permalink
Merge pull request #219 from icerockdev/develop
Browse files Browse the repository at this point in the history
Release 0.15.0
  • Loading branch information
Alex009 committed Dec 19, 2022
2 parents 1e9d4bc + 05eff95 commit 4ab6dee
Show file tree
Hide file tree
Showing 24 changed files with 275 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/compilation-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ macos-latest, windows-latest, ubuntu-latest ]
os: [ macos-11, windows-latest, ubuntu-latest ]
steps:
- uses: actions/checkout@v1
- name: Set up JDK 11
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ macos-latest, windows-latest, ubuntu-latest ]
os: [ macos-11, windows-latest, ubuntu-latest ]
env:
OSSRH_USER: ${{ secrets.OSSRH_USER }}
OSSRH_KEY: ${{ secrets.OSSRH_KEY }}
Expand Down
38 changes: 19 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,22 @@ allprojects {
project build.gradle
```groovy
dependencies {
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
commonMainApi("dev.icerock.moko:mvvm-core:0.15.0") // only ViewModel, EventsDispatcher, Dispatchers.UI
commonMainApi("dev.icerock.moko:mvvm-flow:0.15.0") // api mvvm-core, CFlow for native and binding extensions
commonMainApi("dev.icerock.moko:mvvm-livedata:0.15.0") // api mvvm-core, LiveData and extensions
commonMainApi("dev.icerock.moko:mvvm-state:0.15.0") // api mvvm-livedata, ResourceState class and extensions
commonMainApi("dev.icerock.moko:mvvm-livedata-resources:0.15.0") // api mvvm-core, moko-resources, extensions for LiveData with moko-resources
commonMainApi("dev.icerock.moko:mvvm-flow-resources:0.15.0") // api mvvm-core, moko-resources, extensions for Flow with moko-resources
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
androidMainApi("dev.icerock.moko:mvvm-flow-compose:0.15.0") // api mvvm-flow, binding extensions for Jetpack Compose (jvm, js, android)
androidMainApi("dev.icerock.moko:mvvm-livedata-compose:0.15.0") // api mvvm-livedata, binding extensions for Jetpack Compose (jvm, js, android)
androidMainApi("dev.icerock.moko:mvvm-livedata-material:0.15.0") // api mvvm-livedata, Material library android extensions
androidMainApi("dev.icerock.moko:mvvm-livedata-glide:0.15.0") // api mvvm-livedata, Glide library android extensions
androidMainApi("dev.icerock.moko:mvvm-livedata-swiperefresh:0.15.0") // api mvvm-livedata, SwipeRefreshLayout library android extensions
androidMainApi("dev.icerock.moko:mvvm-databinding:0.15.0") // api mvvm-livedata, DataBinding support for Android
androidMainApi("dev.icerock.moko:mvvm-viewbinding:0.15.0") // api mvvm-livedata, ViewBinding support for Android
commonTestImplementation("dev.icerock.moko:mvvm-test:0.14.0") // test utilities
commonTestImplementation("dev.icerock.moko:mvvm-test:0.15.0") // test utilities
}
```

Expand All @@ -75,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.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")
export("dev.icerock.moko:mvvm-core:0.15.0")
export("dev.icerock.moko:mvvm-livedata:0.15.0")
export("dev.icerock.moko:mvvm-livedata-resources:0.15.0")
export("dev.icerock.moko:mvvm-state:0.15.0")
}
}
}
Expand All @@ -94,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.14.0/mokoMvvmFlowSwiftUI.podspec'
pod 'mokoMvvmFlowSwiftUI', :podspec => 'https://raw.githubusercontent.com/icerockdev/moko-mvvm/release/0.15.0/mokoMvvmFlowSwiftUI.podspec'
```
required export of `mvvm-core` and `mvvm-flow`.

Expand Down
4 changes: 2 additions & 2 deletions 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.14.0"
mokoMvvmVersion = "0.15.0"
mokoKSwiftVersion = "0.4.0"
composeVersion = "1.1.1"
composeJetBrainsVersion = "1.1.1"
Expand Down Expand Up @@ -41,7 +41,7 @@ androidCoreTesting = { module = "androidx.arch.core:core-testing", version = "2.
dokkaGradlePlugin = { module = "org.jetbrains.dokka:dokka-gradle-plugin", version.ref = "kotlinVersion" }
kotlinGradlePlugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlinVersion" }
mobileMultiplatformGradlePlugin = { module = "dev.icerock:mobile-multiplatform", version = "0.13.0" }
androidGradlePlugin = { module = "com.android.tools.build:gradle", version = "7.0.4" }
androidGradlePlugin = { module = "com.android.tools.build:gradle", version = "7.2.2" }
detektGradlePlugin = { module = "io.gitlab.arturbosch.detekt:detekt-gradle-plugin", version = "1.19.0" }
kswiftGradlePlugin = { module = "dev.icerock.moko:kswift-gradle-plugin", version.ref = "mokoKSwiftVersion" }
composeJetBrainsGradlePlugin = { module = "org.jetbrains.compose:compose-gradle-plugin", version.ref = "composeJetBrainsVersion" }
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 1 addition & 1 deletion mokoMvvmFlowSwiftUI.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'mokoMvvmFlowSwiftUI'
s.version = '0.13.0'
s.version = '0.15.0'
s.summary = 'MOKO MVVM SwiftUI additions for Flow'
s.description = 'some description here'
s.homepage = 'localhost'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import com.android.build.gradle.BaseExtension

configure<BaseExtension> {
compileSdkVersion(30)
compileSdkVersion(33)

defaultConfig {
minSdkVersion(16)
targetSdkVersion(30)
minSdk = 16
targetSdk = 33
}
}
2 changes: 1 addition & 1 deletion mvvm-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ dependencies {

commonMainApi(libs.coroutines)

androidMainApi(libs.appCompat)
androidMainApi(libs.lifecycleKtx)
androidMainApi(libs.androidViewModel)
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import kotlinx.coroutines.cancel

@Suppress("EmptyDefaultConstructor")
actual open class ViewModel actual constructor() : ViewModel() {
protected actual val viewModelScope: CoroutineScope = createViewModelScope()
actual val viewModelScope: CoroutineScope = createViewModelScope()

public actual override fun onCleared() {
super.onCleared()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import kotlinx.coroutines.CoroutineScope

@Suppress("EmptyDefaultConstructor")
expect open class ViewModel() {
protected val viewModelScope: CoroutineScope
val viewModelScope: CoroutineScope

open fun onCleared()
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import kotlinx.coroutines.cancel

@Suppress("EmptyDefaultConstructor")
actual open class ViewModel actual constructor() {
protected actual val viewModelScope: CoroutineScope = createViewModelScope()
actual val viewModelScope: CoroutineScope = createViewModelScope()

actual open fun onCleared() {
viewModelScope.cancel()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2022 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license.
*/

package dev.icerock.moko.mvvm.flow.compose

import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.State
import androidx.compose.runtime.collectAsState
import kotlinx.coroutines.flow.MutableStateFlow
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.EmptyCoroutineContext

class MutableStateAdapter<T>(
private val state: State<T>,
private val mutate: (T) -> Unit
) : MutableState<T> {

override var value: T
get() = state.value
set(value) {
mutate(value)
}

override fun component1(): T = value
override fun component2(): (T) -> Unit = { value = it }
}

@Composable
fun <T> MutableStateFlow<T>.collectAsMutableState(
context: CoroutineContext = EmptyCoroutineContext
): MutableState<T> = MutableStateAdapter(
state = collectAsState(context),
mutate = { value = it }
)
15 changes: 15 additions & 0 deletions mvvm-flow-material/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright 2019 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license.
*/

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

dependencies {
api(projects.mvvmFlowResources)

api(libs.material)
}
2 changes: 2 additions & 0 deletions mvvm-flow-material/src/main/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.material" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2021 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license.
*/

package dev.icerock.moko.mvvm.flow.material

import androidx.lifecycle.LifecycleOwner
import com.google.android.material.textfield.TextInputLayout
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

@JvmName("bindErrorString")
fun <T : String?> TextInputLayout.bindError(
lifecycleOwner: LifecycleOwner,
flow: CStateFlow<T?>
): DisposableHandle {
return flow.bind(lifecycleOwner) {
error = it
isErrorEnabled = it != null
}
}

@JvmName("bindErrorStringDesc")
fun <T : StringDesc?> TextInputLayout.bindError(
lifecycleOwner: LifecycleOwner,
flow: CStateFlow<T?>
): DisposableHandle {
return flow.bind(lifecycleOwner) {
error = it?.toString(context)
isErrorEnabled = it != null
}
}
8 changes: 8 additions & 0 deletions mvvm-flow/apple/xcode/mokoMvvmFlow.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
22D5AD53281BD2F700008F57 /* mokoMvvmFlow.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = mokoMvvmFlow.app; sourceTree = BUILT_PRODUCTS_DIR; };
22D5AD59281BD2F700008F57 /* mokoMvvmFlow.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = mokoMvvmFlow.app; sourceTree = BUILT_PRODUCTS_DIR; };
22D5AD5B281BD2F700008F57 /* macOS.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = macOS.entitlements; sourceTree = "<group>"; };
455E6FFE28DF859B001DAA93 /* ViewModelStateNullable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewModelStateNullable.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -158,6 +159,7 @@
22BDE701281BD34C00259368 /* mokoMvvmFlowSwiftUI */ = {
isa = PBXGroup;
children = (
455E6FFE28DF859B001DAA93 /* ViewModelStateNullable.swift */,
22BDE702281BD34C00259368 /* mokoMvvmFlowSwiftUI.h */,
22BDE739281BD56700259368 /* CFlowExt.swift */,
22BDE73C281BD67C00259368 /* ViewModelObservable.swift */,
Expand Down Expand Up @@ -494,6 +496,7 @@
"@loader_path/Frameworks",
);
MARKETING_VERSION = 1.0;
OTHER_SWIFT_FLAGS = "-verify-emitted-module-interface";
PRODUCT_BUNDLE_IDENTIFIER = dev.icerock.moko.mokoMvvmFlowSwiftUI;
PRODUCT_NAME = mokoMvvmFlowSwiftUI;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -528,6 +531,7 @@
"@loader_path/Frameworks",
);
MARKETING_VERSION = 1.0;
OTHER_SWIFT_FLAGS = "-verify-emitted-module-interface";
PRODUCT_BUNDLE_IDENTIFIER = dev.icerock.moko.mokoMvvmFlowSwiftUI;
PRODUCT_NAME = mokoMvvmFlowSwiftUI;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -562,6 +566,7 @@
);
MACOSX_DEPLOYMENT_TARGET = 12.1;
MARKETING_VERSION = 1.0;
OTHER_SWIFT_FLAGS = "-verify-emitted-module-interface";
PRODUCT_BUNDLE_IDENTIFIER = dev.icerock.moko.mokoMvvmFlowSwiftUI;
PRODUCT_NAME = mokoMvvmFlowSwiftUI;
SDKROOT = macosx;
Expand Down Expand Up @@ -594,6 +599,7 @@
);
MACOSX_DEPLOYMENT_TARGET = 12.1;
MARKETING_VERSION = 1.0;
OTHER_SWIFT_FLAGS = "-verify-emitted-module-interface";
PRODUCT_BUNDLE_IDENTIFIER = dev.icerock.moko.mokoMvvmFlowSwiftUI;
PRODUCT_NAME = mokoMvvmFlowSwiftUI;
SDKROOT = macosx;
Expand Down Expand Up @@ -676,6 +682,7 @@
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_INSTALL_OBJC_HEADER = NO;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
};
name = Debug;
Expand Down Expand Up @@ -728,6 +735,7 @@
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_INSTALL_OBJC_HEADER = NO;
SWIFT_OPTIMIZATION_LEVEL = "-O";
};
name = Release;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "22BDE6FF281BD34C00259368"
BuildableName = "mokoMvvmFlowSwiftUI__iOS_.framework"
BuildableName = "mokoMvvmFlowSwiftUI.framework"
BlueprintName = "mokoMvvmFlowSwiftUI (iOS)"
ReferencedContainer = "container:mokoMvvmFlow.xcodeproj">
</BuildableReference>
Expand Down Expand Up @@ -51,7 +51,7 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "22BDE6FF281BD34C00259368"
BuildableName = "mokoMvvmFlowSwiftUI__iOS_.framework"
BuildableName = "mokoMvvmFlowSwiftUI.framework"
BlueprintName = "mokoMvvmFlowSwiftUI (iOS)"
ReferencedContainer = "container:mokoMvvmFlow.xcodeproj">
</BuildableReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "22BDE720281BD37100259368"
BuildableName = "mokoMvvmFlowSwiftUI__macOS_.framework"
BuildableName = "mokoMvvmFlowSwiftUI.framework"
BlueprintName = "mokoMvvmFlowSwiftUI (macOS)"
ReferencedContainer = "container:mokoMvvmFlow.xcodeproj">
</BuildableReference>
Expand Down Expand Up @@ -51,7 +51,7 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "22BDE720281BD37100259368"
BuildableName = "mokoMvvmFlowSwiftUI__macOS_.framework"
BuildableName = "mokoMvvmFlowSwiftUI.framework"
BlueprintName = "mokoMvvmFlowSwiftUI (macOS)"
ReferencedContainer = "container:mokoMvvmFlow.xcodeproj">
</BuildableReference>
Expand Down
11 changes: 10 additions & 1 deletion mvvm-flow/apple/xcode/mokoMvvmFlowSwiftUI/ViewModelState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,16 @@ public extension ObservableObject where Self: ViewModel {
func state<T>(_ flowKey: KeyPath<Self, CStateFlow<NSArray>>) -> Array<T> {
return state(
flowKey,
equals: { $0 === $1 },
equals: { oldValue, newValue in
if let oldValue = oldValue {
guard let newValue = newValue as? Array<T> else {
return false
}
return oldValue.isEqual(to: newValue)
} else {
return newValue == nil
}
},
mapper: { $0 as! Array<T> }
)
}
Expand Down
Loading

0 comments on commit 4ab6dee

Please sign in to comment.