public abstract class ComponentLifecycle extends Object implements EventDispatcher, EventTriggerTarget
ComponentLifecycle
is extended by the Component
class and declare
methods used by a Component
instances to calculate their layout bounds
and mount elements, among other things. This is the base class from which all new component
types inherit.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 |
static interface |
ComponentLifecycle.TransitionContainer
Generated component's state container could implement this interface along with
ComponentLifecycle.StateContainer when componentspec specifies state update method with OnUpdateStateWithTransition annotation. |
Modifier | Constructor and Description |
---|---|
protected |
ComponentLifecycle(Object type)
This constructor should be called only if working with a manually crafted special Component.
|
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(ComponentLifecycle.RenderData previousRenderData) |
protected boolean |
callsShouldUpdateOnMount() |
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) |
Object |
createMountContent(ComponentContext c) |
static void |
dispatchErrorEvent(ComponentContext c,
ErrorEvent e)
For internal use, only.
|
static void |
dispatchErrorEvent(ComponentContext c,
Exception e)
Reraise an error event up the hierarchy so it can be caught by another component, or reach the
root and cause the application to crash.
|
protected void |
dispatchOnEnteredRange(String name) |
Object |
dispatchOnEvent(EventHandler eventHandler,
Object eventState) |
protected void |
dispatchOnExitedRange(String name) |
protected static EventTrigger |
getEventTrigger(ComponentContext c,
int id,
String key) |
protected int |
getExtraAccessibilityNodeAt(int x,
int y)
Get extra accessibility node id at a given point within the component.
|
protected int |
getExtraAccessibilityNodesCount()
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) . |
protected TreeProps |
getTreePropsForChildren(ComponentContext c,
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(ComponentContext c,
int id,
Object[] params) |
protected static <E> EventHandler<E> |
newEventHandler(Component c,
int id,
Object[] params) |
protected static <E> EventTrigger<E> |
newEventTrigger(ComponentContext c,
String childKey,
int id) |
protected void |
onBind(ComponentContext c,
Object mountedContent) |
protected void |
onBoundsDefined(ComponentContext c,
ComponentLayout layout)
Called after the layout calculation is finished and the given
ComponentLayout has its
bounds defined. |
protected Component |
onCreateLayout(ComponentContext c)
Generate a tree of
ComponentLayout representing the layout structure of the Component and its sub-components. |
protected Component |
onCreateLayoutWithSizeSpec(ComponentContext c,
int widthSpec,
int heightSpec) |
protected Object |
onCreateMountContent(Context context)
Create the object that will be mounted in the
LithoView . |
protected MountContentPool |
onCreateMountContentPool() |
protected Transition |
onCreateTransition(ComponentContext c) |
protected void |
onError(ComponentContext c,
Exception e)
Called to provide a fallback if a supported lifecycle method throws an exception.
|
protected void |
onLoadStyle(ComponentContext c) |
protected void |
onMeasure(ComponentContext c,
ComponentLayout layout,
int widthSpec,
int heightSpec,
Size size) |
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)
Deploy all UI elements representing the final bounds defined in the given
ComponentLayout . |
protected void |
onPopulateAccessibilityNode(View host,
AccessibilityNodeInfoCompat accessibilityNode)
Populate an accessibility node with information about the component.
|
protected void |
onPopulateExtraAccessibilityNode(AccessibilityNodeInfoCompat accessibilityNode,
int extraNodeIndex,
int componentBoundsX,
int componentBoundsY)
Populate an extra accessibility node.
|
protected void |
onPrepare(ComponentContext c) |
protected void |
onUnbind(ComponentContext c,
Object mountedContent) |
protected void |
onUnmount(ComponentContext c,
Object mountedContent)
Unload UI elements associated with this component.
|
protected int |
poolSize() |
protected void |
populateTreeProps(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(ComponentLifecycle.RenderData toRecycle) |
protected void |
releaseDiff(Diff diff) |
protected void |
releaseOutput(Output output) |
protected ComponentLayout |
resolve(ComponentContext c)
Resolves the
ComponentLayout for the given Component . |
protected boolean |
shouldAlwaysRemeasure() |
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)
|
protected ComponentLifecycle(Object type)
public Object createMountContent(ComponentContext c)
public static void dispatchErrorEvent(ComponentContext c, Exception e)
c
- The component context the error event was caught in.e
- The original exception.public static void dispatchErrorEvent(ComponentContext c, ErrorEvent e)
dispatchErrorEvent(ComponentContext, Exception)
instead.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(TreeProps parentTreeProps)
protected TreeProps getTreePropsForChildren(ComponentContext c, TreeProps previousTreeProps)
OnCreateTreeProp
methods.protected Component onCreateLayout(ComponentContext c)
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.protected Component onCreateLayoutWithSizeSpec(ComponentContext c, int widthSpec, int heightSpec)
protected ComponentLayout resolve(ComponentContext c)
ComponentLayout
for the given Component
.protected void onPrepare(ComponentContext c)
protected void onLoadStyle(ComponentContext c)
protected void onBoundsDefined(ComponentContext c, ComponentLayout layout)
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.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)
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(Context context)
LithoView
.context
- The Context
to be used to create the content.protected MountContentPool onCreateMountContentPool()
protected void onMount(ComponentContext c, Object convertContent)
ComponentLayout
. Return either a Drawable
or a View
or null
to be
mounted.c
- The ComponentContext
to mount the component into.protected void onUnmount(ComponentContext c, Object mountedContent)
c
- The Context
for this mount operation.mountedContent
- The Drawable
or View
mounted by this component.protected void onBind(ComponentContext c, Object mountedContent)
protected void onUnbind(ComponentContext c, Object mountedContent)
public ComponentLifecycle.MountType getMountType()
Object
that will be returned by mount(com.facebook.litho.ComponentContext, java.lang.Object)
.ComponentLifecycle.MountType
protected void onPopulateAccessibilityNode(View host, AccessibilityNodeInfoCompat accessibilityNode)
accessibilityNode
- node to populateprotected void onPopulateExtraAccessibilityNode(AccessibilityNodeInfoCompat accessibilityNode, int extraNodeIndex, int componentBoundsX, int componentBoundsY)
accessibilityNode
- node to populateextraNodeIndex
- index of extra nodecomponentBoundsX
- left bound of the mounted componentcomponentBoundsY
- top bound of the mounted componentprotected int getExtraAccessibilityNodeAt(int x, int y)
x
- x co-ordinate within the mounted componenty
- y co-ordinate within the mounted componentExploreByTouchHelper#INVALID_ID
protected int getExtraAccessibilityNodesCount()
protected boolean implementsExtraAccessibilityNodes()
protected boolean implementsAccessibility()
protected void transferState(ComponentContext c, ComponentLifecycle.StateContainer previousStateContainer)
protected void createInitialState(ComponentContext c)
protected void onError(ComponentContext c, Exception e)
c
- The ComponentContext
the Component was constructed with.e
- The exception caught.OnError
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 void dispatchOnEnteredRange(String name)
protected void dispatchOnExitedRange(String name)
protected boolean isPureRender()
protected boolean callsShouldUpdateOnMount()
protected boolean isMountSizeDependent()
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)
TransitionSet
specifying how to animate this component to its new layout and
props.protected static <E> EventHandler<E> newEventHandler(ComponentContext c, int id, Object[] params)
protected static <E> EventHandler<E> newEventHandler(Component c, int id, Object[] params)
protected static <E> EventTrigger<E> newEventTrigger(ComponentContext c, String childKey, int id)
@Nullable protected static EventTrigger getEventTrigger(ComponentContext c, int id, String key)
protected boolean needsPreviousRenderData()
protected ComponentLifecycle.RenderData recordRenderData(ComponentLifecycle.RenderData toRecycle)
protected void applyPreviousRenderData(ComponentLifecycle.RenderData previousRenderData)
protected boolean hasState()
protected boolean shouldAlwaysRemeasure()