View profile

jetc.dev Newsletter - Issue #67

jetc.dev Newsletter - Issue #67
By Mark Murphy, CommonsWare • Issue #67 • View online
This week, we dive deep into how some of the Compose magic occurs, with looks at the Kotlin compiler plugin and how recomposition works “under the hood”. We also look at some hiccups with collectAsState(), the current state of Lottie for Compose, and what the newly-added Kotlin/Native support for the Compose compiler plugin means. We also peek at an internationalization/localization library, a command-line tool for setting up Compose for Desktop projects, and what that app widget “conceptual code” shown in a Google I|O presentation might really mean.

One Off the Stack, One Off the Slack
You’ve got questions. That’s understandable!
Prefixes in a TextField()
Composable Commentary
Posts, videos, and other new information related to Jetpack Compose!
Podcast: Jetpack Compose Compilation
A historical introduction to the Compose reactive state model
Custom Weekly Schedule Layout with Jetpack Compose - Part 1
Lottie Animations in Jetpack Compose Android
The All-New State in Jetpack Compose
Compose - List / Detail: Basics
Tweets: Compose and Kotlin/Native
Video: Shimmer Animation (Jetpack Compose Beta)
Resource Roundup
100% pure code!
…And One More Thing
Buried in the Google I|O presentation on app widgets, they showed off some “conceptual code” for creating app widgets using a composable API.
This has led some developers to believe that we will be creating app widgets using Compose UI. I strongly doubt that this is the case. We will be able to create app widgets using Compose, but not Compose UI.
Compose UI requires a Canvas to draw on. In Compose for Android, that is Android’s Canvas. In Compose for Desktop, that is a canvas API supplied by Skia and Skiko.
However, other Compose targets, such as Compose for Web or Jake Wharton’s Mosaic, do not support Canvas. And, as a result, they do not support Compose UI. Compose for Web supports a facsimile of some of Compose UI, where they could pull off the same basic look using the DOM and CSS. And Mosaic has an even more limited API, given that it is targeting a terminal window rather than any sort of GUI.
Compose supports managing trees of data using composable functions. Compose UI supports managing trees of UI elements to be drawn on a Canvas using composable functions.
App widgets do not have a Canvas. Even though app widgets are part of Android, they are very different than the activities and fragments that we traditionally build. App widgets are really an IPC protocol between an app and a launcher, where the data passed between the process just so happens to describe a UI. That is why app widgets are created using RemoteViews, as that RemoteViews structure describes the UI and is what gets passed between the processes. RemoteViews does not give us a Canvas.
The most likely case is that writing app widgets with composables will look a bit like Compose UI, but the composables will map to things that you can represent in a RemoteViews. So, in the code snippet shown above, the Column() will map to a LinearLayout, the Text() will map to a TextView, and CheckBox() will map to a CheckBox (newly supported in RemoteViews in Android 12). But, you will not find TextField() in the app widgets API, as RemoteViews does not support EditText.
It would be truly wonderful if app widgets could somehow use the full suite of composables offered by Compose UI. Alas, that is unrealistic.
Did you enjoy this issue?
Mark Murphy, CommonsWare

Jetpack Compose news and notes.

If you don't want these updates anymore, please unsubscribe here.
If you were forwarded this newsletter and you like it, you can subscribe here.
Powered by Revue