TestComponentScope

Test implementation of ComponentScope used for testing purposes. Provides a test-specific context for component operations.

Constructors

Link copied to clipboard
constructor(context: ComponentContext)

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
fun ComponentScope.calculate(component: Component, sizeConstraints: SizeConstraints): LayoutResult?
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 enterHook(callSiteId: Int)

Called by compiler-injected code before a dynamically repeated @Hook function call. Creates a HookKey from the compile-time assigned callSiteId and a runtime index that counts how many times this call site has been entered within its parent hook invocation.

fun enterHook(callSiteId: Int, index: Int)

Called for a hook call site whose index the compiler determined statically.

Link copied to clipboard
fun exitHook()

Called by compiler-injected code after a @Hook function call returns. Restores the hook key to the parent scope.

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
inline fun ResourcesScope.NullableWrapper(name: String? = null, style: Style, crossinline content: ResourcesScope.() -> Component?): Wrapper?

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

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.StackLayout(alignContent: YogaAlign? = null, alignItems: YogaAlign? = null, justifyContent: YogaJustify? = null, wrap: YogaWrap? = null, gap: Dimen? = null, style: Style = Style, noinline children: StackContainerScope.() -> Unit): Component

A layout component that stacks its children on top of each other. Each child is positioned absolutely within the container, allowing them to overlap.

Link copied to clipboard
open fun Dimen.toPixels(): Int
Link copied to clipboard
fun <T> ComponentScope.useAnimatable(initialValue: T, typeConverter: TypeConverter<T>, label: String = ""): Animatable<T>

Creates an Animatable for imperative animation control.

Link copied to clipboard
fun ComponentScope.useAnimatedColor(targetValue: Color, spec: FiniteAnimationSpec<Color> = spring(), trigger: AnimationTrigger = AnimationTrigger.Immediate, label: String = "color"): Value<Color>

Animates a Color value with per-channel interpolation, automatically starting a new animation whenever targetValue changes.

Link copied to clipboard
fun ComponentScope.useAnimatedDimen(targetValue: Dimen, spec: FiniteAnimationSpec<Dimen> = spring(), trigger: AnimationTrigger = AnimationTrigger.Immediate, label: String = "dimen"): Value<Dimen>

Animates a Dimen value, automatically starting a new animation whenever targetValue changes.

Link copied to clipboard
fun ComponentScope.useAnimatedFloat(targetValue: Float, spec: FiniteAnimationSpec<Float> = spring(), trigger: AnimationTrigger = AnimationTrigger.Immediate, label: String = "float"): Value<Float>

Animates a Float value, automatically starting a new animation whenever targetValue changes.

Link copied to clipboard
fun ComponentScope.useAnimatedInt(targetValue: Int, spec: FiniteAnimationSpec<Int> = spring(), trigger: AnimationTrigger = AnimationTrigger.Immediate, label: String = "int"): Value<Int>

Animates an Int value, automatically starting a new animation whenever targetValue changes.

Link copied to clipboard
fun <T> ComponentScope.useAnimatedValue(targetValue: T, typeConverter: TypeConverter<T>, spec: FiniteAnimationSpec<T> = spring(), trigger: AnimationTrigger = AnimationTrigger.Immediate, label: String = ""): Value<T>

Animates a value of type T, automatically starting a new animation whenever targetValue changes.

Link copied to clipboard
fun <S> ComponentScope.useAnimationGroup(targetState: S, trigger: AnimationTrigger = AnimationTrigger.Immediate, label: String = "transition"): AnimationGroup<S>

Coordinates multiple animated properties that respond to a shared targetState.

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 ComponentScope.useHandle(vararg inputs: Any?): Handle

Returns a new, cached Handle instance if it hasn't already been provided or if the inputs have changed since the previous invocation of this method.

Link copied to clipboard

Creates an InfiniteAnimationGroup container for continuous, lifecycle-owned looping animations — shimmer, pulse, spinners, breathing effects, loading dots. Each child loops between an explicit from and to, starts with the component, and stops when it unmounts.

Link copied to clipboard

Returns a stable AnimationTrigger.Lazy instance for explicit manual triggering.

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.useSaveableState(key: String? = null, saver: Saver<T> = autoSaver(), initializer: () -> T): State<T>

Declares component state that can be restored by a lifecycle-backed host.

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 <T> ComponentScope.useStateWithDeps(vararg deps: Any? = NoDeps, initializer: () -> T): State<T>

Declares a state within a Component. The initializer will be invoked to provide the initial value of state. The initializer will be invoked again if the deps change when the Component is rendered again.

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 <T : ViewModel> ComponentScope.useViewModel(key: String? = null, noinline factory: () -> T): ReadOnlyProperty<Any?, T>

Declares a ViewModel scoped to the store supplied by the tree's host. Root trees supply a LithoViewModelStore through ComponentTree.Builder.withLithoViewModelStore, while nested trees receive their current inherited store through TreeProps.

Link copied to clipboard
inline fun <R> ComponentScope.withNewScope(key: Any, block: ComponentScope.() -> R): R

Gives every hook called by block an identity nested under key. Use this when the same source hook call renders several logical items whose order can change. The key must be immutable, stable across renders, and unique among invocations of this withNewScope call site under the same parent scope. Duplicate sibling keys are reported and disambiguated by their order. Two different call sites may use the same key without colliding.

Link copied to clipboard
inline fun ResourcesScope.Wrapper(name: String? = null, 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.