Course contentsShow
← React Native
Lesson 16 of 1,5551. The React Native ArchitectureFree lesson

The Shadow Tree Architecture

You will be able to visualize how the Shadow Tree maintains the virtual layout representation of the native UI.

In this lesson, you will learn how the Shadow Tree acts as a blueprint to help React Native translate your JavaScript components into real pixels on a screen.

The Virtual Blueprint

When you write code like <View style={{ width: 100 }} />, React Native doesn't immediately draw a box on your phone. Instead, it creates a lightweight object in JavaScript that describes what you want. This description is sent over to the native side, where React Native maintains a Shadow Tree.

Think of the Shadow Tree as a Virtual Layout Model. It is a tree structure residing in memory (on the native side) that mirrors your React component hierarchy. Each node in this tree corresponds to a component in your UI, but instead of containing actual pixels, it contains "layout constraints"—properties like width, height, padding, and flexbox instructions.

Why do we need a separate tree?

The Shadow Tree exists specifically to handle the "math" of your UI without blocking the main UI thread.

  1. Calculation: The Shadow Tree works with the Yoga layout engine (which we discussed in the previous lesson) to calculate the exact x, y, width, and height of every single element in your app.
  2. Comparison: When your state changes, React creates a new "draft" of the tree. The system compares the new tree with the current one to see exactly what moved or resized.
  3. Commitment: Once the calculations are finished, the final layout results are "committed" to the native UI manager, which then performs the heavy lifting of updating the actual views (like UIView on iOS or android.view on Android).
// A simple React component
<View style={{ flex: 1 }}>
  <Text>Hello!</Text>
</View>

/* 
  Shadow Tree Representation:
  - RootNode (flex: 1)
    - TextNode (content: "Hello!")
*/

By keeping this Shadow Tree separate, React Native can perform complex layout math off the main thread, ensuring that your app’s interface remains smooth even while the UI is being recalculated. The Shadow Tree is essentially the "architect" that hands the finalized blueprints to the "builders" (the native UI components) so they know exactly where to place everything.

Key Takeaway: The Shadow Tree is an off-thread data structure that calculates the geometric blueprint of your app, ensuring layout logic doesn't stutter the user interface.