$30 off During Our Annual Pro Sale. View Details »

Kotlin Multiplatform

Panini
December 20, 2018

Kotlin Multiplatform

Panini

December 20, 2018
Tweet

More Decks by Panini

Other Decks in Technology

Transcript

  1. Kotlin Multiplatform
    集まれもうやんカレーとKotlin好き!Kotlin愛好会 vol6

    View Slide

  2. About Me
    ● Matthew Vern / Panini
    ● Twitter: @callipan Github: panpanini
    ● Mercari, Inc
    ● Android Engineer (US)
    ● Kotlin可愛い

    View Slide

  3. Summary
    ● I made a Kotlin Multiplatform project!
    ● It has an Android and iOS app both backed by a common library

    View Slide

  4. Kotlin Multiplatform

    View Slide

  5. Kotlin Multiplatform
    ● https://speakerdeck.com/panini/kotlin-multi-platform
    ● This time I will actually talk about Kotlin Multiplatform

    View Slide

  6. Kotlin Multiplatform
    ● https://kotlinlang.org/docs/reference/multiplatform.html
    ● 1 codebase, multiple platforms
    ○ Android
    ○ iOS
    ○ JS
    ○ (JVM)

    View Slide

  7. Kotlin Multiplatform - requirements
    ● Multiplatform code must be 100% pure Kotlin
    ● Platform specific code must be referenced using `expect` and `actual`

    View Slide

  8. Kotlin Multiplatform - tutorial
    ● https://kotlinlang.org/docs/tutorials/native/mpp-ios-android.html
    ● Explains how to use `expect` and `actual` mechanism
    expect fun platformName(): String
    fun createApplicationScreenMessage() : String {
    return "Kotlin Rocks on ${platformName()}"
    }

    View Slide

  9. :thinking:

    View Slide

  10. Kotlin Multiplatform - tutorial v2.0
    ● I want a realistic sample project, that reflects real world usage
    ● It should perform network operations
    ● UI should be managed by each platform, so only logic should be shared

    View Slide

  11. Lets build!

    View Slide

  12. Lets build!
    ● I wrote some details in this blog, please check it!
    ● https://tech.mercari.com/entry/2018/12/18/114010
    ● I want to build this architecture

    View Slide

  13. Lets build!
    ● First, lets build http client
    ● Because I’m normally an Android Engineer, lets use Retrofit
    ● https://square.github.io/retrofit/
    ● It lets us make network calls just by creating an interface

    View Slide

  14. View Slide

  15. Kotlin Multiplatform - requirements
    ● Multiplatform code must be 100% pure Kotlin
    ● Platform specific code must be referenced using `expect` and `actual`

    View Slide

  16. View Slide

  17. View Slide

  18. View Slide

  19. Ktor
    ● https://ktor.io
    ● Kotlin http server
    ● Kotlin http client

    View Slide

  20. Ktor
    ● https://ktor.io
    ● Kotlin http server
    ● Kotlin http client
    ● Multiplatform support

    View Slide

  21. Lets build!!!!

    View Slide

  22. Service.kt

    View Slide

  23. ViewModel.kt

    View Slide

  24. Observable.kt

    View Slide

  25. Lets build iOS!!!!

    View Slide

  26. Observable.kt

    View Slide

  27. Observable.kt

    View Slide

  28. Lets open Xcode!!!!

    View Slide

  29. Xcode………..

    View Slide

  30. SplatMaps.xcproject

    View Slide

  31. ViewController.swift

    View Slide

  32. View Slide

  33. Lets build Android!!!!

    View Slide

  34. SplatoonCoroutine.idea

    View Slide

  35. MatchFragment.kt

    View Slide

  36. View Slide

  37. Summary
    ● I made a Kotlin Multiplatform project!
    ● It has an Android and iOS app both backed by a common library
    ● Http client is not as easy to use as Retrofit
    ● return KotlinUnit() is ダサイ...
    ● Kotlin works anywhere and that makes it 可愛い
    ● https://github.com/panpanini/SplatMaps-Multiplatform

    View Slide

  38. Have a nice Kotlin!

    View Slide