ComponentScope

open class ComponentScope(val context: ComponentContext, resolveContext: ResolveContext? = null) : ResourcesScope

The implicit receiver for KComponent.render call. This class exposes the ability to use hooks, like useState, and convenience functions, like dp.

Inheritors

Constructors

Link copied to clipboard
constructor(context: ComponentContext, resolveContext: ResolveContext? = null)

Properties

Link copied to clipboard
open override val androidContext: Context
Link copied to clipboard
open override val context: ComponentContext
Link copied to clipboard
open override val resourceResolver: ResourceResolver
Link copied to clipboard
open val <T> TreeProp<T>.value: T

Functions

Link copied to clipboard
inline fun ResourcesScope.Column(alignContent: YogaAlign? = null, alignItems: YogaAlign? = null, justifyContent: YogaJustify? = null, wrap: YogaWrap? = null, isReversed: Boolean = false, gap: Dimen? = null, style: Style? = null): Column

Constructs a new Column without any children.

inline fun ResourcesScope.Column(alignContent: YogaAlign? = null, alignItems: YogaAlign? = null, justifyContent: YogaJustify? = null, wrap: YogaWrap? = null, isReversed: Boolean = false, gap: Dimen? = null, style: Style? = null, init: FlexboxContainerScope.() -> Unit): Column

Constructs a new Column. Add children by using FlexboxContainerScope.child or FlexboxContainerScope.children:

Link copied to clipboard
fun BaseResourcesScope.drawableColor(@ColorInt color: Int): Drawable
fun BaseResourcesScope.drawableColor(@ColorInt color: Long): Drawable

Return a android.graphics.drawable.Drawable for a ColorInt value as a Drawable instance.

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 Style.viewTag. An appropriate time to call this is in your Component's onVisible callback.

Link copied to clipboard
open fun getIntAttrValue(componentContext: ComponentContext, @StyleableRes id: Int, @StyleableRes attrs: IntArray, defaultValue: Int): Int

Retrieves a styled attribute value for provided {@param id}.

Link copied to clipboard
inline fun <T : Any> ResourcesScope.getTreeProp(): T?

Returns the instance registered for the type T in this hierarchy, and null if no value was registered. Tree props are registered for a sub-hierarchy via TreePropProvider or com.facebook.litho.annotations.OnCreateTreeProp in the Spec API.

Link copied to clipboard

Returns the instance registered for the type T in this hierarchy, throws if no value was registered. Tree props are registered for a sub-hierarchy via TreePropProvider or com.facebook.litho.annotations.OnCreateTreeProp in the Spec API.

Link copied to clipboard
inline fun ResourcesScope.Row(alignContent: YogaAlign? = null, alignItems: YogaAlign? = null, justifyContent: YogaJustify? = null, wrap: YogaWrap? = null, isReversed: Boolean = false, gap: Dimen? = null, style: Style? = null): Row

Constructs a new Column without any children.

inline fun ResourcesScope.Row(alignContent: YogaAlign? = null, alignItems: YogaAlign? = null, justifyContent: YogaJustify? = null, wrap: YogaWrap? = null, isReversed: Boolean = false, gap: Dimen? = null, style: Style? = null, init: FlexboxContainerScope.() -> Unit): Row

Constructs a new Row. Add children by using FlexboxContainerScope.child or FlexboxContainerScope.children:

Link copied to clipboard
open fun Dimen.toPixels(): Int
Link copied to clipboard
fun <T> ComponentScope.useBinding(initialValue: T): DynamicValue<T>

Creates a DynamicValue with a static initial value. This DynamicValue can be passed to the variants of Style properties that take DynamicValue, like Style.backgroundColor or Style.translationY. You can then imperatively set a new value on the main thread to update that property without a state update, or use the collection of Animated APIs to drive animations on this DynamicValue, which will in turn animate the property.

fun <T, S> ComponentScope.useBinding(binding: DynamicValue<T>, transform: (T) -> S): DynamicValue<S>

Creates a DynamicValue deriving from an existing binding param, with modifications applied by transform function.

Link copied to clipboard
fun <T> ComponentScope.useCached(vararg inputs: Any?, calculator: () -> T): T

Create a CachedValue variable within a Component. The calculator will provide the calculated value if it hasn't already been calculated or if the inputs have changed since the previous calculation.

Link copied to clipboard
fun <R> ComponentScope.useCallback(callback: () -> R): () -> R

useCallback allows a parent to pass a child component a callback which: 1) maintains referential equality across multiple layout passes 2) is updated to have the latest parent props and state, even if the child doesn't re-render.

fun <A, R> ComponentScope.useCallback(callback: (A) -> R): (A) -> R

1-parameter overload of useCallback: refer to docs there.

fun <A, B, R> ComponentScope.useCallback(callback: (A, B) -> R): (A, B) -> R

2-parameter overload of useCallback: refer to docs there.

fun <A, B, C, R> ComponentScope.useCallback(callback: (A, B, C) -> R): (A, B, C) -> R

3-parameter overload of useCallback: refer to docs there.

fun <A, B, C, D, R> ComponentScope.useCallback(callback: (A, B, C, D) -> R): (A, B, C, D) -> R

4-parameter overload of useCallback: refer to docs there.

fun <A, B, C, D, E, R> ComponentScope.useCallback(callback: (A, B, C, D, E) -> R): (A, B, C, D, E) -> R

5-parameter overload of useCallback: refer to docs there.

fun <A, B, C, D, E, F, R> ComponentScope.useCallback(callback: (A, B, C, D, E, F) -> R): (A, B, C, D, E, F) -> R

6-parameter overload of useCallback: refer to docs there.

fun <A, B, C, D, E, F, G, R> ComponentScope.useCallback(callback: (A, B, C, D, E, F, G) -> R): (A, B, C, D, E, F, G) -> R

7-parameter overload of useCallback: refer to docs there.

Link copied to clipboard
fun ComponentScope.useEffect(onAttach: () -> CleanupFunc?)
fun ComponentScope.useEffect(vararg deps: Any?, onAttach: () -> CleanupFunc?)

Registers a callback to perform side-effects when this Component is attached/detached from the tree.

Link copied to clipboard
fun ComponentScope.useErrorBoundary(onError: (exception: Exception) -> Unit)

Registers a callback to perform error handling for exceptions that might happen in child components down in the tree.

Link copied to clipboard

Provides a persistent FirstDrawReporter instance to trigger onDrawn callback immediately after the first draw for a given component. To bind returned reporter with a component, pass it via the Style.reportFirstContentDraw prop.

Link copied to clipboard

This hook creates a set of references, one for each focusable component that can be used for changing the default focus order. Use with Style.focusOrder

Link copied to clipboard
fun <T> ComponentScope.useRef(initializer: () -> T): Ref<T>

Declares a mutable, main-thread confined reference that will be persisted across renders with an initial value provided by the initializer. It's similar to useState, except that the returned reference is mutable and updating it will not cause a re-render.

Link copied to clipboard
fun <T> ComponentScope.useState(initializer: () -> T): State<T>

Declares a state variable within a Component. The initializer will provide the initial value if it hasn't already been initialized in a previous render of the Component.

Link copied to clipboard
fun ComponentScope.useTransition(transition: Transition?)

Defines one or more Transition animations for the given component

fun ComponentScope.useTransition(createTransition: UseTransitionScope.() -> Transition?)

Defines single or multiple Transition animations for the given component.

fun ComponentScope.useTransition(vararg deps: Any?, createTransition: UseTransitionScope.() -> Transition?)

Defines one or more Transition animations for the given component and allows for the Transition to be re-evaluated based on changes in the deps

Link copied to clipboard
inline fun ResourcesScope.Wrapper(style: Style, crossinline content: ResourcesScope.() -> Component): Wrapper

Builder function for creating Wrapper components. It's useful for adding additional Style props to a given component.