ComponentContext

open class ComponentContext

A Context subclass for use within the Components framework. Contains extra bookkeeping information used internally in the library.

Constructors

Link copied to clipboard
constructor(context: Context, lithoConfiguration: LithoConfiguration? = null, treePropContainer: TreePropContainer? = null)

This constructors takes a Context. This should only be used to create ComponentTree

constructor(context: ComponentContext, treePropContainer: TreePropContainer? = context.treePropContainer)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
val resourceCache: ResourceCache?
Link copied to clipboard
val resourceResolver: ResourceResolver
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard
fun applyStyle(node: LithoNode, @AttrRes defStyleAttr: Int, @StyleRes defStyleRes: Int)
Link copied to clipboard

This method determine if transitions are enabled for the user. If the experiment is enabled for the user then they will get cached value else it will be determined using the utility method.

Link copied to clipboard

Wraps this existing ComponentContext in a ResourcesScope, for calling the ResourcesScope DSL (Row, Column, widgets such as Card) from code that already holds a ComponentContext but has no ambient ComponentScope — e.g. a @LayoutSpec helper or a builder-style function.

Link copied to clipboard
fun ComponentContext.boolAttr(@AttrRes attrResId: Int, @BoolRes defResId: Int = 0): Boolean

Return a boolean for an attribute resource ID.

Link copied to clipboard

Return a boolean for a resource ID.

Link copied to clipboard
fun calculateLayoutOutputId(componentKey: GlobalKey, type: Int): Long

Calculates a returns a unique ID for a given component key and output type. The IDs will be unique for components in the ComponentTree this ID generator is linked with. If an ID was already generated for a given component, the same ID will be returned. Otherwise, a new unique ID will be generated.

Link copied to clipboard
Link copied to clipboard

Return a ColorInt value, corresponding to an attribute resource ID. If given attribute ID can not be found, default color resource ID defResId is used.

Link copied to clipboard

Return a ColorInt value for a color resource ID.

Link copied to clipboard
fun <E> createEventHandler(id: Int, mode: EventHandlerRebindMode, params: Array<Any?>?, reference: Class<out Component>, source: String): EventHandler<E>
Link copied to clipboard
fun ComponentContext.dimenAttr(@AttrRes id: Int, @DimenRes defResId: Int = 0): Dimen

Return a dimen for an attribute resource ID.

Link copied to clipboard

Resolve a dimen resource ID as a Dimen value.

Link copied to clipboard

Retrieve a android.graphics.drawable.Drawable, corresponding to an attribute resource ID, as a Drawable instance. If given attribute ID can not be found, default Drawable resource ID defResId is used.

Link copied to clipboard

Retrieve a android.graphics.drawable.Drawable for a resource ID as a Drawable instance.

Link copied to clipboard
fun enterNoStateUpdatesMethod(noStateUpdatesMethod: String)
Link copied to clipboard
Link copied to clipboard
fun <T : View?> findViewWithTag(tag: Any): T?

A utility function to find the View with a given tag under the current Component's LithoView. To set a view tag, use the .viewTag() common prop or Style.viewTag. An appropriate time to call this is in your Component's onVisible callback.

Link copied to clipboard
fun findViewWithTagValue(key: Int, tag: Any): View?

A utility function to find the View with a given tag under the current Component's LithoView. To set a view tag, use the .viewTags() common prop or Style.viewTags. An appropriate time to call this is in your Component's onVisible callback.

Link copied to clipboard
fun ComponentContext.floatAttr(@AttrRes id: Int, @DimenRes defResId: Int = 0): Float
Link copied to clipboard
Link copied to clipboard
fun getCachedValue(cacheKey: HookGlobalKey, cachedValueInputs: Any): Any?
Link copied to clipboard
fun getColor(@ColorRes id: Int): Int
Link copied to clipboard
fun <T : Any> getParentTreeProp(key: Class<T>): T?
Link copied to clipboard
fun getString(@StringRes resId: Int): String
fun getString(@StringRes resId: Int, vararg formatArgs: Any?): String
Link copied to clipboard
Link copied to clipboard
fun <T> getTreeProp(key: TreeProp<T>): T
fun <T : Any> getTreeProp(key: Class<T>): T?
Link copied to clipboard
fun ComponentContext.intAttr(@AttrRes id: Int, @IntegerRes defResId: Int = 0): Int
Link copied to clipboard
Link copied to clipboard

Temporary workaround to suppress the "measure in resolve" violation policy.

Link copied to clipboard
Link copied to clipboard
open fun <E> newEventTrigger(id: Int, childKey: String, handle: Handle?): EventTrigger<E>
Link copied to clipboard

Retrieve a android.graphics.drawable.Drawable for a resource ID as a Drawable instance, or null if the resource ID is zero or null.

Link copied to clipboard
fun obtainStyledAttributes(attrs: IntArray, @AttrRes defStyleAttr: Int): TypedArray
Link copied to clipboard
fun putCachedValue(cacheKey: HookGlobalKey, cachedValueInputs: Any, cachedValue: Any?)
Link copied to clipboard
fun ComponentContext.quantityStringRes(@PluralsRes id: Int, quantity: Int, vararg formatArgs: Any?): String
Link copied to clipboard
fun removePendingStateUpdate(key: GlobalKey, isLayoutState: Boolean)
Link copied to clipboard
fun setDefStyle(@AttrRes defStyleAttr: Int, @StyleRes defStyleRes: Int)
Link copied to clipboard
@VisibleForTesting(otherwise = 3)
fun setLithoLayoutContext(lithoLayoutContext: LithoLayoutContext)
Link copied to clipboard

For test usage. This method will ensure this ComponentContext has a RenderStateContex. This is critical for tests that trigger layout calculation functionality outside of a LayoutState calculation (i.e., including willRender, Layout API, caching, etc).

Link copied to clipboard
fun ComponentContext.stringAttr(@AttrRes attrResId: Int, @StringRes defResId: Int = 0): String

Return a string for an attribute resource ID.

Link copied to clipboard

Return a string for a resource ID.

Return a string for a resource ID, substituting the format arguments with arg.

fun ComponentContext.stringRes(@StringRes id: Int, vararg formatArgs: Any?): String

Return a string for a resource ID, substituting the format arguments with formatArgs.

Link copied to clipboard
open fun updateStateAsync(stateUpdate: StateContainer.StateUpdate, attribution: String)

Notify the Component Tree that it needs to asynchronously perform a state update.

fun updateStateAsync(stateUpdate: StateContainer.StateUpdate, attribution: String, reference: Class<out Component>)

Variant of updateStateAsync that asserts the update is performed with the ComponentContext of reference — the component that owns the state. Generated by the Spec annotation processor for @OnUpdateState methods; see assertValidStateUpdateContext.

Link copied to clipboard

fun updateStateLazy(stateUpdate: StateContainer.StateUpdate, reference: Class<out Component>)

Variant of updateStateLazy that asserts the update is performed with the ComponentContext of reference — the component that owns the state. Generated by the Spec annotation processor for lazy state updates; see assertValidStateUpdateContext.

Link copied to clipboard
open fun updateStateSync(stateUpdate: StateContainer.StateUpdate, attribution: String)

Notify the Component Tree that it needs to synchronously perform a state update.

fun updateStateSync(stateUpdate: StateContainer.StateUpdate, attribution: String, reference: Class<out Component>)

Variant of updateStateSync that asserts the update is performed with the ComponentContext of reference — the component that owns the state. Generated by the Spec annotation processor for @OnUpdateState methods; see assertValidStateUpdateContext.

Link copied to clipboard

fun updateStateWithTransition(stateUpdate: StateContainer.StateUpdate, attribution: String, reference: Class<out Component>)

Variant of updateStateWithTransition that asserts the update is performed with the ComponentContext of reference — the component that owns the state. Generated by the Spec annotation processor for @OnUpdateStateWithTransition methods.