Skip to content

0.8.0

Latest
Compare
Choose a tag to compare
@github-actions github-actions released this 09 Jun 10:33
· 56 commits to master since this release

Update dependencies

kmp-viewmodel-savedstate

  • Added JvmSerializable - multiplatform reference to Java java.io.Serializable interface,
    along with NonNullSavedStateHandleKey.Companion.serializable and NullableSavedStateHandleKey.Companion.serializable

    // Use `JvmSerializable` with enum classes.
    enum class Gender : JvmSerializable {
      MALE,
      FEMALE,
    }
    
    // Create a `NonNullSavedStateHandleKey` for a serializable type.
    private val genderKey: NonNullSavedStateHandleKey<Gender> = NonNullSavedStateHandleKey.serializable(
      key = "gender",
      defaultValue = Gender.MALE,
    )
    
    // Use `SavedStateHandle.safe` extension function to access `SavedStateHandle` in a type-safe way.
    val genderStateFlow: NonNullStateFlowWrapper<Gender> = savedStateHandle
      .safe { it.getStateFlow(genderKey) }
      .wrap()
  • Since Kotlin 2.0.0, you must add "plugin:org.jetbrains.kotlin.parcelize:additionalAnnotation=com.hoc081098.kmp.viewmodel.parcelable.Parcelize"
    as a free compiler argument to able to use @Parcelize annotation in the common/shared module (Kotlin Multiplatform module).

    // build.gradle.kts
    plugins {
      id("kotlin-parcelize") // Apply the plugin for Android
    }
    
    // Since Kotlin 2.0.0, you must add the below code to your build.gradle.kts of the common/shared module (Kotlin Multiplatform module).
    kotlin {
      [...] // Other configurations
    
      targets.configureEach {
        val isAndroidTarget = platformType == org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType.androidJvm
        compilations.configureEach {
          compileTaskProvider.configure {
            compilerOptions {
              if (isAndroidTarget) {
                freeCompilerArgs.addAll(
                  "-P",
                  "plugin:org.jetbrains.kotlin.parcelize:additionalAnnotation=com.hoc081098.kmp.viewmodel.parcelable.Parcelize",
                )
              }
            }
          }
        }
      }
    }