@Retention(value=RUNTIME)
public @interface FromPrepare
FromPrepare
is used to pass objects from the OnPrepare
lifecycle methods of
MountSpec
to lifecycle methods called successively such as OnMount
or OnBind
method, use FromPrepare
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 OnPrepare
. 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 FromPrepare
with the same type and name to retrieve your previously
set object.
This can be used in:
OnMeasure
OnMeasureBaseline
OnBoundsDefined
OnMount
OnBind
OnUnbind
OnUnmount
OnPopulateAccessibilityNode
OnPopulateExtraAccessibilityNode
GetExtraAccessibilityNodeAt
GetExtraAccessibilityNodesCount
Example:
@MountSpec
public class MyComponentSpec {
@OnCreateMountContent
MyDrawable onCreateMountContent(Context context) {
return new MyDrawable(c);
}
@OnPrepare
void onPrepare(
ComponentContext c,
Output<MyFromPrepareObject> fromPrepareObject) {
MyFromPrepareObject myFromPrepareObject = new MyFromPrepareObject();
fromPrepareObject.set(myFromPrepareObject);
}
@OnMount
void onMount(
ComponentContext c,
MyDrawable myDrawable,
@FromPrepare MyFromPrepareObject fromPrepareObject) {
fromPrepareObject.doSomething();
}
}