diff --git a/README.md b/README.md index 23ef281..348f030 100755 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ allprojects { project build.gradle ```groovy dependencies { - commonMainApi("dev.icerock.moko:parcelize:0.8.0") + commonMainApi("dev.icerock.moko:parcelize:0.9.0") } ``` diff --git a/build.gradle.kts b/build.gradle.kts index 291cb91..28a54b5 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -19,8 +19,3 @@ allprojects { version = libs.versions.mokoParcelizeVersion.get() } } - -// temporary fix for Apple Silicon (remove after 1.6.20 update) -rootProject.plugins.withType { - rootProject.the().nodeVersion = "16.0.0" -} diff --git a/gradle.properties b/gradle.properties index f09b63b..c877a2f 100755 --- a/gradle.properties +++ b/gradle.properties @@ -5,7 +5,6 @@ org.gradle.parallel=true kotlin.code.style=official kotlin.mpp.stability.nowarn=true -kotlin.mpp.enableGranularSourceSetsMetadata=true -kotlin.mpp.enableCompatibilityMetadataVariant=true +kotlin.mpp.androidSourceSetLayoutVersion=2 android.useAndroidX=true diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 6585fcb..b5b572f 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,6 +1,6 @@ [versions] androidAppCompatVersion = "1.2.0" -mokoParcelizeVersion = "0.8.0" +mokoParcelizeVersion = "0.9.0" [libraries] appCompat = { module = "androidx.appcompat:appcompat", version.ref = "androidAppCompatVersion" } \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 2e6e589..774fae8 100755 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/parcelize-build-logic/build.gradle.kts b/parcelize-build-logic/build.gradle.kts index e8b30b4..a4a2568 100644 --- a/parcelize-build-logic/build.gradle.kts +++ b/parcelize-build-logic/build.gradle.kts @@ -11,7 +11,7 @@ repositories { dependencies { api("dev.icerock:mobile-multiplatform:0.13.0") - api("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10") - api("com.android.tools.build:gradle:7.0.4") - api("io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.19.0") + api("org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.20") + api("com.android.tools.build:gradle:7.4.2") + api("io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.22.0") } diff --git a/parcelize-build-logic/src/main/kotlin/android-base-convention.gradle.kts b/parcelize-build-logic/src/main/kotlin/android-base-convention.gradle.kts index 7f67285..c36ca55 100644 --- a/parcelize-build-logic/src/main/kotlin/android-base-convention.gradle.kts +++ b/parcelize-build-logic/src/main/kotlin/android-base-convention.gradle.kts @@ -5,10 +5,10 @@ import com.android.build.gradle.BaseExtension configure { - compileSdkVersion(30) + compileSdkVersion(33) defaultConfig { - minSdkVersion(16) - targetSdkVersion(30) + minSdk = 16 + targetSdk = 33 } } diff --git a/parcelize-build-logic/src/main/kotlin/detekt-convention.gradle.kts b/parcelize-build-logic/src/main/kotlin/detekt-convention.gradle.kts index 7d7c654..bd7cc6a 100644 --- a/parcelize-build-logic/src/main/kotlin/detekt-convention.gradle.kts +++ b/parcelize-build-logic/src/main/kotlin/detekt-convention.gradle.kts @@ -14,5 +14,5 @@ tasks.register("detektWithoutTests") { } dependencies { - "detektPlugins"("io.gitlab.arturbosch.detekt:detekt-formatting:1.19.0") + "detektPlugins"("io.gitlab.arturbosch.detekt:detekt-formatting:1.22.0") } diff --git a/parcelize-build-logic/src/main/kotlin/multiplatform-library-convention.gradle.kts b/parcelize-build-logic/src/main/kotlin/multiplatform-library-convention.gradle.kts index 3c20e8f..10b1e8b 100644 --- a/parcelize-build-logic/src/main/kotlin/multiplatform-library-convention.gradle.kts +++ b/parcelize-build-logic/src/main/kotlin/multiplatform-library-convention.gradle.kts @@ -31,11 +31,6 @@ kotlin { wasm32() sourceSets { - all { - languageSettings.apply { - useExperimentalAnnotation("kotlin.RequiresOptIn") - } - } val commonMain by getting diff --git a/parcelize/src/androidMain/kotlin/dev/icerock/moko/parcelize/Parcelize.kt b/parcelize/src/androidMain/kotlin/dev/icerock/moko/parcelize/Parcelize.kt index 26ec31b..27f71e9 100755 --- a/parcelize/src/androidMain/kotlin/dev/icerock/moko/parcelize/Parcelize.kt +++ b/parcelize/src/androidMain/kotlin/dev/icerock/moko/parcelize/Parcelize.kt @@ -7,9 +7,17 @@ package dev.icerock.moko.parcelize import android.os.Parcelable import kotlinx.android.parcel.IgnoredOnParcel import kotlinx.android.parcel.Parcelize +import kotlinx.parcelize.Parceler +import kotlinx.parcelize.TypeParceler actual typealias Parcelize = Parcelize actual typealias Parcelable = Parcelable actual typealias IgnoredOnParcel = IgnoredOnParcel + +actual typealias Parceler

= Parceler

+ +actual typealias TypeParceler = TypeParceler + +actual typealias Parcel = android.os.Parcel diff --git a/parcelize/src/commonMain/kotlin/dev/icerock/moko/parcelize/Parcelize.kt b/parcelize/src/commonMain/kotlin/dev/icerock/moko/parcelize/Parcelize.kt index fb3d572..32615e3 100755 --- a/parcelize/src/commonMain/kotlin/dev/icerock/moko/parcelize/Parcelize.kt +++ b/parcelize/src/commonMain/kotlin/dev/icerock/moko/parcelize/Parcelize.kt @@ -8,4 +8,31 @@ expect annotation class Parcelize() expect interface Parcelable -expect annotation class IgnoredOnParcel() \ No newline at end of file +expect annotation class IgnoredOnParcel() + +expect interface Parceler

{ + fun create(parcel: Parcel): P + + fun P.write(parcel: Parcel, flags: Int) +} + +expect annotation class TypeParceler>() + +expect class Parcel { + fun readByte(): Byte + fun readInt(): Int + + fun readFloat(): Float + fun readDouble(): Double + fun readString(): String? + + fun writeByte(value: Byte) + fun writeInt(value: Int) + + fun writeFloat(value: Float) + + fun writeDouble(value: Double) + fun writeString(value: String?) + + +} \ No newline at end of file diff --git a/parcelize/src/notAndroidMain/kotlin/dev/icerock/moko/parcelize/Parcelize.kt b/parcelize/src/notAndroidMain/kotlin/dev/icerock/moko/parcelize/Parcelize.kt index 3b22dc6..2b957a0 100755 --- a/parcelize/src/notAndroidMain/kotlin/dev/icerock/moko/parcelize/Parcelize.kt +++ b/parcelize/src/notAndroidMain/kotlin/dev/icerock/moko/parcelize/Parcelize.kt @@ -6,4 +6,36 @@ package dev.icerock.moko.parcelize actual interface Parcelable actual annotation class IgnoredOnParcel -actual annotation class Parcelize \ No newline at end of file +actual annotation class Parcelize +actual interface Parceler

{ + actual fun create(parcel: Parcel): P + actual fun P.write(parcel: Parcel, flags: Int) +} + +actual annotation class TypeParceler> + +actual class Parcel { + actual fun readString(): String? = null + actual fun readByte(): Byte = 1 + + actual fun readInt(): Int = 1 + + actual fun readFloat(): Float = 1f + + actual fun readDouble(): Double = 1.0 + + actual fun writeByte(value: Byte) { + } + + actual fun writeInt(value: Int) { + } + + actual fun writeFloat(value: Float) { + } + + actual fun writeDouble(value: Double) { + } + + actual fun writeString(value: String?) { + } +} \ No newline at end of file diff --git a/sample/android-app/src/main/AndroidManifest.xml b/sample/android-app/src/main/AndroidManifest.xml index 29ce9ad..cf8cdc9 100755 --- a/sample/android-app/src/main/AndroidManifest.xml +++ b/sample/android-app/src/main/AndroidManifest.xml @@ -10,7 +10,7 @@ android:theme="@style/Theme.AppCompat.DayNight" tools:ignore="GoogleAppIndexingWarning"> - + diff --git a/sample/android-app/src/main/java/com/icerockdev/MainActivity.kt b/sample/android-app/src/main/java/com/icerockdev/MainActivity.kt index e480d1b..1fdb07f 100755 --- a/sample/android-app/src/main/java/com/icerockdev/MainActivity.kt +++ b/sample/android-app/src/main/java/com/icerockdev/MainActivity.kt @@ -5,18 +5,16 @@ package com.icerockdev import android.os.Bundle +import android.util.Log import androidx.appcompat.app.AppCompatActivity +import com.icerockdev.library.TestUsers import com.icerockdev.library.User +import kotlinx.datetime.LocalDateTime class MainActivity : AppCompatActivity() { private val userInstanceKey = "user" - private var user: User = User( - firstName = "Aleksey", - lastName = "Mikhailov", - phone = "+79000000000", - age = 26 - ) + private var user: User = TestUsers.user override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -26,7 +24,6 @@ class MainActivity : AppCompatActivity() { override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) - outState.putParcelable(userInstanceKey, user) } @@ -34,6 +31,7 @@ class MainActivity : AppCompatActivity() { super.onRestoreInstanceState(savedInstanceState) savedInstanceState.getParcelable(userInstanceKey)?.let { + Log.d("MainActivity", "Read user: $it") this.user = it } } diff --git a/sample/ios-app/src/TestViewController.swift b/sample/ios-app/src/TestViewController.swift index b673abb..ce51c88 100755 --- a/sample/ios-app/src/TestViewController.swift +++ b/sample/ios-app/src/TestViewController.swift @@ -11,14 +11,7 @@ class TestViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() - - let user = User( - firstName: "Aleksey", - lastName: "Mikhailov", - phone: "+79000000000", - age: 26 - ) - label.text = "Hello, \(user.firstName)!" + label.text = "Hello, \(TestUsers.shared.user.firstName)!" } } diff --git a/sample/macos-app/mokoSampleParcelize/ContentView.swift b/sample/macos-app/mokoSampleParcelize/ContentView.swift index b202950..c654c5f 100644 --- a/sample/macos-app/mokoSampleParcelize/ContentView.swift +++ b/sample/macos-app/mokoSampleParcelize/ContentView.swift @@ -8,16 +8,9 @@ import SwiftUI import MultiPlatformLibrary -let user = User( - firstName: "Aleksey", - lastName: "Mikhailov", - phone: "+79000000000", - age: 26 -) - struct ContentView: View { var body: some View { - Text("Hello, \(user.firstName)!") + Text("Hello, \(TestUsers.shared.user.firstName)!") .frame(maxWidth: .infinity, maxHeight: .infinity) } } diff --git a/sample/mpp-library/build.gradle.kts b/sample/mpp-library/build.gradle.kts index ab4e1ae..ac71831 100644 --- a/sample/mpp-library/build.gradle.kts +++ b/sample/mpp-library/build.gradle.kts @@ -22,4 +22,5 @@ kotlin { dependencies { commonMainApi(projects.parcelize) + commonMainApi("org.jetbrains.kotlinx:kotlinx-datetime:0.4.0") } diff --git a/sample/mpp-library/src/commonMain/kotlin/com/icerockdev/library/LocalDateTimeParceler.kt b/sample/mpp-library/src/commonMain/kotlin/com/icerockdev/library/LocalDateTimeParceler.kt new file mode 100644 index 0000000..6ca45b7 --- /dev/null +++ b/sample/mpp-library/src/commonMain/kotlin/com/icerockdev/library/LocalDateTimeParceler.kt @@ -0,0 +1,19 @@ +package com.icerockdev.library + +import dev.icerock.moko.parcelize.Parcel +import dev.icerock.moko.parcelize.Parceler +import kotlinx.datetime.LocalDateTime +import kotlinx.datetime.toLocalDateTime + +object LocalDateTimeParceler : + Parceler { + override fun create(parcel: Parcel): LocalDateTime { + val date = parcel.readString() + return date?.toLocalDateTime() + ?: LocalDateTime(0, 0, 0, 0, 0) + } + + override fun LocalDateTime.write(parcel: Parcel, flags: Int) { + parcel.writeString(this.toString()) + } +} \ No newline at end of file diff --git a/sample/mpp-library/src/commonMain/kotlin/com/icerockdev/library/TestUsers.kt b/sample/mpp-library/src/commonMain/kotlin/com/icerockdev/library/TestUsers.kt new file mode 100644 index 0000000..3c4b9ed --- /dev/null +++ b/sample/mpp-library/src/commonMain/kotlin/com/icerockdev/library/TestUsers.kt @@ -0,0 +1,13 @@ +package com.icerockdev.library + +import kotlinx.datetime.LocalDateTime + +object TestUsers { + val user: User = User( + firstName = "Aleksey", + lastName = "Mikhailov", + phone = "+79000000000", + age = 26, + birthday = LocalDateTime(1970, 1, 1, 0, 0, 0, 0) + ) +} \ No newline at end of file diff --git a/sample/mpp-library/src/commonMain/kotlin/com/icerockdev/library/User.kt b/sample/mpp-library/src/commonMain/kotlin/com/icerockdev/library/User.kt index b85c3e8..07c1dd7 100755 --- a/sample/mpp-library/src/commonMain/kotlin/com/icerockdev/library/User.kt +++ b/sample/mpp-library/src/commonMain/kotlin/com/icerockdev/library/User.kt @@ -6,11 +6,15 @@ package com.icerockdev.library import dev.icerock.moko.parcelize.Parcelable import dev.icerock.moko.parcelize.Parcelize +import dev.icerock.moko.parcelize.TypeParceler +import kotlinx.datetime.LocalDateTime @Parcelize data class User( val firstName: String, val lastName: String, val phone: String, - val age: Int + val age: Int, + @TypeParceler() + val birthday : LocalDateTime ) : Parcelable