@Retention(value=SOURCE) public @interface FromBind
FromBind
is used to pass objects from the OnBind
lifecycle methods of MountSpec
to lifecycle methods called successively such as OnUnbind
or OnUnmount
. method, use FromBind
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 OnBind
. 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 FromBind
with the same type and name to retrieve your previously set object.
Example:
@MountSpec
public class MyComponentSpec {
@OnCreateMountContent
MyDrawable onCreateMountContent(Context context) {
return new MyDrawable(c);
}
@OnMount
void onMount(
ComponentContext c,
MyDrawable myDrawable,
@Prop MyProp prop) {
myDrawable.setMyProp(prop);
}
@OnBind
void onBind(
ComponentContext c,
MyDrawable myDrawable,
Output<MyFromBindObject> fromBindObject) {
MyFromBindObject myFromBindObject = new MyFromBindObject();
fromBindObject.set(myFromBindObject);
}
@OnUnbind
void onUnbind(
ComponentContext c,
MyDrawable myDrawable,
@FromBind MyFromBindObject fromBindObject) {
fromBindObject.doSomething();
}
}