@Retention(value=SOURCE)
public @interface FromBoundsDefined
FromBoundsDefined
is used to pass objects from the OnBoundsDefined
lifecycle
methods of MountSpec
to lifecycle methods called successively such as OnMount
or
OnBind
method, use FromBoundsDefined
with the same type and name to retrieve your
previously set
To use it, simply declare a parameter of type com.facebook.litho.Output<>
within the
method annotated with OnBoundsDefined
. com.facebook.litho.Output<>
accepts a
generic type which should be the type of the object you want to pass around. Then, in a
successive lifecycle method, use FromBoundsDefined
with the same type and name to
retrieve your previously set object.
This can be used in:
OnMount
OnBind
OnUnbind
OnUnmount
OnPopulateAccessibilityNode
OnPopulateExtraAccessibilityNode
GetExtraAccessibilityNodeAt
GetExtraAccessibilityNodesCount
Example:
@MountSpec
public class MyComponentSpec {
@OnCreateMountContent
MyDrawable onCreateMountContent(Context context) {
return new MyDrawable(c);
}
@OnBoundsDefined
void onBoundsDefined(
ComponentContext c,
ComponentLayout layout,
Output<MyFromBoundsDefinedObject> fromBoundsDefinedObject) {
MyFromBoundsDefinedObject myFromBoundsDefinedObject = new MyFromBoundsDefinedObject();
fromBoundsDefinedObject.set(myFromBoundsDefinedObject);
}
@OnMount
void onMount(
ComponentContext c,
MyDrawable myDrawable,
@FromBoundsDefined MyFromBoundsDefinedObject fromBoundsDefinedObject) {
fromBoundsDefinedObject.doSomething();
}
}