Square Aug 10, 2021

Jetpack Compose Support in Workflow

Article Summary

Zach Klippenstein from Square reveals how they bridged their state machine architecture with Google's declarative UI toolkit—a year before Compose hit 1.0.

Square's Point of Sale apps run on Workflow, a library that treats business logic as declarative state machines. When Jetpack Compose emerged, they faced a challenge: integrate a radically new UI paradigm without breaking their existing architecture. This deep dive documents their experimental journey through Compose's beta period, solving problems around navigation lifecycles, state persistence, and composition linking.

Key Takeaways

Critical Insight

Square built a complete Compose integration for Workflow that maintains unidirectional data flow while enabling bidirectional interop between Compose and View-based screens.

The article reveals a potential performance trap in their rendering model that even Compose's optimizations can't fully solve.

About This Article

Problem

Square's Workflow library expected the view layer to intelligently diff changes to view models. Instead, many developers writing XML layouts and direct View APIs manually diffed changes themselves, which led to inefficient views that didn't take advantage of declarative UI benefits.

Solution

Zach Klippenstein's team built composedViewFactory() and WorkflowRendering composables that handle diffing automatically through Compose's snapshot state system. This removed the need for manual change detection and let them use Compose's built-in optimization mechanisms.

Impact

Square got bidirectional interop between Compose and View-based screens while keeping unidirectional data flow. This let them adopt Compose gradually across their Point of Sale apps without rewriting all their existing business logic.

Recent from Square

Related Articles