Reconciler¶
Diffs successive virtual trees and applies the smallest set of native
mutations that bring the on-screen view tree in line with the new
description. The reconciler is platform-agnostic; it talks to native
widgets exclusively through the
NativeViewRegistry.
Virtual-tree reconciler.
Maintains a tree of VNode objects
(each wrapping a native view) and diffs incoming
Element trees to apply the minimal set of
native mutations.
Supports:
- Native elements (
typeis a string like"Text"). - Function components (
typeis a callable decorated withcomponent). Their hook state is preserved across renders. - Provider elements (
type == "__Provider__"), which push and pop context values during tree traversal. - Error boundary elements (
type == "__ErrorBoundary__"), which catch exceptions in child subtrees and render a fallback. - Key-based child reconciliation for stable identity across re-renders.
- Post-render effect flushing. After each mount or reconcile pass, all queued effects are executed so they see the committed native tree.
- Layout pass: after every commit, a parallel
LayoutNodetree is built from the committed VNodes and fed throughcalculate_layout; the resulting per-node frames are applied via the backend'sset_frame. The viewport size is supplied by the screen host viaset_viewport_size.
Classes:
| Name | Description |
|---|---|
VNode |
A mounted |
Reconciler |
Create, diff, and patch native view trees from |
VNode
¶
A mounted Element plus its native view.
The reconciler walks parallel trees of VNode and incoming
Element to compute the minimal set of native mutations.
Attributes:
| Name | Type | Description |
|---|---|---|
element |
The |
|
native_view |
The platform-native view (e.g., an Android |
|
children |
Ordered list of child |
|
hook_state |
Any
|
The component's
|
Reconciler
¶
Reconciler(backend: Any)
Create, diff, and patch native view trees from Element descriptors.
After each mount or
reconcile call the
reconciler walks the committed tree and flushes all pending effects
so effect callbacks run after native mutations are applied.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend
|
Any
|
An object implementing the native-view protocol
( |
required |
Methods:
| Name | Description |
|---|---|
mount |
Build native views from |
reconcile |
Diff |
set_viewport_size |
Update the viewport size and re-run layout if it changed. |
compute_layout_for_test |
Build and compute a layout tree without touching the backend. |
mount
¶
reconcile
¶
set_viewport_size
¶
Update the viewport size and re-run layout if it changed.
Called by the screen host whenever the platform reports a new
container size (Android: onLayoutChange; iOS:
viewDidLayoutSubviews). The first call after mount
triggers the initial layout pass; subsequent identical
sizes are no-ops.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
width
|
float
|
Viewport width in points. |
required |
height
|
float
|
Viewport height in points. |
required |
compute_layout_for_test
¶
compute_layout_for_test(viewport_width: float, viewport_height: float) -> Optional[LayoutNode]
Build and compute a layout tree without touching the backend.
Test helper that returns the synthetic viewport LayoutNode
with all descendants positioned. Returns None if no tree
has been mounted yet.
Next steps¶
- Read the high-level walkthrough in Reconciliation.
- See how native widgets are registered in Native views.