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

What's New In Kotlin? - Seattle GDG I/O'19 Exte...

What's New In Kotlin? - Seattle GDG I/O'19 Extended

A look at some of the newest Kotlin features and announcements from 2019 and Google I/O '19.

- New Features
- IO19
- New Learning Opportunities

Specific topics include:
- kotlinx.coroutines
- kotlinx.coroutines.flow
- kotlinx.serialization
- Jetpack Compose
- Kotlin/Everywhere
- etc...

Nate Ebel

May 22, 2019
Tweet

More Decks by Nate Ebel

Other Decks in Programming

Transcript

  1. import kotlinx.coroutines.* fun main() = runBlocking { launch { doWorld()

    } println("Hello,") } // this is your first suspending function suspend fun doWorld() { delay(1000L) println("World!") } Simple Coroutine
  2. class MyViewModel: ViewModel() { init { viewModelScope.launch { // Coroutine

    that will be canceled // when the ViewModel is cleared. } } } New ViewModelScope
  3. • Similar to RxJava • Channels = hot • Flow

    = cold • Multiplatform support
  4. val ints: Flow<Int> = flow { for (i in 1..10)

    { delay(100) emit(i) } } // takes 1 second, prints 10 ints ints.collect { println(it) } Flow In Action https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/index.html
  5. import kotlinx.serialization.* import kotlinx.serialization.json.Json /** * From https://github.com/Kotlin/kotlinx.serialization */ @Serializable

    data class Data(val a: Int, val b: String = "42") fun main(args: Array<String>) { // serializing objects val jsonData = Json.stringify(Data.serializer(), Data(42)) // serializing lists val jsonList = Json.stringify(Data.serializer().list, listOf(Data(42))) println(jsonData) // {"a": 42, "b": "42"} println(jsonList) // [{"a": 42, "b": "42"}] // parsing data back // b is optional since it has default value val obj = Json.parse(Data.serializer(), """{"a":42}""") println(obj) // Data(a=42, b="42") } Multiplatform Serialization https://github.com/Kotlin/kotlinx.serializationl
  6. And more... • Incremental annotation processing for kapt • Unsigned

    numbers • Cocoapod support for XCode • Kotlin Gradle DSL support for multiplatform projects
  7. • New, reactive UI toolkit written in Kotlin • Unbundled

    from framework • Compose UI Library & Compose Compiler
  8. @Model class CounterState(var count: Int) @Composable fun Counter() { //

    introduce a CounterState value. // Instance will be preserved across compositions. // Note: the `+` syntax is temporary val count = +memo { CounterState(0) } // use it to compose your UI. pass it into other composables as parameters Text(text="Count: ${count.count}") // modify the value inside of event handlers, for instance Button(text="Increment, onClick = { count.count += 1; }) } Build Composable UI https://developer.android.com/jetpack/compose
  9. class UserListActivity : Activity() { override fun onCreate(savedInstanceState: Bundle?) {

    super.onCreate(savedInstanceState) setContent { AppComponent() } } } Build Composable UI https://developer.android.com/jetpack/compose
  10. • Understand Kotlin Coroutines on Android • Mobile Backends with

    Kotlin and Google Cloud • What's New in Android • Kotlin Under the Hood: Understand the Internals • Declarative UI Patterns • What’s New In Kotlin On Android, 2 Years In
  11. • Developing Android Apps with Kotlin by Google • New

    course from Google & Udacity • Free
  12. • Kotlin/Everywhere • Community-led events • Learn about Kotlin for

    Android, Cloud, and Multi-platform development • Apply for support from Google & JetBrains
  13. • Kotlin-related talks from Google I/O • Reference for kotlinx.coroutines.flow

    • Post regarding goals/need for Flow • Discussion around Flow vs Channels vs RxJava • Reference for kotlinx.serialization • Developing Android Apps With Kotlin Course • KOTLIN/Everywhere • ASOP page for Jetpack Compose • Reference for Jetpack Compose @n8ebel