public abstract class ComponentLifecycle extends Object implements EventDispatcher, EventTriggerTarget
ComponentLifecycle
is a stateless singleton object that defines how Component
instances calculate their layout bounds and mount elements, among other things. This is the
base class from which all new component types inherit.
In most cases, the ComponentLifecycle
class will be automatically generated by the
annotation processor at build-time based on your spec class and you won't have to deal with
it directly when implementing new component types.Modifier and Type | Class and Description |
---|---|
static class |
ComponentLifecycle.MountType |
static interface |
ComponentLifecycle.RenderData
A per-Component-class data structure to keep track of some of the last mounted @Prop/@State
params a component was rendered with.
|
static interface |
ComponentLifecycle.StateContainer |
static interface |
ComponentLifecycle.StateUpdate |
Modifier | Constructor and Description |
---|---|
protected |
ComponentLifecycle() |
Modifier and Type | Method and Description |
---|---|
Object |
acceptTriggerEvent(EventTrigger eventTrigger,
Object eventState,
Object[] params) |
protected <T> Diff<T> |
acquireDiff(T previousValue,
T nextValue) |
protected Output |
acquireOutput() |
protected void |
applyPreviousRenderData(Component component,
ComponentLifecycle.RenderData previousRenderData) |
protected boolean |
callsShouldUpdateOnMount() |
protected boolean |
canAcceptTrigger() |
protected boolean |
canMeasure()
Whether this
ComponentLifecycle is able to measure itself according
to specific size constraints. |
protected boolean |
canMountIncrementally()
Whether this
ComponentLifecycle mounts views that contain component-based
content that can be incrementally mounted e.g. |
protected boolean |
canPreallocate() |
protected void |
createInitialState(ComponentContext c,
Component<?> component) |
Object |
dispatchOnEvent(EventHandler eventHandler,
Object eventState) |
protected static EventTrigger |
getEventTrigger(ComponentContext c,
int methodId,
String key) |
protected int |
getExtraAccessibilityNodeAt(int x,
int y,
Component<?> component)
Get extra accessibility node id at a given point within the component.
|
protected int |
getExtraAccessibilityNodesCount(Component<?> component)
The number of extra accessibility nodes that this component wishes to provides to the
accessibility system.
|
ComponentLifecycle.MountType |
getMountType()
This indicates the type of the
Object that will be returned by
mount(com.facebook.litho.ComponentContext, java.lang.Object, com.facebook.litho.Component<?>) . |
protected TreeProps |
getTreePropsForChildren(ComponentContext c,
Component<?> component,
TreeProps previousTreeProps)
Updates the TreeProps map with outputs from all
OnCreateTreeProp methods. |
protected boolean |
hasState() |
protected boolean |
implementsAccessibility()
Whether this component will populate any accessibility nodes or events that are passed to it.
|
protected boolean |
implementsExtraAccessibilityNodes()
Whether this component will expose any virtual views to the accessibility framework
|
protected boolean |
isMountSizeDependent() |
protected boolean |
isPureRender() |
protected boolean |
needsPreviousRenderData() |
protected static <E> EventHandler<E> |
newEventHandler(Component<?> c,
String name,
int id,
Object[] params) |
protected static <E> EventHandler<E> |
newEventHandler(ComponentContext c,
String name,
int id,
Object[] params) |
protected static <E> EventTrigger<E> |
newEventTrigger(ComponentContext c) |
protected void |
onBind(ComponentContext c,
Object mountedContent,
Component<?> component) |
protected void |
onBoundsDefined(ComponentContext c,
ComponentLayout layout,
Component<?> component)
Called after the layout calculation is finished and the given
ComponentLayout
has its bounds defined. |
protected ComponentLayout |
onCreateLayout(ComponentContext c,
Component<?> component)
Generate a tree of
ComponentLayout representing the layout structure of
the Component and its sub-components. |
protected ComponentLayout |
onCreateLayoutWithSizeSpec(ComponentContext c,
int widthSpec,
int heightSpec,
Component<?> component) |
protected Object |
onCreateMountContent(ComponentContext context)
Create the object that will be mounted in the
LithoView . |
protected Transition |
onCreateTransition(ComponentContext c,
Component<?> component) |
protected void |
onLoadStyle(ComponentContext c,
Component<?> component) |
protected void |
onMeasure(ComponentContext c,
ComponentLayout layout,
int widthSpec,
int heightSpec,
Size size,
Component<?> component) |
protected int |
onMeasureBaseline(ComponentContext c,
int width,
int height)
Called during layout calculation to determine the baseline of a component.
|
protected void |
onMount(ComponentContext c,
Object convertContent,
Component<?> component)
Deploy all UI elements representing the final bounds defined in the given
ComponentLayout . |
protected void |
onPopulateAccessibilityNode(AccessibilityNodeInfoCompat accessibilityNode,
Component<?> component)
Populate an accessibility node with information about the component.
|
protected void |
onPopulateExtraAccessibilityNode(AccessibilityNodeInfoCompat accessibilityNode,
int extraNodeIndex,
int componentBoundsX,
int componentBoundsY,
Component<?> component)
Populate an extra accessibility node.
|
protected void |
onPrepare(ComponentContext c,
Component<?> component) |
protected void |
onUnbind(ComponentContext c,
Object mountedContent,
Component<?> component) |
protected void |
onUnmount(ComponentContext c,
Object mountedContent,
Component<?> component)
Unload UI elements associated with this component.
|
protected int |
poolSize() |
protected void |
populateTreeProps(Component<?> component,
TreeProps parentTreeProps)
Retrieves all of the tree props used by this Component from the TreeProps map
and sets the tree props as fields on the ComponentImpl.
|
protected ComponentLifecycle.RenderData |
recordRenderData(Component component,
ComponentLifecycle.RenderData toRecycle) |
protected void |
releaseDiff(Diff diff) |
protected void |
releaseOutput(Output output) |
protected boolean |
shouldUpdate(Component previous,
Component next)
Whether the component needs updating.
|
protected boolean |
shouldUseDisplayList()
Whether this drawable mount spec should cache its drawing in a display list.
|
protected void |
transferState(ComponentContext c,
ComponentLifecycle.StateContainer previousStateContainer,
Component component)
|
protected Output acquireOutput()
protected void releaseOutput(Output output)
protected final <T> Diff<T> acquireDiff(T previousValue, T nextValue)
protected void releaseDiff(Diff diff)
protected void populateTreeProps(Component<?> component, TreeProps parentTreeProps)
protected TreeProps getTreePropsForChildren(ComponentContext c, Component<?> component, TreeProps previousTreeProps)
OnCreateTreeProp
methods.protected ComponentLayout onCreateLayout(ComponentContext c, Component<?> component)
ComponentLayout
representing the layout structure of
the Component
and its sub-components. You should use
ComponentContext.newLayoutBuilder(int, int)
to build the layout tree.c
- The ComponentContext
to build a ComponentLayout
tree.component
- The component to create the ComponentLayout
tree from.protected ComponentLayout onCreateLayoutWithSizeSpec(ComponentContext c, int widthSpec, int heightSpec, Component<?> component)
protected void onPrepare(ComponentContext c, Component<?> component)
protected void onLoadStyle(ComponentContext c, Component<?> component)
protected void onBoundsDefined(ComponentContext c, ComponentLayout layout, Component<?> component)
ComponentLayout
has its bounds defined. You can use ComponentLayout.getX()
,
ComponentLayout.getY()
, ComponentLayout.getWidth()
, and
ComponentLayout.getHeight()
to get the size and position of the component
in the layout tree.c
- The Context
used by this component.layout
- The ComponentLayout
with defined position and size.component
- The Component
for this component.protected int onMeasureBaseline(ComponentContext c, int width, int height)
c
- The Context
used by this component.width
- The width of this component.height
- The height of this component.protected boolean canMeasure()
ComponentLifecycle
is able to measure itself according
to specific size constraints.protected void onMeasure(ComponentContext c, ComponentLayout layout, int widthSpec, int heightSpec, Size size, Component<?> component)
protected boolean canMountIncrementally()
ComponentLifecycle
mounts views that contain component-based
content that can be incrementally mounted e.g. if the mounted view has a
LithoView with incremental mount enabled.protected boolean shouldUseDisplayList()
protected Object onCreateMountContent(ComponentContext context)
LithoView
.context
- The ComponentContext
to be used to create the content.protected void onMount(ComponentContext c, Object convertContent, Component<?> component)
ComponentLayout
. Return either a Drawable
or a View
or
null
to be mounted.c
- The ComponentContext
to mount the component into.component
- The Component
for this component.protected void onUnmount(ComponentContext c, Object mountedContent, Component<?> component)
c
- The Context
for this mount operation.mountedContent
- The Drawable
or View
mounted by this component.component
- The Component
for this component.protected void onBind(ComponentContext c, Object mountedContent, Component<?> component)
protected void onUnbind(ComponentContext c, Object mountedContent, Component<?> component)
public ComponentLifecycle.MountType getMountType()
Object
that will be returned by
mount(com.facebook.litho.ComponentContext, java.lang.Object, com.facebook.litho.Component<?>)
.ComponentLifecycle.MountType
protected void onPopulateAccessibilityNode(AccessibilityNodeInfoCompat accessibilityNode, Component<?> component)
accessibilityNode
- node to populatecomponent
- The Component
for this component.protected void onPopulateExtraAccessibilityNode(AccessibilityNodeInfoCompat accessibilityNode, int extraNodeIndex, int componentBoundsX, int componentBoundsY, Component<?> component)
accessibilityNode
- node to populateextraNodeIndex
- index of extra nodecomponentBoundsX
- left bound of the mounted componentcomponentBoundsY
- top bound of the mounted componentcomponent
- The Component
for this component.protected int getExtraAccessibilityNodeAt(int x, int y, Component<?> component)
x
- x co-ordinate within the mounted componenty
- y co-ordinate within the mounted componentcomponent
- the Component
for this componentExploreByTouchHelper#INVALID_ID
protected int getExtraAccessibilityNodesCount(Component<?> component)
component
- the Component
for this componentprotected boolean implementsExtraAccessibilityNodes()
protected boolean implementsAccessibility()
protected void transferState(ComponentContext c, ComponentLifecycle.StateContainer previousStateContainer, Component component)
protected void createInitialState(ComponentContext c, Component<?> component)
public Object dispatchOnEvent(EventHandler eventHandler, Object eventState)
dispatchOnEvent
in interface EventDispatcher
@Nullable public Object acceptTriggerEvent(EventTrigger eventTrigger, Object eventState, Object[] params)
acceptTriggerEvent
in interface EventTriggerTarget
protected boolean isPureRender()
protected boolean callsShouldUpdateOnMount()
protected boolean isMountSizeDependent()
protected boolean canAcceptTrigger()
OnTrigger
*protected int poolSize()
protected boolean canPreallocate()
protected boolean shouldUpdate(Component previous, Component next)
For layout components, the framework will verify that none of the children of the component need updating, and that both components have the same number of children. Therefore this method just needs to determine any changes to the top-level component that would cause it to need to be updated (for example, a click handler was added).
For mount specs, the framework does nothing extra and this method alone determines whether the component is updated or not.
previous
- the previous component to compare against.next
- the component that is now in use.protected Transition onCreateTransition(ComponentContext c, Component<?> component)
TransitionSet
specifying how to animate this component to its new layout and
props.protected static <E> EventHandler<E> newEventHandler(ComponentContext c, String name, int id, Object[] params)
protected static <E> EventHandler<E> newEventHandler(Component<?> c, String name, int id, Object[] params)
protected static <E> EventTrigger<E> newEventTrigger(ComponentContext c)
@Nullable protected static EventTrigger getEventTrigger(ComponentContext c, int methodId, String key)
protected boolean needsPreviousRenderData()
protected ComponentLifecycle.RenderData recordRenderData(Component component, ComponentLifecycle.RenderData toRecycle)
protected void applyPreviousRenderData(Component component, ComponentLifecycle.RenderData previousRenderData)
protected boolean hasState()