public abstract class Component extends java.lang.Object implements java.lang.Cloneable, HasEventDispatcher, EventDispatcher, Equivalence<Component>
Modifier and Type | Class and Description |
---|---|
static class |
Component.Builder<T extends Component.Builder<T>> |
static class |
Component.ContainerBuilder<T extends Component.ContainerBuilder<T>> |
static class |
Component.MountType |
static interface |
Component.RenderData
A per-Component-class data structure to keep track of some of the last mounted @Prop/@State
params a component was rendered with.
|
Modifier | Constructor and Description |
---|---|
protected |
Component() |
protected |
Component(int identityHashCode)
This constructor should be called only if working with a manually crafted "special" Component.
|
Modifier and Type | Method and Description |
---|---|
protected boolean |
canMeasure()
Whether this
Component is able to measure itself according to
specific size constraints. |
protected java.lang.Object |
clone() |
java.lang.Object |
createMountContent(Context c) |
static void |
dispatchErrorEvent(ComponentContext c,
ErrorEvent e)
For internal use, only.
|
java.lang.Object |
dispatchOnEvent(EventHandler eventHandler,
java.lang.Object eventState) |
protected java.lang.Object |
dispatchOnEventImpl(EventHandler eventHandler,
java.lang.Object eventState) |
boolean |
equals(java.lang.Object obj) |
protected boolean |
excludeFromIncrementalMount() |
CommonProps |
getCommonProps() |
protected DynamicValue[] |
getDynamicProps() |
protected EventHandler<ErrorEvent> |
getErrorHandler() |
EventDispatcher |
getEventDispatcher()
Deprecated.
|
protected static EventTrigger |
getEventTrigger(ComponentContext c,
int id,
Handle handle) |
protected static EventTrigger |
getEventTrigger(ComponentContext c,
int id,
java.lang.String key) |
Handle |
getHandle() |
Component.MountType |
getMountType()
This indicates the type of the
Object that will be returned by com.facebook.litho.Component#mount . |
java.lang.String |
getSimpleName() |
static <T> T |
getTreePropFromParent(TreeProps parentTreeProps,
java.lang.Class<T> key) |
int |
getTypeId() |
protected boolean |
hasChildLithoViews()
Whether this
Component mounts views that contain component-based
content that can be incrementally mounted e.g. |
boolean |
hasClickHandlerSet() |
int |
hashCode() |
protected boolean |
implementsShouldUpdate() |
protected boolean |
isEqualivalentTreeProps(ComponentContext current,
ComponentContext next) |
protected boolean |
isEquivalentCommonProps(Component other) |
boolean |
isEquivalentProps(Component other,
boolean shouldCompareCommonProps)
Determine if this component has equivalent props to a given component.
|
boolean |
isEquivalentTo(Component other)
Compares this component to a different one to check if they are the same
|
boolean |
isEquivalentTo(Component other,
boolean shouldCompareCommonProps) |
static boolean |
isLayoutSpecWithSizeSpec(Component component) |
protected boolean |
isPureRender() |
static boolean |
isPureRender(Component component) |
Component |
makeShallowCopy() |
void |
measure(ComponentContext c,
int widthSpec,
int heightSpec,
Size outputSize)
Measure a component with the given
SizeSpec constrain. |
void |
measure(ComponentContext c,
int widthSpec,
int heightSpec,
Size outputSize,
boolean shouldCacheResult) |
void |
measureMightNotCacheInternalNode(ComponentContext c,
int widthSpec,
int heightSpec,
Size outputSize)
Deprecated.
|
protected static <E> EventHandler<E> |
newEventHandler(java.lang.Class<? extends Component> reference,
java.lang.String className,
ComponentContext c,
int id,
java.lang.Object[] params) |
protected static <E> EventTrigger<E> |
newEventTrigger(ComponentContext c,
Component component,
int methodId)
This variant is used to create an EventTrigger used to register this component as a target in
EventTriggersContainer |
protected static <E> EventTrigger<E> |
newEventTrigger(ComponentContext c,
java.lang.String childKey,
int methodId)
Deprecated.
|
protected java.lang.Object |
onCreateMountContent(Context context)
Create the object that will be mounted in the
LithoView . |
protected Transition |
onCreateTransition(ComponentContext c) |
protected void |
onLoadStyle(ComponentContext c) |
protected void |
onPopulateAccessibilityNode(ComponentContext c,
View host,
AccessibilityNodeInfoCompat accessibilityNode,
InterStagePropsContainer interStagePropsContainer)
Populate an accessibility node with information about the component.
|
protected void |
onPopulateExtraAccessibilityNode(ComponentContext c,
AccessibilityNodeInfoCompat accessibilityNode,
int extraNodeIndex,
int componentBoundsX,
int componentBoundsY,
InterStagePropsContainer interStagePropsContainer)
Populate an extra accessibility node.
|
protected PrepareResult |
prepare(RenderStateContext renderStateContext,
ComponentContext c) |
protected static void |
registerWorkingRange(ComponentContext scopedContext,
java.lang.String name,
WorkingRange workingRange,
Component component,
java.lang.String globalKey)
Store a working range information into a list for later use by
LayoutState . |
protected RenderResult |
render(RenderStateContext renderStateContext,
ComponentContext c,
int widthSpec,
int heightSpec)
Invokes the Component-specific render implementation, returning a RenderResult.
|
protected LithoNode |
resolve(RenderStateContext renderStateContext,
ComponentContext c)
Resolves the
ComponentLayout for the given Component . |
protected static <T> T |
retrieveValue(DynamicValue<T> dynamicValue) |
protected boolean |
shouldUpdate(Component previous,
StateContainer prevStateContainer,
Component next,
StateContainer nextStateContainer)
Whether the component needs updating.
|
java.lang.String |
toString() |
protected void |
transferState(StateContainer previousStateContainer,
StateContainer nextStateContainer)
|
protected boolean |
usesLocalStateContainer() |
static boolean |
willRender(ComponentContext c,
Component component)
Deprecated.
Using willRender is regarded as an anti-pattern, since it will load all classes
into memory in order to potentially decide not to use any of them.
|
protected Component()
protected Component(int identityHashCode)
Component()
instead.public final java.lang.Object createMountContent(Context c)
public final java.lang.Object dispatchOnEvent(EventHandler eventHandler, java.lang.Object eventState)
dispatchOnEvent
in interface EventDispatcher
protected java.lang.Object dispatchOnEventImpl(EventHandler eventHandler, java.lang.Object eventState)
public Component.MountType getMountType()
Object
that will be returned by com.facebook.litho.Component#mount
.Component.MountType
public final int getTypeId()
protected boolean canMeasure()
Component
is able to measure itself according to
specific size constraints.protected boolean excludeFromIncrementalMount()
protected boolean hasChildLithoViews()
Component
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 usesLocalStateContainer()
protected boolean implementsShouldUpdate()
protected boolean isPureRender()
protected RenderResult render(RenderStateContext renderStateContext, ComponentContext c, int widthSpec, int heightSpec)
#resolve(LayoutStateContext, ComponentContext)
'ed), as well as other
metadata from that render call such as transitions that should be applied.protected java.lang.Object onCreateMountContent(Context context)
LithoView
.context
- The Context
to be used to create the content.protected Transition onCreateTransition(ComponentContext c)
TransitionSet
specifying how to animate this component to its new layout and
props.protected void onLoadStyle(ComponentContext c)
protected void onPopulateAccessibilityNode(ComponentContext c, View host, AccessibilityNodeInfoCompat accessibilityNode, InterStagePropsContainer interStagePropsContainer)
accessibilityNode
- node to populateprotected void onPopulateExtraAccessibilityNode(ComponentContext c, AccessibilityNodeInfoCompat accessibilityNode, int extraNodeIndex, int componentBoundsX, int componentBoundsY, InterStagePropsContainer interStagePropsContainer)
accessibilityNode
- node to populateextraNodeIndex
- index of extra nodecomponentBoundsX
- left bound of the mounted componentcomponentBoundsY
- top bound of the mounted componentinterStagePropsContainer
- protected PrepareResult prepare(RenderStateContext renderStateContext, ComponentContext c)
protected LithoNode resolve(RenderStateContext renderStateContext, ComponentContext c)
ComponentLayout
for the given Component
.protected boolean isEqualivalentTreeProps(ComponentContext current, ComponentContext next)
protected boolean shouldUpdate(Component previous, StateContainer prevStateContainer, Component next, StateContainer nextStateContainer)
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 void transferState(StateContainer previousStateContainer, StateContainer nextStateContainer)
public static void dispatchErrorEvent(ComponentContext c, ErrorEvent e)
protected static EventTrigger getEventTrigger(ComponentContext c, int id, java.lang.String key)
protected static EventTrigger getEventTrigger(ComponentContext c, int id, Handle handle)
protected static <E> EventHandler<E> newEventHandler(java.lang.Class<? extends Component> reference, java.lang.String className, ComponentContext c, int id, java.lang.Object[] params)
protected static <E> EventTrigger<E> newEventTrigger(ComponentContext c, Component component, int methodId)
EventTriggersContainer
@Deprecated protected static <E> EventTrigger<E> newEventTrigger(ComponentContext c, java.lang.String childKey, int methodId)
public final CommonProps getCommonProps()
@Deprecated public final EventDispatcher getEventDispatcher()
getEventDispatcher
in interface HasEventDispatcher
public java.lang.String getSimpleName()
public final boolean hasClickHandlerSet()
public boolean isEquivalentProps(Component other, boolean shouldCompareCommonProps)
other
- the component to compare toprotected final boolean isEquivalentCommonProps(Component other)
public final boolean isEquivalentTo(Component other)
This is used to be able to skip rendering a component again. We avoid using the Object.equals(Object)
so we can optimize the code better over time since we don't have to
adhere to the contract required for a equals method.
isEquivalentTo
in interface Equivalence<Component>
other
- the component to compare topublic final boolean isEquivalentTo(Component other, boolean shouldCompareCommonProps)
public Component makeShallowCopy()
public final void measure(ComponentContext c, int widthSpec, int heightSpec, Size outputSize)
SizeSpec
constrain.c
- ComponentContext
.widthSpec
- Width SizeSpec
constrain.heightSpec
- Height SizeSpec
constrain.outputSize
- Size object that will be set with the measured dimensions.public final void measure(ComponentContext c, int widthSpec, int heightSpec, Size outputSize, boolean shouldCacheResult)
@Deprecated public final void measureMightNotCacheInternalNode(ComponentContext c, int widthSpec, int heightSpec, Size outputSize)
This is very inefficient because it throws away the InternalNode from measuring here and will have to remeasure when the component needs to be measured as part of a LayoutState. This will lead to suboptimal performance.
You probably don't need to use this. If you really need to measure your Component outside of a LayoutState calculation reach out to the Litho team to discuss an alternative solution.
If this is called during a LayoutState calculation, it will delegate to SpecGeneratedComponent.onMeasure(ComponentContext, ComponentLayout, int, int, Size,
InterStagePropsContainer)
, which does cache the measurement result for the duration of this
LayoutState.
protected final EventHandler<ErrorEvent> getErrorHandler()
public final Handle getHandle()
protected DynamicValue[] getDynamicProps()
public final java.lang.String toString()
toString
in class java.lang.Object
@Deprecated public static boolean willRender(ComponentContext c, Component component)
public static boolean isLayoutSpecWithSizeSpec(Component component)
public static boolean isPureRender(Component component)
protected static void registerWorkingRange(ComponentContext scopedContext, java.lang.String name, WorkingRange workingRange, Component component, java.lang.String globalKey)
LayoutState
.protected static <T> T retrieveValue(DynamicValue<T> dynamicValue)
public final int hashCode()
hashCode
in class java.lang.Object
public final boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
protected final java.lang.Object clone() throws java.lang.CloneNotSupportedException
clone
in class java.lang.Object
java.lang.CloneNotSupportedException
public static <T> T getTreePropFromParent(TreeProps parentTreeProps, java.lang.Class<T> key)