jetc.dev Newsletter Issue #148

Published: 2023-01-10

This week, we look at onNewIntent() and ContactsContract, and how each can be used from within Compose UI. We focus some on focus, and we look at a snippet for rendering a QR code. Plus, we feast our eyes on some balloons, though for most phone apps, 99 red balloons might be a bit much.

One Off the Stack, One Off the Slack

You’ve got questions. That’s understandable!

What Is “The Context of a @Composable Function”?

Many Compose developers have gotten the error “@Composable invocations can only happen from the context of a @Composable function”. Learn more about that error and how to revise your approach to avoid it, in this week’s highlighted Stack Overflow question.

How Do We Reliably Find Out About Focus Events?

Focus can be a bit tricky in Compose UI. See the differences between onFocusChanged and onFocusEvent, and the importance of collectIsFocusedAsState(), in this week’s highlighted Kotlinlang #compose Slack thread.

Composable Commentary

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

How to handle focus in Jetpack Compose with examples

Alex Styl returns, looking at the various classes and functions involved in managing the focus for TextField() composables. This includes requesting focus, clearing focus, setting the focus order, and more! (Did I mention that focus can be a bit tricky in Compose UI?)

onNewIntent in Jetpack Compose

FunkyMuse looks at onNewIntent(), the Activity lifecycle method that gets called if an existing Activity instance is brought back to the foreground via a startActivity() call. How do you integrate these callbacks into your Compose UI setup, such that your app can react both to the initial activity creation (onCreate()) and onNewIntent() calls as well?

Medium: Setup A Self Modifiable List Of Data In Jetpack Compose

Elye is back, this time looking at situations where the contents of a list are meant to be modified by the user via a composable. When it comes to adding and removing list items, it is clear that we need to mutate the entire list. But, what if it is only the contents of an individual item that are affected (e.g., the checked state of a checklist item)? Elye explores a few possible ways to model and observe these changes.

Medium: Android Contacts & Jetpack Compose

Enrico Mazzucchelli brings us an extended example, looking at how to get contact data from ContactsContract, expose it in a repository, then render it using Compose UI. The UI includes handling the runtime permission request as well as sticky headers in a lazy list, to group contacts by first letter.

Medium: Jetpack Compose clear back stack, popUpTo/popBackStack inclusive explained

Ban Markovic looks at Navigation for Compose and how to manage the back stack, particularly for the case of completely clearing the back stack to get to the initial route. As Ban points out, “the back stack doesn’t contain only screens as destinations; it also contains navigational graphs”, which makes this process a bit more confusing than you might expect.

Resource Roundup

100% pure code!

GitHub: skydoves / Balloon

Jaewoong Eum recently added Compose UI support to his tooltips library, in the form of a Balloon() composable supported by a BalloonBuilder class for configuration details. Learn more about how to create tooltips and other types of popups with this library in this Medium post

Gist: dev-niiaddy / QRPainter.kt

Addy Godwin Nii posted a function that takes some text, encodes it as a QR code, then renders that QR code as a BitmapPainter for use in an Image() or other composable.

GitHub: M0Coding / Pencil-Loader-Animation

Mohamed Ben Rejeb created an elaborate loading animation, showing a pencil drawing, then erasing, a circle.