Newsletter Issue #34

Published: 2020-10-06

alpha04 is here. The Box() is dead; long live the new Box() (formerly Stack())!

Beyond that, we will explore more about how themes work and how you can create your own custom theme. Also, we will look at creating swipeable pages, sortable tables, and Compose-driven presentations.

Note that alpha04 requires the use of Android Studio 4.2 Canary 13. That combination seems to have stability issues, which is unfortunate, understandable, and explored more at the end of the newsletter.

One Off the Stack, One Off the Slack

You’ve got questions. That’s understandable!

Calling Suspend Functions from Composable Callbacks

Many composables take function types as callback parameters, such as for click events on Button(). Sometimes, you might want to call a suspend function from those callbacks. However, usually those callback function types do not themselves declare suspend, so you cannot just call a suspend function from them — you need to wrap it in a coroutine launcher. We explore a bit more about how that works in this week’s highlighted Stack Overflow post.

What Is a Theme, Anyway?

What seemed like a simple question about how to get a material-styled Text() resulted in an exploration of how themes and colors work. MaterialTheme() is not magic: it is just a collection of ambients. We explore more about this in this week’s highlighted Slack thread.

Composable Commentary

Posts, videos, and other new information related to Jetpack Compose!

Compose Foundation alpha04 Release Notes

It appears that we now have two Box() implementations, the original (now deprecated) and the new one (formerly known as Stack()). We now have LazyListState for being able to track the state of LazyColumn() and LazyRow() composables, and that state is already set up to save the scroll position in instance state. Also, if you were using some modifiers tied specifically to RowScope or ColumnScope, those will no longer be available outside of those scopes.

Compose Material alpha04 Release Notes

Some Material composables, such as Slider() and Switch(), now expose InteractionState parameters, so their states can be managed and observed from higher-level composables.

Building a Design System implementation using Jetpack Compose — Part1 (Theme)

Part of the power of Compose UI is not just in being able to rapidly assemble user interfaces, but in creating a library of composables that implement a set of design primitives that designers can use to make it easier to match mockups to implementations. Howie Zuo is starting to explore this area, with a post on creating a custom theme implementation.

Jetpack Compose ViewPager

Jorge Castillo returns with a post on creating a swipeable container composable, designed to provide similar capabilities to ViewPager and ViewPager2. It reviews the Pager() implementation from Google’s JetCaster sample app.

First steps in Jetpack Compose, Part 1 — the power of @Preview

Zhelyazko Atanasov brings us a review of various properties that you can declare on @Preview to configure how previews work, reminiscent of this blog post from July.

Resource Roundup

100% pure code!

GitHub: zach-klippenstein/compose-richtext

All the way back in issue #4 I mentioned Zach Klippenstein’s DSL for creating and rendering rich text in Compose UI. It gets a “re-up” in this issue because Zach added another library to the project, one that renders presentation-style slideshows, with a set of stock slide structures and a set of composables for populating them.

GitHub: hashlin / ComposeDataTable

Lin Min Phyo brings us a library that implements a table composable, with headers and rows with columns. It offers sorting by column, optional row selection, and more!

GitHub: iambaljeet / GitReposCompose

Baljeet Singh is back, with another sample Compose UI app. This particular example uses the GitHub API to let you browse public GitHub repositories.

…And One More Thing

Based on the questions and comments appearing in Slack and Stack Overflow, it appears that Compose ecosystem stability took a hit with Android Studio 4.2 Canary 13 and Compose alpha04. Stability had been on a bit of a downward trend in Studio support for Compose for a while, but this seems like a significant jump in the wrong direction. This is exacerbated by the requirement that you use Canary 13 for alpha04.

Ideally, this stuff would work better.

However, do bear in mind that this is still “bleeding edge”. Given the definition of “Canary” builds, both Studio and Compose are alphas. Alphas are going to have problems from time to time. That is not unique to these two pieces of technology and it is not unique to Google. Just because we got past the “developer preview” phase does not mean that Compose is rock-solid and that everything we do with it comes up with rainbows and unicorns. Sometimes, the unicorns will be more like this one.

(WARNING: the preceding link contains unicorn-delivered violence, with lots of fake blood)

(WARNING: it also contains a scary clown, which in no way should be considered a metaphor for anything related to Android app development)

With luck, things will improve in the coming weeks.

In the meantime, though, you are going to need to live with the fact that, from time to time, you will need to put your Compose experiments to the side for a while and wait for stability to improve. Or, you will need to live with the fact that you are helping improve the stability, by filing bug reports with projects that reproduce problems. If enough developers contribute this way, stability can get better faster for everyone… but if you are not in position to contribute bug reports, that is fine.

Beyond that, keep calm and code on.

If you encounter problems in subscribing, let us know!
Spread the Word!
If you have ideas for items for future newsletter editions, reach out via email or contact Mark Murphy on kotlinlang Slack!