Skip to content

05nelsonm/component-parcelize

Repository files navigation

component-parcelize

badge-license badge-latest-release

badge-kotlin

badge-platform-android badge-platform-jvm badge-platform-js badge-platform-js-node badge-platform-linux badge-platform-macos badge-platform-ios badge-platform-tvos badge-platform-watchos badge-platform-wasm badge-platform-windows badge-support-android-native badge-support-apple-silicon badge-support-js-ir badge-support-linux-arm badge-support-linux-mips

Kotlin Multiplatform support for using android.os.Parcelable from common code.

A full list of kotlin-components projects can be found HERE

Get Started

  • Add dependency to commonMain

    // build.gradle.kts
    dependencies {
        val vParcelize = "0.1.2"
        // If usage is a part of your public api, use `api`; otherwise
        // use `implementation` for internal-only usage.
        api("io.matthewnelson.kotlin-components:parcelize:$vParcelize")
    }
    // build.gradle
    dependencies {
        def vParcelize = "0.1.1"
        // If usage is a part of your public api, use `api`; otherwise
        // use `implementation` for internal-only usage.
        api "io.matthewnelson.kotlin-components:parcelize:$vParcelize"
    }
  • Add the kotlin-parcelize plugin to your project

    plugins {
        id("kotlin-parcelize")
    }

Usage

  • In commonMain

    import io.matthewnelson.component.parcelize.Parcelable
    import io.matthewnelson.component.parcelize.Parcelize
    
    @Parcelize
    data class MyData(val value: String): Parcelable
  • Usable from androidMain

    // androidMain
    val intent = Intent()
    intent.putExtra("MY_DATA", MyData("Parcelable commonMain class"))
    
    val myData = intent.getParcelableExtra<MyData>("MY_DATA")
    println(myData.toString())
  • See the sample-data and sample-app examples

Kotlin Version Compatibility

parcelize kotlin
0.1.2 1.8.0
0.1.1 1.7.20
0.1.0 1.6.21

Git

This project utilizes git submodules. You will need to initialize them when cloning the repository via:

$ git clone --recursive https://github.com/05nelsonm/component-parcelize.git

If you've already cloned the repository, run:

$ git checkout master
$ git pull
$ git submodule update --init

In order to keep submodules updated when pulling the latest code, run:

$ git pull --recurse-submodules