Zalando Mar 16, 2021

Flexbox Layout Behavior in Jetpack Compose

Article Summary

Zalando's engineering team is evaluating Jetpack Compose to replace Litho for their backend-driven mobile screens. But there's no Flexbox composable, so they mapped it themselves.

Andy Dyer from Zalando breaks down how CSS Flexbox layout concepts translate to Jetpack Compose (then in beta). Their fashion store apps rely on flexbox for dynamic UI, currently using Litho and Yoga layout engine.

Key Takeaways

Critical Insight

Most flexbox behaviors have direct Compose analogs, though some require creative workarounds or custom Layout composables.

The article includes a sample app repo and reveals what happened when they built their home screen during Hack Week.

About This Article

Problem

Zalando needed to map CSS Flexbox specification concepts to Jetpack Compose's layout system. Compose didn't have a unified Flexbox composable, though it offered multiple layout primitives with some flexbox-like behavior.

Solution

Andy Dyer documented how flexbox properties translate to Compose modifiers. The weight() modifier handles flex-grow, Modifier.preferredWidth(IntrinsicSize.Min) handles flex-shrink constraints, horizontalArrangement and verticalArrangement handle justify-content, and Box with align() handles absolute positioning.

Impact

Zalando built a performant Compose-powered home screen during Hack Week. Some flexbox concepts required creative workarounds, but Compose proved viable as a Litho successor for backend-driven screens.