public class ComponentContext
extends java.lang.Object
implements java.lang.Cloneable
Constructor and Description |
---|
ComponentContext(ComponentContext context,
TreeProps treeProps) |
ComponentContext(Context context) |
ComponentContext(Context context,
java.lang.String logTag,
ComponentsLogger logger)
Constructor that can be used to receive log data from components.
|
ComponentContext(Context context,
java.lang.String logTag,
ComponentsLogger logger,
TreeProps treeProps) |
Modifier and Type | Method and Description |
---|---|
StateContainer |
applyLazyStateUpdatesForContainer(StateContainer container) |
long |
calculateLayoutOutputId(java.lang.String componentKey,
int type)
Calculates a returns a unique ID for a given component key and output type.
|
void |
clearCalculationStateContext() |
protected ComponentContext |
clone() |
<T extends View> |
findViewWithTag(java.lang.Object tag)
A utility function to find the View with a given tag under the current Component's LithoView.
|
Context |
getAndroidContext() |
Context |
getApplicationContext() |
java.lang.Object |
getCachedValue(java.lang.Object cachedValueInputs) |
int |
getColor(int id) |
Component |
getComponentScope() |
EventHandler<ErrorEvent> |
getErrorEventHandler() |
java.lang.String |
getGlobalKey() |
LayoutStateContext |
getLayoutStateContext() |
TreeFuture |
getLayoutStateFuture() |
int |
getLayoutVersion() |
ComponentsLogger |
getLogger() |
java.lang.String |
getLogTag() |
Looper |
getMainLooper() |
static RunnableHandler |
getMountContentPreallocationHandler(ComponentContext c) |
<T> T |
getParentTreeProp(java.lang.Class<T> key) |
TreeProps |
getParentTreeProps() |
RenderStateContext |
getRenderStateContext() |
ResourceCache |
getResourceCache() |
ResourceResolver |
getResourceResolver() |
Resources |
getResources() |
ScopedComponentInfo |
getScopedComponentInfo() |
java.lang.String |
getString(int resId) |
java.lang.String |
getString(int resId,
java.lang.Object... formatArgs) |
java.lang.CharSequence |
getText(int resId) |
<T> T |
getTreeProp(java.lang.Class<T> key) |
TreeProps |
getTreeProps() |
TreeProps |
getTreePropsCopy()
Obtain a copy of the tree props currently held by this context.
|
static boolean |
isIncrementalMountEnabled(ComponentContext c)
Checks if incremental mount is enabled given a ComponentContext, so you can throw an error if
you require that incremental mount is enabled (e.g.
|
protected boolean |
isParentTreePropsCloned() |
boolean |
isReconciliationEnabled() |
static boolean |
isVisibilityProcessingEnabled(ComponentContext c) |
static ComponentContext |
makeCopyForNestedTree(ComponentContext parentTreeContext)
Creates a new ComponentContext based on the given ComponentContext, propagating log tag,
logger, and tree props.
|
<E> EventHandler<E> |
newEventHandler(int id,
java.lang.Object[] params) |
TypedArray |
obtainStyledAttributes(int[] attrs,
int defStyleAttr) |
void |
putCachedValue(java.lang.Object cachedValueInputs,
java.lang.Object cachedValue) |
void |
setLayoutStateContext(LayoutStateContext layoutStateContext) |
void |
setLayoutStateContextForTesting() |
void |
setParentTreeProps(TreeProps treeProps) |
protected void |
setParentTreePropsCloned(boolean isParentTreePropsCloned) |
void |
setRenderStateContext(RenderStateContext renderStateContext) |
RenderStateContext |
setRenderStateContextForTests()
For test usage.
|
void |
setTreeProps(TreeProps treeProps) |
void |
updateStateAsync(StateContainer.StateUpdate stateUpdate,
java.lang.String attribution)
Notify the Component Tree that it needs to asynchronously perform a state update.
|
void |
updateStateLazy(StateContainer.StateUpdate stateUpdate) |
void |
updateStateSync(StateContainer.StateUpdate stateUpdate,
java.lang.String attribution)
Notify the Component Tree that it needs to synchronously perform a state update.
|
void |
updateStateWithTransition(StateContainer.StateUpdate stateUpdate,
java.lang.String attribution) |
static ComponentContext |
withComponentScope(ComponentContext parentContext,
Component scope,
java.lang.String globalKey)
Creates a new ComponentContext instance scoped to the given component and sets it on the
component.
|
static ComponentContext |
withComponentTree(ComponentContext context,
ComponentTree componentTree)
Creates a new ComponentContext instance and sets the
ComponentTree on the component. |
public ComponentContext(Context context)
public ComponentContext(Context context, java.lang.String logTag, ComponentsLogger logger)
ComponentsLogger
for the type of events you can listen for.context
- Android context.logTag
- a log tag to be used with the logger.logger
- a lifecycle logger to be used.public ComponentContext(Context context, java.lang.String logTag, ComponentsLogger logger, TreeProps treeProps)
public ComponentContext(ComponentContext context, TreeProps treeProps)
public static ComponentContext withComponentTree(ComponentContext context, ComponentTree componentTree)
ComponentTree
on the component.context
- context scoped to the parent componentcomponentTree
- component tree associated with the newly created contextpublic static ComponentContext withComponentScope(ComponentContext parentContext, Component scope, java.lang.String globalKey)
parentContext
- context scoped to the parent componentscope
- component associated with the newly created scoped contextpublic static ComponentContext makeCopyForNestedTree(ComponentContext parentTreeContext)
public void setLayoutStateContext(LayoutStateContext layoutStateContext)
public void clearCalculationStateContext()
public void setLayoutStateContextForTesting()
public RenderStateContext setRenderStateContextForTests()
public void setRenderStateContext(RenderStateContext renderStateContext)
public final Context getAndroidContext()
public final Context getApplicationContext()
public Resources getResources()
public ResourceResolver getResourceResolver()
public final Looper getMainLooper()
public java.lang.CharSequence getText(int resId)
public java.lang.String getString(int resId)
public java.lang.String getString(int resId, java.lang.Object... formatArgs)
public int getColor(int id)
public Component getComponentScope()
public java.lang.String getGlobalKey()
public EventHandler<ErrorEvent> getErrorEventHandler()
public TreeFuture getLayoutStateFuture()
public void updateStateSync(StateContainer.StateUpdate stateUpdate, java.lang.String attribution)
stateUpdate
- state update to performpublic void updateStateAsync(StateContainer.StateUpdate stateUpdate, java.lang.String attribution)
stateUpdate
- state update to performpublic void updateStateWithTransition(StateContainer.StateUpdate stateUpdate, java.lang.String attribution)
public void updateStateLazy(StateContainer.StateUpdate stateUpdate)
public StateContainer applyLazyStateUpdatesForContainer(StateContainer container)
public TypedArray obtainStyledAttributes(int[] attrs, int defStyleAttr)
public java.lang.String getLogTag()
public ComponentsLogger getLogger()
public <T extends View> T findViewWithTag(java.lang.Object tag)
As with View.findViewWithTag in general, this must be called on the main thread.
Note that null may be returned if the associated View doesn't exist or isn't mounted: with incremental mount turned on (which is the default), if the component is off-screen, it won't be mounted.
Finally, note that you should never hold a reference to the view returned by this function as Litho may unmount your Component and mount it to a different View.
public long calculateLayoutOutputId(java.lang.String componentKey, int type)
ComponentContext must have a ComponentTree instance.
componentKey
- The component keytype
- The output type @see OutputUnitTypepublic void setTreeProps(TreeProps treeProps)
public void setParentTreeProps(TreeProps treeProps)
public TreeProps getTreeProps()
public TreeProps getParentTreeProps()
protected boolean isParentTreePropsCloned()
protected void setParentTreePropsCloned(boolean isParentTreePropsCloned)
public <T> T getTreeProp(java.lang.Class<T> key)
public <T> T getParentTreeProp(java.lang.Class<T> key)
public TreeProps getTreePropsCopy()
public int getLayoutVersion()
public ResourceCache getResourceCache()
public <E> EventHandler<E> newEventHandler(int id, java.lang.Object[] params)
public java.lang.Object getCachedValue(java.lang.Object cachedValueInputs)
public void putCachedValue(java.lang.Object cachedValueInputs, java.lang.Object cachedValue)
public static boolean isIncrementalMountEnabled(ComponentContext c)
public static RunnableHandler getMountContentPreallocationHandler(ComponentContext c)
public static boolean isVisibilityProcessingEnabled(ComponentContext c)
public boolean isReconciliationEnabled()
public LayoutStateContext getLayoutStateContext()
public RenderStateContext getRenderStateContext()
public ScopedComponentInfo getScopedComponentInfo()
protected ComponentContext clone()
clone
in class java.lang.Object