public class ComponentTree extends java.lang.Object implements LithoLifecycleListener
The usual use case for ComponentTree
is:
ComponentTree component = ComponentTree.create(context, MyComponent.create());
myHostView.setRoot(component);
Modifier and Type | Class and Description |
---|---|
static class |
ComponentTree.Builder
A builder class that can be used to create a
ComponentTree . |
static interface |
ComponentTree.MeasureListener |
static interface |
ComponentTree.NewLayoutStateReadyListener
Listener that will be notified when a new LayoutState is computed and ready to be committed to
this ComponentTree.
|
Modifier and Type | Field and Description |
---|---|
static int |
INVALID_ID |
static int |
INVALID_LAYOUT_VERSION |
protected int |
mId |
static int |
STATE_UPDATES_IN_LOOP_THRESHOLD |
Modifier | Constructor and Description |
---|---|
protected |
ComponentTree(ComponentTree.Builder builder) |
Modifier and Type | Method and Description |
---|---|
TreeState |
acquireTreeState()
Provides a new instance of the
TreeState that is initialized with the TreeState held by
the ComponentTree. |
void |
addMeasureListener(ComponentTree.MeasureListener measureListener)
The provided measureListener will be called when a valid layout is commited.
|
void |
cancelLayoutAndReleaseTree() |
void |
checkWorkingRangeAndDispatch(int position,
int firstVisibleIndex,
int lastVisibleIndex,
int firstFullyVisibleIndex,
int lastFullyVisibleIndex)
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. |
void |
clearMeasureListener(ComponentTree.MeasureListener measureListener) |
RenderState |
consumePreviousRenderState()
Takes ownership of the
RenderState object from this ComponentTree - this allows the
RenderState to be persisted somewhere and then set back on another ComponentTree using the
ComponentTree.Builder . |
static ComponentTree.Builder |
create(ComponentContext context) |
static ComponentTree.Builder |
create(ComponentContext context,
Component.Builder<?> root) |
static ComponentTree.Builder |
create(ComponentContext context,
Component root) |
static ComponentTree.Builder |
create(ComponentContext context,
Component root,
LithoLifecycleProvider lifecycleProvider) |
static ComponentTree.Builder |
createNestedComponentTree(ComponentContext parentContext,
Component component)
Creates a ComponentTree nested inside the ComponentTree of the provided parentContext.
|
static int |
generateComponentTreeId() |
CalculationStateContext |
getCalculationStateContext() |
LayoutState |
getCommittedLayoutState() |
ComponentContext |
getContext() |
static Looper |
getDefaultLayoutThreadLooper() |
ErrorEventHandler |
getErrorEventHandler() |
RunnableHandler |
getLayoutThreadHandler() |
LithoLifecycleProvider |
getLifecycleProvider() |
static LithoLifecycleProvider |
getLifecycleProvider(ComponentContext context) |
LithoView |
getLithoView() |
ComponentsLogger |
getLogger() |
java.lang.String |
getLogTag() |
ComponentTree.NewLayoutStateReadyListener |
getNewLayoutStateReadyListener() |
java.lang.String |
getSimpleName() |
boolean |
hasCompatibleLayout(int widthSpec,
int heightSpec) |
boolean |
hasMounted()
Whether this ComponentTree has been mounted at least once.
|
boolean |
isFirstMount() |
boolean |
isIncrementalMountEnabled()
Returns whether incremental mount is enabled or not in this component.
|
boolean |
isReconciliationEnabled() |
boolean |
isReleased() |
boolean |
isReuseLastMeasuredNodeInComponentMeasureEnabled() |
boolean |
isSplitStateHandlersEnabled() |
boolean |
isSubscribedToLifecycleProvider() |
void |
onMovedToState(LithoLifecycleProvider.LithoLifecycle state) |
void |
release()
The contract is that in order to release a ComponentTree, you must do so from the main thread.
|
void |
setCalculationStateContext(CalculationStateContext stateContext) |
void |
setIsFirstMount(boolean isFirstMount) |
void |
setNewLayoutStateReadyListener(ComponentTree.NewLayoutStateReadyListener listener) |
void |
setRoot(Component root)
Update the root component.
|
void |
setRootAndSizeSpecAsync(Component root,
int widthSpec,
int heightSpec)
Compute asynchronously a new layout with the given component root and sizes
|
void |
setRootAndSizeSpecAsync(Component root,
int widthSpec,
int heightSpec,
TreeProps treeProps)
Compute asynchronously a new layout with the given component root, sizes and stored TreeProps.
|
void |
setRootAndSizeSpecSync(Component root,
int widthSpec,
int heightSpec)
Compute a new layout with the given component root and sizes
|
void |
setRootAndSizeSpecSync(Component root,
int widthSpec,
int heightSpec,
Size output) |
void |
setRootAndSizeSpecSync(Component root,
int widthSpec,
int heightSpec,
Size output,
TreeProps treeProps) |
void |
setRootAsync(Component root) |
void |
setSizeSpec(int widthSpec,
int heightSpec)
Update the width/height spec.
|
void |
setSizeSpec(int widthSpec,
int heightSpec,
Size output)
Same as
setSizeSpec(int, int) but fetches the resulting width/height in the given
Size . |
void |
setSizeSpecAsync(int widthSpec,
int heightSpec) |
void |
setVersionedRootAndSizeSpec(Component root,
int widthSpec,
int heightSpec,
Size output,
TreeProps treeProps,
int externalRootVersion) |
void |
setVersionedRootAndSizeSpecAsync(Component root,
int widthSpec,
int heightSpec,
Size output,
TreeProps treeProps,
int externalRootVersion) |
boolean |
shouldKeepLithoNodeAndLayoutResultTreeWithReconciliation() |
boolean |
shouldReuseOutputs() |
void |
subscribeToLifecycleProvider(LithoLifecycleProvider lifecycleProvider) |
void |
updateLayoutThreadHandler(RunnableHandler layoutThreadHandler)
Provide custom
RunnableHandler . |
public static final int INVALID_LAYOUT_VERSION
public static final int INVALID_ID
public static final int STATE_UPDATES_IN_LOOP_THRESHOLD
protected final int mId
protected ComponentTree(ComponentTree.Builder builder)
public void onMovedToState(LithoLifecycleProvider.LithoLifecycle state)
onMovedToState
in interface LithoLifecycleListener
public void subscribeToLifecycleProvider(LithoLifecycleProvider lifecycleProvider)
public boolean isSubscribedToLifecycleProvider()
public static ComponentTree.Builder create(ComponentContext context)
public static ComponentTree.Builder create(ComponentContext context, Component.Builder<?> root)
public static ComponentTree.Builder create(ComponentContext context, Component root)
public static ComponentTree.Builder create(ComponentContext context, Component root, LithoLifecycleProvider lifecycleProvider)
public void setCalculationStateContext(CalculationStateContext stateContext)
public CalculationStateContext getCalculationStateContext()
public void addMeasureListener(ComponentTree.MeasureListener measureListener)
measureListener
- public void clearMeasureListener(ComponentTree.MeasureListener measureListener)
public LayoutState getCommittedLayoutState()
public boolean hasMounted()
public boolean isFirstMount()
public void setIsFirstMount(boolean isFirstMount)
public void setNewLayoutStateReadyListener(ComponentTree.NewLayoutStateReadyListener listener)
public void updateLayoutThreadHandler(RunnableHandler layoutThreadHandler)
RunnableHandler
. If null is provided default one will be used for
layouts.public RunnableHandler getLayoutThreadHandler()
public ComponentTree.NewLayoutStateReadyListener getNewLayoutStateReadyListener()
public boolean hasCompatibleLayout(int widthSpec, int heightSpec)
public boolean isIncrementalMountEnabled()
public boolean shouldReuseOutputs()
public boolean isReconciliationEnabled()
public boolean isSplitStateHandlersEnabled()
public boolean isReuseLastMeasuredNodeInComponentMeasureEnabled()
public boolean shouldKeepLithoNodeAndLayoutResultTreeWithReconciliation()
public ErrorEventHandler getErrorEventHandler()
public void setRoot(Component root)
public void setRootAsync(Component root)
public void checkWorkingRangeAndDispatch(int position, int firstVisibleIndex, int lastVisibleIndex, int firstFullyVisibleIndex, int lastFullyVisibleIndex)
LayoutState
have entered/exited the working
range, and dispatch the event to trigger the corresponding registered methods.public void setSizeSpec(int widthSpec, int heightSpec)
public void setSizeSpec(int widthSpec, int heightSpec, Size output)
setSizeSpec(int, int)
but fetches the resulting width/height in the given
Size
.public void setSizeSpecAsync(int widthSpec, int heightSpec)
public void setRootAndSizeSpecAsync(Component root, int widthSpec, int heightSpec)
public void setRootAndSizeSpecAsync(Component root, int widthSpec, int heightSpec, TreeProps treeProps)
public void setRootAndSizeSpecSync(Component root, int widthSpec, int heightSpec)
public void setRootAndSizeSpecSync(Component root, int widthSpec, int heightSpec, Size output)
public void setRootAndSizeSpecSync(Component root, int widthSpec, int heightSpec, Size output, TreeProps treeProps)
public void setVersionedRootAndSizeSpec(Component root, int widthSpec, int heightSpec, Size output, TreeProps treeProps, int externalRootVersion)
public void setVersionedRootAndSizeSpecAsync(Component root, int widthSpec, int heightSpec, Size output, TreeProps treeProps, int externalRootVersion)
public LithoView getLithoView()
LithoView
associated with this ComponentTree if any. Since this is modified
on the main thread, it is racy to get the current LithoView off the main thread.public TreeState acquireTreeState()
TreeState
that is initialized with the TreeState held by
the ComponentTree.public static LithoLifecycleProvider getLifecycleProvider(ComponentContext context)
public LithoLifecycleProvider getLifecycleProvider()
public static ComponentTree.Builder createNestedComponentTree(ComponentContext parentContext, Component component)
SimpleNestedTreeLifecycleProvider
hooked with the parent's
lifecycle provider.parentContext
- context associated with the parent ComponentTree.component
- root of the new nested ComponentTree.public RenderState consumePreviousRenderState()
RenderState
object from this ComponentTree - this allows the
RenderState to be persisted somewhere and then set back on another ComponentTree using the
ComponentTree.Builder
. See RenderState
for more information on the purpose of this object.public void release()
public java.lang.String getSimpleName()
public static Looper getDefaultLayoutThreadLooper()
public boolean isReleased()
public ComponentContext getContext()
public ComponentsLogger getLogger()
public java.lang.String getLogTag()
public void cancelLayoutAndReleaseTree()
public static int generateComponentTreeId()