jetc.dev Newsletter Issue #26
Published: 2020-08-11
This week, most of the focus is on the dev16
release, both in terms of the
big changes (totally revised Java packages) and the smaller ones. Plus,
we try to think declaratively, look at Joe Birch’s latest Compose app, and
just try to “roll with the (Compose) changes”.
One Off the Stack, One Off the Slack
You’ve got questions. That’s understandable!
Alas, we continue to collect few good answers in Stack Overflow in
the android-jetpack-compose
tag.
Visibility and Declarative Thinking
Android developers are very used to “to change what the user sees, manipulate properties of objects”. Compose and declarative UIs instead go with “to change what the user sees, describe what you want to show now”. This is more powerful and, in the end, less complex, but it is a change in mindset, as we see in this week’s highlighted Slack thread.
Composable Commentary
Posts, videos, and other new information related to Jetpack Compose!
Compose dev16
Release Notes
dev15
was about changing artifacts. dev16
is about changing Java packages.
Most of your imports will need to be switched. A table appears in the release
notes, and all of the new packages are sub-packages of androidx.compose
.
androidx.ui.test
and androidx.ui.tooling
are left alone, as their artifacts
were in dev15
.
Compose Runtime dev16
Release Notes
mutableStateOf()
, ambientOf()
, and savedInstanceStateOf()
now use
==
instead of ===
to determine when values have changed, by default.
Use policy = referentialEqualityPolicy()
in those functions to switch
back to ===
.
Compose Foundation dev16
Release Notes
Names keep changing: what was AdapterList
, then LazyColumnItems
, is now
LazyColumnFor
. We also have LazyColumnForIndexed
to give us an index number
along with each item in the callback, plus Row
equivalents (LazyRowFor
,
LazyRowForIndexed
). Modifier.drawBackground()
is now Modifier.background()
,
Row
and Column
are now inline functions, and ConstraintSet2
is now called
just ConstraintSet
. And more!
Compose UI dev16
Release Notes
setViewContent()
on ViewGroup
and Activity
are now deprecated in favor of setContent()
.
FocusManager
has been deprecated in favor of modifiers like Modifier.focus()
.
Modifier.tag()
is deprecated in favor of Modifier.layoutId()
. And Modifier.plus()
is deprecated (along with the +
operator) in favor of Modifier.then()
.
Compose Material dev16
Release Notes
ColorPalette
is now Colors
and is a final class, and its focus is tightened to
being just a definition of material colors, not a general-purpose theme engine.
Also, TextField
is now called BaseTextField
and FilledTextField
takes over
the TextField
name.
YouTube: Codelab - Art of Jetpack Compose
Wajahat Karim’s 360|AnDev presentation video is up; Issue #24 had links to the slides. As the title suggests, this is a codelab walking you through setting up Compose and making a basic app.
Jetpack Compose: Part 1 — Design
Himanshu Choudhary provides us with another introduction to Compose.
Resource Roundup
100% pure code!
GitHub: hitherejoe / minimise
Joe Birch returns with Minimise, “to help us think more about the purchases we make and rediscover the things that we own”. This is a Kotlin/Multiplatform app, with Android and iOS UIs, the former implemented using Compose.
GitHub: MFranceschi6 / loading-spinner
GitHub user MFranceschi6 offers a Compose modifier that adds an animated loading spinner to the composable of your choice, with a simple boolean state to control when the spinner should be replaced by the real content.
…And One More Thing
With luck, dev16
represents the last of the “refactor the world” developer
preview releases. dev15
switched the artifacts; dev16
switched the Java
packages. So while last time you needed to fix your Gradle build scripts,
this time you just need to reimport everything.
“Just”.
The top-level dev16
release notes
offers a cheat sheet of all the Java packages, set up as import
statements.
In theory, you can replace all the broken ones with this list, then let
Android Studio optimize the imports. Just do that for every source file.
Once again, “just”.
This sort of change might not have been inevitable, but it seems perfectly reasonable. Compose is huge, and it would have been unrealistic to expect its developers to get the packaging correct the first time. Conversely, this sort of wide-ranging set of moves gets more painful as we move into alpha/beta/RC/stable releases, so this is a good time to get it out of the way.
The downside, as with all of these sorts of things, is making existing educational material moderately obsolete. Questions like this one exemplify the problem: developers trying to play with Compose run into out-of-date posts and stuff. Now, that just got a lot worse… temporarily. In the fullness of time, we will have new articles, posts, videos, projects, and answers to replace the obsolete ones. And, that is a key reason why it is good that these changes are out of the way, so by the time alpha releases arrive, we have a (hopefully) stable packaging of Compose.
So, everything will be wonderful in time. We just have to wait for the future to get here.
“Just”.
Or, you can subscribe to the Atom feed or follow Mark Murphy in the Fediverse.
Recent Issues:
- 2024-10-01: Lazy grids! Focus! @colinmarsch@androiddev.social on CMP accessibility! @skydoves@androiddev.social on Landscapist! @sinasamaki@androiddev.social on Slider()! And... what is it?!?
- 2024-09-24: A Compose security fix and a new alpha! clipToBounds()! Localization! offset()! @skydoves@androiddev.social on server-defined UI! Bottom sheets! And... someone set us up *3* BOMs?!?
- 2024-09-17: Compose 1.7.1 and Compose Multiplatform 1.7.0-beta02! Flow layouts! TV Compose! SharedBounds! Image cropping! And... why does remember() not seem always to remember?!?