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.TransitionContainer
Generated component's state container could implement this interface along with
StateContainer when componentspec specifies state update method with OnUpdateStateWithTransition annotation. |
Modifier and Type | Method and Description |
---|---|
Object |
acceptTriggerEvent(EventTrigger eventTrigger,
Object eventState,
Object[] params) |
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 |
canPreallocate() |
protected void |
createInitialState(ComponentContext c) |
Object |
createMountContent(Context 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,
Handle handle) |
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 treeProps)
Updates the TreeProps map with outputs from all
OnCreateTreeProp methods. |
protected boolean |
hasAttachDetachCallback() |
protected boolean |
hasChildLithoViews()
Whether this
ComponentLifecycle mounts views that contain component-based content that
can be incrementally mounted e.g. |
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 |
isLayoutSpecWithSizeSpecCheck() |
protected boolean |
isMountSizeDependent() |
protected boolean |
isPureRender() |
protected boolean |
needsPreviousRenderData() |
protected static <E> EventHandler<E> |
newEventHandler(Class<? extends Component> reference,
ComponentContext c,
int id,
Object[] params) |
protected static <E> EventTrigger<E> |
newEventTrigger(ComponentContext c,
String childKey,
int id,
Handle handle) |
protected void |
onAttached(ComponentContext c)
Called when the component is attached to the
ComponentTree . |
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 |
onDetached(ComponentContext c)
Called when the component is detached from the
ComponentTree . |
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 boolean |
onShouldCreateLayoutWithNewSizeSpec(ComponentContext context,
int newWidthSpec,
int newHeightSpec) |
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 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 |
shouldUseGlobalPool() |
protected void |
transferState(StateContainer previousStateContainer,
StateContainer nextStateContainer)
|
public Object acceptTriggerEvent(EventTrigger eventTrigger, Object eventState, Object[] params)
acceptTriggerEvent
in interface EventTriggerTarget
public Object createMountContent(Context c)
public Object dispatchOnEvent(EventHandler eventHandler, Object eventState)
dispatchOnEvent
in interface EventDispatcher
public ComponentLifecycle.MountType getMountType()
Object
that will be returned by mount(com.facebook.litho.ComponentContext, java.lang.Object)
.ComponentLifecycle.MountType
protected void applyPreviousRenderData(ComponentLifecycle.RenderData previousRenderData)
protected boolean callsShouldUpdateOnMount()
protected boolean canMeasure()
ComponentLifecycle
is able to measure itself according to specific size
constraints.protected boolean canPreallocate()
protected void createInitialState(ComponentContext c)
protected void dispatchOnEnteredRange(String name)
protected void dispatchOnExitedRange(String name)
protected 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 TreeProps getTreePropsForChildren(ComponentContext c, TreeProps treeProps)
OnCreateTreeProp
methods.protected boolean hasAttachDetachCallback()
OnAttached
or OnDetached
delegate
methods.protected boolean hasChildLithoViews()
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 hasState()
protected boolean implementsAccessibility()
protected boolean implementsExtraAccessibilityNodes()
protected boolean isLayoutSpecWithSizeSpecCheck()
true
iff the LayoutSpec
implements OnShouldCreateLayoutWithNewSizeSpec
to true
.protected boolean isMountSizeDependent()
protected boolean isPureRender()
protected boolean needsPreviousRenderData()
protected void onAttached(ComponentContext c)
ComponentTree
.c
- The ComponentContext
the Component was constructed with.protected void onBind(ComponentContext c, Object mountedContent)
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 Component onCreateLayout(ComponentContext c)
ComponentLayout
representing the layout structure of the Component
and its sub-components.c
- The ComponentContext
to build a ComponentLayout
tree.protected Component onCreateLayoutWithSizeSpec(ComponentContext c, int widthSpec, int heightSpec)
protected Object onCreateMountContent(Context context)
LithoView
.context
- The Context
to be used to create the content.protected MountContentPool onCreateMountContentPool()
protected Transition onCreateTransition(ComponentContext c)
TransitionSet
specifying how to animate this component to its new layout and
props.protected void onDetached(ComponentContext c)
ComponentTree
.c
- The ComponentContext
the Component was constructed with.protected void onError(ComponentContext c, Exception e)
c
- The ComponentContext
the Component was constructed with.e
- The exception caught.OnError
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)
c
- The Context
used by this component.width
- The width of this component.height
- The height of this component.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 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 void onPrepare(ComponentContext c)
protected boolean onShouldCreateLayoutWithNewSizeSpec(ComponentContext context, int newWidthSpec, int newHeightSpec)
protected void onUnbind(ComponentContext c, Object mountedContent)
protected void onUnmount(ComponentContext c, Object mountedContent)
c
- The Context
for this mount operation.mountedContent
- The Drawable
or View
mounted by this component.protected int poolSize()
protected void populateTreeProps(TreeProps parentTreeProps)
protected ComponentLifecycle.RenderData recordRenderData(ComponentLifecycle.RenderData toRecycle)
protected ComponentLayout resolve(ComponentContext c)
ComponentLayout
for the given Component
.protected boolean shouldAlwaysRemeasure()
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 boolean shouldUseGlobalPool()
protected void transferState(StateContainer previousStateContainer, StateContainer nextStateContainer)
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 static EventTrigger getEventTrigger(ComponentContext c, int id, String key)
protected static EventTrigger getEventTrigger(ComponentContext c, int id, Handle handle)
protected static <E> EventHandler<E> newEventHandler(Class<? extends Component> reference, ComponentContext c, int id, Object[] params)
protected static <E> EventTrigger<E> newEventTrigger(ComponentContext c, String childKey, int id, Handle handle)