jetc.dev Newsletter Issue #101
While we patiently await a 1.1.0 stable release, we look at switching locales
Switch(). We look at Microsoft’s latest foldable support library,
testing with Robolectric, and criteria for navigation solutions. We examine a segmented progress bar and
an OTP input composable. Plus, Reddit ponders Compose for iOS, while I ponder
Compose… for PDFs.
One Off the Stack, One Off the Slack
You’ve got questions. That’s understandable!
Android 13 is rumored to have a “panlingual” feature, where users can indicate a
particular locale to use on a per-app basis. For older devices, we are stuck with
setLocale() on a
Configuration. But, how do we get our composables
to recompose when we change the locale, particularly if the change switches from
LTR to RTL languages? The answer, like many edge cases in Compose, is a bit tricky,
as we see in this week’s highlighted Stack Overflow question.
Compose UI elements are stateless… except when they are not. That can lead to UI
inconsistencies, and the occasional Compose UI bug, as we see in this week’s
#compose Slack thread.
Posts, videos, and other new information related to Jetpack Compose!
A Redditor pointed out that JetBrains has some commits up showing a version of Compose/Multiplatform that targets iOS. Preliminary indications are that it uses the Skia port to iOS, akin to how Flutter supports iOS.
The Microsoft team supporting the Surface Duo has a preview release up
WindowState object that wraps up a bunch of information for dealing
with foldables, such as the direction of the fold, the current fold state, and
Filip Babić is back, with a presentation from Kotlin KODERS 2021. Here, Filip looks at state management (including integration with various reactive frameworks), animations, and creating reusable composables.
Sebastian Lobato Genco created the Resaca library that I mentioned last week. In this post, Sebastian explains how to set up non-visual Compose tests using Robolectric, for testing infrastructure composables like the ones in Resaca.
Ataul Munim walks us through customizing the semantic nodes for our composables, as those nodes drive accessibility features like TalkBack. In particular, Ataul explores replacing a bunch of individual semantic nodes with ones representing logical groups of composables, to simplify navigation for those using accessibility services.
Rebecca Stockbridge warns us that
Text() (a common composable) and
(a far less common composable) have different default font characteristics, particularly
font size. Rebecca wandered through their respective implementations to track down
where the font sizes get defined and why they differ.
Here, I lay out a set of candidate criteria to use when evaluating the vast array of possible options for navigation frameworks in Compose UI apps. Note: I do not make an actual recommendation, because how I weight criteria could very easily differ from how you would weight them.
Other Interesting Links
- Medium: Requesting Multiple Permissions in Jetpack Compose
- Medium: Add a developers menu to your Compose app with Tweaks
- Medium: Jetpack Compose: Detect the number of fingers touching the screen
- Medium: Highlight filtered Text in Compose While Using Search
- Creating a Flipped Box Card in Android Jetpack Compose
- Creating a Custom Animated Shimmer Effect with Jetpack Compose
- Video: Intro to Animating things with Jetpack Compose
- Medium: Jetpack Compose Side Effects Made Easy
- Medium: Correlating Jetpack Compose Side Effects
- App widgets in Android with Glance
- Medium: Custom Jetpack Compose Chips
- Medium: Remember, Remember Jetpack Compose
- Medium: Jetpack Compose — Pulsating Circles Animation
- Medium: ViewPager in Jetpack Compose with dot indicators (within minutes)
- Jetpack Compose Is A Real Game Changer for Android Development
- Medium: Jetpack compose — A primer
100% pure code!
Stephen Vinouze created a progress bar that shows distinct segments in its progress, such as for indicating various steps along the way for some overall operation to complete. See this blog post for more!
Other Interesting Links
- GitHub: hiteshchopra11 / JetCalendarView
- GitHub: timeline-notes / compose-code-editor
- GitHub: danchoo21 / compose-glide-image
- GitHub: umutsoysl / ComposeCreditCardView
…And One More Thing
Creating PDF files is a remarkably popular thing to do, even in 2022, and even on phones. A lot of questions pop up in Stack Overflow from Android developers trying to figure out how to create PDFs. Many try using Android’s printing framework, which is not designed to create PDF files as much as it is designed to create PDFs for printing. Some work with the iText PDF library, which is a fine library but whose license (GPL) causes problems for some projects. Few seem to be using Relatively few seem to use Apache PdfBox by way of Tom Roush’s Android port, though that may be a mix of project obscurity and limited documentation.
Given that we have composables for lots of UI targets, I wonder if and when somebody will try creating Compose for PDF.
Skia — the 2D graphics layer that powers Compose for Android, Compose for Desktop, some of Compose for Web, and maybe Compose for iOS — already has a PDF backend called SkPDF. In theory, Skiko — the Kotlin Skia wrapper — could write to SkPDF. With luck and work, the existing Compose UI layer could be used to create PDF content. What would remain would be surfacing PDF-specific constructs, such as “start a new page”.
Overall, creating PDFs might no so much exercise Compose as it would exercise the UI logic baked into Compose UI. Developers will be more familiar with that API than those of iText or PdfBox, so in theory it might be easier for them to create PDFs using composables they already know. There might be ways to better leverage Compose, such as using recomposition to advance to the next page in the document.
Even if using SkPDF proved to be impractical, creating a composable library atop of PdfBox might make PDF generation be more approachable to more Kotlin developers, particularly from within Android apps.
Is this practical? I don’t know. PDF generation is enough of a pain point, though, that it would be interesting if somebody gives this a try.
- 2023-09-12: Compose 1.5.1! Glance 1.0.0! Compose Multiplatform! Themes! Photos! Coachmarks! A bit of CommonsWare history! And @firstname.lastname@example.org tells us what not to do!
- 2023-09-05: Compose Compiler 1.5.3! Compose Multiplatform 1.5.0! @email@example.com on greyscaling composables! @firstname.lastname@example.org on Espresso testing with Compose interop! Scrollbars! AnnotatedString!
- 2023-08-29: Compose Compiler 1.5.2! Compose and Wear Compose alphas! Capture composables to bitmaps! Testing! Recomposition! Compose Multiplatform! And... Accompanist is downsizing?!?