Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Said Tahsin Dane_Tobias Heine - Droidcon (Code)...

Said Tahsin Dane_Tobias Heine - Droidcon (Code) Sharing is caring - An Introduction to Kotlin Multiplatform projects

droidcon Berlin

July 12, 2018
Tweet

More Decks by droidcon Berlin

Other Decks in Programming

Transcript

  1. apply plugin: 'kotlin-platform-jvm' dependencies { compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" expectedBy project(":data-common") expectedBy

    project(":io-common") testCompile "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version" testCompile "org.jetbrains.kotlin:kotlin-test:$kotlin_version" } Kotlin Multiplatform Project - Common JVM
  2. apply plugin: 'kotlin' apply plugin: 'application' dependencies { compile project(':common-jvm')

    compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" compile 'no.tornado:tornadofx:1.7.14' testCompile "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version" testCompile "org.jetbrains.kotlin:kotlin-test:$kotlin_version" } mainClassName = 'com.novoda.gol.GameOfLife' Kotlin Multiplatform Project - Desktop Client
  3. apply plugin: 'kotlin-platform-android' apply plugin: 'com.android.application' dependencies { compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"

    expectedBy project(":common") testCompile "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version" testCompile "org.jetbrains.kotlin:kotlin-test:$kotlin_version" } Kotlin Multiplatform Project - Android Platform
  4. expect class GameLoop { fun startWith(intervalMs: Int, onTick: () ->

    Unit) fun stop() fun isLooping(): Boolean } GameLoop - Common
  5. actual class GameLoop { private var gameLoop: Disposable? = null

    actual fun startWith(intervalMs: Int, onTick: () -> Unit) { gameLoop = Flowable.interval(intervalMs.toLong(), TimeUnit.MILLISECONDS) .subscribe { onTick() } } actual fun stop() = gameLoop!!.dispose() actual fun isLooping() = gameLoop != null } GameLoop - JVM
  6. actual class GameLoop { private var gameloop: Int? = null

    actual fun startWith(intervalMs: Int, onTick: () -> Unit) { gameloop = window.setInterval({ onTick() }, intervalMs) } actual fun stop() = window.clearInterval(gameloop!!) actual fun isLooping() = gameloop != null } GameLoop - JS
  7. actual class GameLoop { private var gameloop: NSTimer? = null

    actual fun startWith(intervalMs: Int, onTick: () -> Unit) { gameloop = NSTimer(NSDate(), 0.5, true, { onTick() }) NSRunLoop.currentRunLoop().addTimer(gameloop!!, NSRunLoopCommonModes) } actual fun stop() = gameloop!!.invalidate() actual fun isLooping() = gameloop != null } GameLoop - Kotlin/Native
  8. apply plugin: 'konan' konan.targets = ['iphone', 'iphone_sim'] konanArtifacts { framework('KotlinGameOfLife')

    { enableMultiplatform true enableDebug true } } dependencies { expectedBy project(':common') } Kotlin/Native Gradle Plugin
  9. Multiplatform Libs are coming! K/N Coroutines are coming - slowly!

    HttpClient Mocking library Sqlite for Kotlin multiplatform Reagent
  10. What is missing for v1.0 ? Multithreading HTTP Reactive Code

    Caching (Better) testing support Third party SDK’s (ads, tracking, ...)