Mobile Development 15 min read

Litho: Declarative Android UI Framework – Principles, Usage, and Performance

Litho, Facebook’s declarative Android UI framework, lets developers define components with immutable props and asynchronous layout, flattening view hierarchies and enabling fine‑grained reuse to boost scroll performance and cut memory usage, though it requires custom component code and lacks a real‑time preview.

Meituan Technology Team
Meituan Technology Team
Meituan Technology Team
Litho: Declarative Android UI Framework – Principles, Usage, and Performance

1. What is Litho?

Litho is a declarative framework released by Facebook for building efficient Android UI, especially complex RecyclerView lists. It improves scroll performance and reduces memory usage.

Litho lets you build UI with components instead of traditional Android views. A component is a function that takes immutable props and returns a component hierarchy.

2. Using Litho

2.1 Differences from native Android

Traditional Android defines layouts in XML and inflates them in Activities/Fragments. Litho defines UI declaratively in Java using annotated components.

2.2 Custom components

Components (called Component) are created via @LayoutSpec or @MountSpec annotations. LayoutSpec generates layout components (similar to ViewGroup); MountSpec generates mount components that render a View or Drawable.

Key lifecycle annotations include @OnPrepare, @OnMeasure, @OnBoundsDefined, @OnCreateMountContent, @OnMount, @OnBind, @OnUnBind, @OnUnmount.

2.2.1 Component specifications

LayoutSpec requires @LayoutSpec and @OnCreateLayout; MountSpec requires @MountSpec and @OnCreateMountContent.

2.2.2 Props and State

Props are immutable parameters annotated with @Prop; State is mutable internal data managed by the component.

3. Features and underlying principles

3.1 Declarative components

Litho’s API is inspired by React; components describe UI via immutable props.

3.2 Asynchronous layout

Layout and measurement are performed off the UI thread, reducing jank in complex lists.

3.3 Flat view hierarchy

Litho flattens the view tree using Yoga for layout calculation and renders most components with lightweight Drawables instead of Views.

3.4 Fine‑grained reuse

Components are recycled at a granular level, improving memory efficiency compared with native RecyclerView view holders.

4. Practice at Meituan

Meituan integrates Litho as the rendering engine for its MTFlexbox dynamic layout system, achieving noticeable memory and FPS improvements in the Meituan app.

5. Summary

Litho brings React‑style declarative UI to Android, offering performance gains but requiring custom component development and lacking real‑time preview.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Mobile DevelopmentAndroidDeclarative UIRecyclerViewLitho
Meituan Technology Team
Written by

Meituan Technology Team

Over 10,000 engineers powering China’s leading lifestyle services e‑commerce platform. Supporting hundreds of millions of consumers, millions of merchants across 2,000+ industries. This is the public channel for the tech teams behind Meituan, Dianping, Meituan Waimai, Meituan Select, and related services.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.