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

Build a Multiplatform Future with Kotlin (Craft Conference 2024)

Build a Multiplatform Future with Kotlin (Craft Conference 2024)

Márton Braun

May 31, 2024
Tweet

More Decks by Márton Braun

Other Decks in Programming

Transcript

  1. Native Reduced development time Consistent behavior Fewer bugs Best user

    experience Cross-platform VS Great performance Full platform capabilities
  2. Native Reduced development time Consistent behavior Fewer bugs Great performance

    Best user experience Cross-platform & Full platform capabilities
  3. Start of project 2013 2014 2015 2016 2017 2018 2019

    2020 2021 2012 2022 2010 2011 2023 2024 2025
  4. Start of project 2013 2014 2015 2016 2017 2018 2019

    2020 2021 2012 2022 2010 2011 2023 2024 2025 Kotlin/JVM .kt .class Java .java .class
  5. Public announcement Start of project Open source 2013 2014 2015

    2016 2017 2018 2019 2020 2021 2012 2022 2010 2011 2023 2024 2025 Kotlin/JVM .kt .class Java .java .class
  6. Public announcement Start of project Open source 2013 2014 2015

    2016 2017 2018 2019 2020 2021 2012 2022 2010 2011 2023 2024 2025 Kotlin/JVM .kt .class Kotlin 1.0
  7. Kotlin 1.0 Public announcement Start of project Open source JavaScript

    2013 2014 2015 2016 2017 2018 2019 2020 2021 2012 2022 2010 2011 2023 2024 2025 Kotlin/JVM .kt .class Kotlin/JS .kt .js
  8. Kotlin 1.0 Public announcement Start of project Open source Native

    JavaScript 2013 2014 2015 2016 2017 2018 2019 2020 2021 2012 2022 2010 2011 2023 2024 2025 Kotlin/Native .kt .klib|.kexe
  9. Kotlin 1.0 Public announcement Start of project Open source Native

    JavaScript 2013 2014 2015 2016 2017 2018 2019 2020 2021 2012 2022 2010 2011 2023 2024 2025 Kotlin/Native .kt .so|.dll|.exe|.kexe|.etc
  10. Kotlin 1.0 Public announcement Start of project Open source Native

    JavaScript 2013 2014 2015 2016 2017 2018 2019 2020 2021 2012 2022 2010 2011 2023 2024 2025 Kotlin/Native .kt .klib|.kexe
  11. Kotlin 1.0 Public announcement Start of project Open source Native

    JavaScript 2013 2014 2015 2016 2017 2018 2019 2020 2021 2012 2022 2010 2011 2023 2024 2025 Kotlin/JVM .kt .class Kotlin/Native .kt .klib|.kexe Kotlin/JS .kt .js
  12. Kotlin 1.0 Public announcement Start of project Open source Native

    JavaScript KMP alpha 2013 2014 2015 2016 2017 2018 2019 2020 2021 2012 2022 2010 2011 2023 2024 2025
  13. Kotlin 1.0 Public announcement Start of project Open source Native

    JavaScript KMP alpha KMP beta 2013 2014 2015 2016 2017 2018 2019 2020 2021 2012 2022 2010 2011 2023 2024 2025
  14. Kotlin 1.0 Public announcement Start of project Open source Native

    JavaScript KMP stable KMP alpha KMP beta 2013 2014 2015 2016 2017 2018 2019 2020 2021 2012 2022 2010 2011 2023 2024 2025
  15. Kotlin 1.0 Public announcement Start of project Open source Native

    JavaScript KMP stable Wasm Kotlin/JVM .kt Kotlin/Native .kt Kotlin/JS .kt Kotlin/Wasm .kt .class .klib|.kexe .js .wasm KMP alpha KMP beta 2013 2014 2015 2016 2017 2018 2019 2020 2021 2012 2022 2010 2011 2023 2024 2025
  16. .kt K2 frontend JVM backend Native backend JS backend Wasm

    backend .class .klib|.kexe .js .wasm
  17. .kt K2 frontend JVM backend Native backend JS backend Wasm

    backend .class .klib|.kexe .js .wasm
  18. Kotlin 1.0 Public announcement Start of project Open source Native

    JavaScript KMP stable Wasm KMP alpha KMP beta 2013 2014 2015 2016 2017 2018 2019 2020 2021 2012 2022 2010 2011 2023 2024 2025
  19. Kotlin 1.0 Public announcement Start of project Open source Native

    JavaScript KMP stable Wasm KMP alpha KMP beta 2013 2014 2015 2016 2017 2018 2019 2020 2021 2012 2022 2010 2011 2023 2024 2025
  20. Kotlin 1.0 Public announcement Start of project Open source Native

    JavaScript KMP stable Wasm KMP alpha KMP beta 2013 2014 2015 2016 2017 2018 2019 2020 2021 2012 2022 2010 2011 2023 2024 2025
  21. Java + Kotlin Kotlin 1.0 Public announcement Start of project

    Open source Native JavaScript KMP stable Wasm KMP alpha KMP beta 2013 2014 2015 2016 2017 2018 2019 2020 2021 2012 2022 2010 2011 2023 2024 2025
  22. Kotlin first Java + Kotlin Kotlin 1.0 Public announcement Start

    of project Open source Native JavaScript KMP stable Wasm KMP alpha KMP beta 2013 2014 2015 2016 2017 2018 2019 2020 2021 2012 2022 2010 2011 2023 2024 2025
  23. Kotlin first, Jetpack Compose Java + Kotlin Kotlin 1.0 Public

    announcement Start of project Open source Native JavaScript KMP stable Wasm KMP alpha KMP beta 2013 2014 2015 2016 2017 2018 2019 2020 2021 2012 2022 2010 2011 2023 2024 2025
  24. Jetpack KMP Kotlin first, Jetpack Compose Java + Kotlin Kotlin

    1.0 Public announcement Start of project Open source Native JavaScript KMP stable Wasm KMP alpha KMP beta 2013 2014 2015 2016 2017 2018 2019 2020 2021 2012 2022 2010 2011 2023 2024 2025
  25. .kt .kt .kt Android Desktop iOS Common class Person(val name:

    String, var age: Int) fun greet(person: Person) { println("Hello, ${person.name}") }
  26. .kt .kt .kt Android Desktop iOS Common fun List<Person>.duplicates(): Map<String,

    Int> { return map { it.name.substringBefore(" ") } .groupingBy { it } .eachCount() .filter { (name, count) -> count > 1 } }
  27. Android Desktop iOS Common fun getPlatform(): String fun getPlatform(): String

    = "Java ${System.getProperty("java.version")}" expect actual actual actual
  28. Android iOS fun getPlatform(): String = "Android ${Build.VERSION.SDK_INT}" actual actual

    Common fun getPlatform(): String expect Desktop fun getPlatform(): String = "Java ${System.getProperty("java.version")}" actual
  29. Android iOS fun getPlatform(): String = "iOS ${UIDevice.currentDevice.systemVersion}" fun getPlatform():

    String = "Android ${Build.VERSION.SDK_INT}" actual actual Common fun getPlatform(): String expect Desktop fun getPlatform(): String = "Java ${System.getProperty("java.version")}" actual
  30. Android Desktop iOS Common fun getPlatform(): String fun getPlatform(): String

    = "Java ${System.getProperty("java.version")}" fun getPlatform(): String = "iOS ${UIDevice.currentDevice.systemVersion}" fun getPlatform(): String = "Android ${Build.VERSION.SDK_INT}" expect actual actual actual
  31. .kt .kt .kt Android Desktop iOS Common import io.ktor.client.* suspend

    fun loadHtml(): String { val client = HttpClient() val response = client.get("https://kotlinlang.org") return response.body<String>() }
  32. @Composable fun SquaresGalleryView( images: List<PictureData>, selectedImage: PictureData, onSelect: (PictureData) ->

    Unit, ) { LazyVerticalGrid( modifier = Modifier.padding(top = 4.dp), columns = GridCells.Adaptive(minSize = 130.dp), verticalArrangement = Arrangement.spacedBy(1.dp), horizontalArrangement = Arrangement.spacedBy(1.dp) ) { itemsIndexed(images) { _, picture -> SquareThumbnail( picture = picture, onClick = { onSelect(picture) }, isHighlighted = selectedImage === picture ) } } }
  33. @Composable fun SquaresGalleryView( images: List<PictureData>, selectedImage: PictureData, onSelect: (PictureData) ->

    Unit, ) { LazyVerticalGrid( modifier = Modifier.padding(top = 4.dp), columns = GridCells.Adaptive(minSize = 130.dp), verticalArrangement = Arrangement.spacedBy(1.dp), horizontalArrangement = Arrangement.spacedBy(1.dp) ) { itemsIndexed(images) { _, picture -> SquareThumbnail( picture = picture, onClick = { onSelect(picture) }, isHighlighted = selectedImage === picture ) } } }
  34. Desktop logic Android logic iOS logic Shared logic Shared UI

    Compose Multiplatform Swing Android Views SwiftUI
  35. Desktop logic Android logic iOS logic Shared logic Shared UI

    Compose Multiplatform Swing Android Views SwiftUI
  36. ViewModel org.jetbrains.androidx.lifecycle:lifecycle-viewmodel-compose package androidx.lifecycle public abstract class ViewModel { protected

    open fun onCleared() public fun addCloseable(key: String, closeable: AutoCloseable) public open fun addCloseable(closeable: AutoCloseable) } public val ViewModel.viewModelScope: CoroutineScope
  37. Navigation org.jetbrains.androidx.navigation:navigation-compose val navController: NavHostController = rememberNavController() NavHost( navController, startDestination

    = "list" ) { composable("list") { ListScreen(navController) } composable("detail/{objectId}") { backStackEntry -> val objectId = backStackEntry.arguments?.getString("objectId")?.toInt() DetailScreen(navController, objectId!!) } }