ComponentTree

Represents a tree of components and controls their life cycle. ComponentTree takes in a single root component and recursively invokes its OnCreateLayout to create a tree of components. ComponentTree is responsible for refreshing the mounted state of a component with new props.

The usual use case for ComponentTree is:

ComponentTree component = ComponentTree.create(context, MyComponent.create());
myHostView.setRoot(component);

Types

Link copied to clipboard
class Builder

A builder class that can be used to create a ComponentTree.

Link copied to clipboard
object Companion
Link copied to clipboard
fun interface MeasureListener
Link copied to clipboard

Listener that will be notified when a new LayoutState is computed and ready to be committed to this ComponentTree.

Properties

Link copied to clipboard
open override var committedTreeState: TreeState?

The default TreeState needed by the StateProvider when there's no active scope in flight.

Link copied to clipboard
Link copied to clipboard

Property accessor for effectHandler, for backward compatibility with test code.

Link copied to clipboard
val id: Int
Link copied to clipboard

Whether this updater implements the same-frame animation invalidation path.

Link copied to clipboard
open override var isFirstMount: Boolean
Link copied to clipboard

Returns whether incremental mount is enabled or not in this component.

Link copied to clipboard
open override val isReleased: Boolean
Link copied to clipboard
@get:JvmName(name = "lithoViewProperty")
val lithoView: LithoView?

Kotlin property alias for _lithoView.

Link copied to clipboard
Link copied to clipboard
@get:JvmName(name = "mainThreadLayoutStateProperty")
val mainThreadLayoutState: LayoutState?

Kotlin property alias for _mainThreadLayoutState.

Link copied to clipboard
open override val mountedView: View?
Link copied to clipboard
@set:JvmName(name = "setRootProperty")
var root: Component?

Kotlin property for accessing and setting the root component.

Link copied to clipboard
open override var uiTreeState: TreeState?

The default stable TreeState needed by the StateProvider as a fallback for UI thread reads when there's no active scope in flight.

Functions

Link copied to clipboard

Transfers this tree's LithoSaveableStateRegistry to the caller so it can be supplied to a replacement tree with Builder.withLithoSaveableStateRegistry. The caller becomes responsible for closing the registry when the logical UI scope ends. Returns null when the tree has no saveable-state owner.

Link copied to clipboard

Provides a new instance of the TreeState that is initialized with the committed TreeState held by the ComponentTree.

Link copied to clipboard

The provided measureListener will be called when a valid layout is committed.

Link copied to clipboard
Link copied to clipboard

Applies a batch of animation-frame invalidations produced during a single AnimationController frame tick. Each invalidation re-renders the read-tracked consumers of its stateId; the animated value itself stays owned by its AnimatedValue.

Link copied to clipboard
open override fun applyLazyStateUpdatesForContainer(componentKey: GlobalKey, container: StateContainer, isLayoutState: Boolean): StateContainer
Link copied to clipboard

The layouts which this ComponentTree was currently calculating will be terminated before a valid result is computed. It's not safe to try to compute any layouts for this ComponentTree after that because it's in an incomplete state, so it needs to be released.

Link copied to clipboard
open override fun <T> canSkipStateUpdate(stateId: StateId, newValue: T?, isLayoutState: Boolean): Boolean
open override fun <T> canSkipStateUpdate(newValueFunction: (T) -> T, stateId: StateId, isLayoutState: Boolean): Boolean
Link copied to clipboard
fun checkWorkingRangeAndDispatch(position: Int, firstVisibleIndex: Int, lastVisibleIndex: Int, firstFullyVisibleIndex: Int, lastFullyVisibleIndex: Int)

Check if the any child components stored in LayoutState have entered/exited the working range, and dispatch the event to trigger the corresponding registered methods.

Link copied to clipboard
Link copied to clipboard
open override fun getCachedValue(cacheKey: HookGlobalKey, cachedValueInputs: Any, isLayoutState: Boolean): Any?

Returns a Cached value that is accessible across all re-render operations.

Link copied to clipboard
Link copied to clipboard
@JvmName(name = "getEffectHandlerNotNull")
fun getEffectHandler(): EffectHandler
Link copied to clipboard
open override fun getEventTrigger(triggerKey: Any): EventTrigger<*>?
open override fun getEventTrigger(handle: Handle, methodId: Int): EventTrigger<*>?
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Retrieves the tree property associated with the given key, if it exists in this ComponentTree

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
fun hasCompatibleLayout(widthSpec: Int, heightSpec: Int): Boolean
Link copied to clipboard

Whether this ComponentTree has been mounted at least once.

Link copied to clipboard
open override fun onErrorComponent(component: Component?)
Link copied to clipboard
Link copied to clipboard
open override fun putCachedValue(cacheKey: HookGlobalKey, cachedValueInputs: Any, cachedValue: Any?, isLayoutState: Boolean)

Stores a Cached value that will be accessible across all re-render operations.

Link copied to clipboard
fun release()

The contract is that in order to release a ComponentTree, you must do so from the main thread. Usually HostView will handle releasing, but if you never attach to a host view, then you should call release yourself.

Link copied to clipboard

Removes a previously-added listener. Providers that never retain listeners may no-op.

Link copied to clipboard
open override fun removePendingStateUpdate(key: GlobalKey, isLayoutState: Boolean)

Removes a state update that was previously enqueued if the state update has not been processed yet.

Link copied to clipboard
fun setDebugLogsBreadcrumb(breadcrumb: String?)

This method associates this ComponentTree debug logs with the given String This allows you to create an association of the ComponentTree with any identifier or sorts that enables you to trace the logs of this ComponentTree with the identifier.

Link copied to clipboard
fun setRoot(root: Component?)

Update the root component. This can happen in both attached and detached states. In each case we will run a layout and then proxy a message to the main thread to cause a relayout/invalidate.

Link copied to clipboard
fun setRootAndSizeSpecAsync(root: Component?, widthSpec: Int, heightSpec: Int)

Compute asynchronously a new layout with the given component root and sizes

fun setRootAndSizeSpecAsync(root: Component?, widthSpec: Int, heightSpec: Int, treePropContainer: TreePropContainer?)

Compute asynchronously a new layout with the given component root, sizes and stored TreePropContainer.

Link copied to clipboard
fun setRootAndSizeSpecSync(root: Component?, widthSpec: Int, heightSpec: Int)

Compute a new layout with the given component root and sizes

fun setRootAndSizeSpecSync(root: Component?, widthSpec: Int, heightSpec: Int, output: Size?)
fun setRootAndSizeSpecSync(root: Component?, widthSpec: Int, heightSpec: Int, output: Size?, treePropContainer: TreePropContainer?)
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
fun setSizeSpec(widthSpec: Int, heightSpec: Int)

Update the width/height spec. This is useful if you are currently detached and are responding to a configuration change. If you are currently attached then the HostView is the source of truth for width/height, so this call will be ignored.

fun setSizeSpec(widthSpec: Int, heightSpec: Int, output: Size?)

Same as setSizeSpec but fetches the resulting width/height in the given Size.

Link copied to clipboard
fun setSizeSpecAsync(widthSpec: Int, heightSpec: Int)
Link copied to clipboard
fun setVersionedRootAndSizeSpec(root: Component?, widthSpec: Int, heightSpec: Int, output: Size?, treePropContainer: TreePropContainer?, externalRootVersion: Int)
Link copied to clipboard
fun setVersionedRootAndSizeSpecAsync(root: Component?, widthSpec: Int, heightSpec: Int, output: Size?, treePropContainer: TreePropContainer?, externalRootVersion: Int)
Link copied to clipboard
open override fun updateHookStateAsync(stateId: StateId, updater: HookUpdater, attribution: String?, isLayoutState: Boolean)

Same as updateStateAsync but for Hook State.

Link copied to clipboard
open override fun updateHookStateSync(stateId: StateId, updater: HookUpdater, attribution: String?, isLayoutState: Boolean)

Same as updateStateSync but for Hook State.

Link copied to clipboard
fun updateLayoutThreadHandler(layoutThreadHandler: RunnableHandler?)

Provide custom RunnableHandler. If null is provided default one will be used for layouts.

Link copied to clipboard
fun updateStateAsync(componentKey: String, stateUpdate: StateContainer.StateUpdate, attribution: String?)

open override fun updateStateAsync(componentKey: GlobalKey, stateUpdate: StateContainer.StateUpdate, attribution: String?, isLayoutState: Boolean)

Enqueues a state update that will schedule a new render on a Thread controlled by the Litho infrastructure.

Link copied to clipboard
open override fun updateStateLazy(componentKey: GlobalKey, stateUpdate: StateContainer.StateUpdate, isLayoutState: Boolean)

Enqueues a state update that will not schedule a new render. The new state will immediately be visible in Event Handlers and it will be visible in the next render phase.

Link copied to clipboard
open override fun updateStateSync(componentKey: GlobalKey, stateUpdate: StateContainer.StateUpdate, attribution: String?, isLayoutState: Boolean)

Enqueues a state update that will schedule a new render on the calling thread at the end of its current run-loop. It is expected that the calling thread has an active Looper.