@Retention(value=CLASS)
public @interface OnMount
OnMount
is called on a MountSpec
component before the
component is attached to a hosting view. This will happen when the component is about to become
visible when incremental mount is enabled (it is enabled by default). The framework will always
invoke this method on the UI thread. This method is critical for performance as it is UI-bound;
expensive operations should not be performed here.
You can think of methods annotated with OnMount
as the equivalent of the
RecyclerView.Adapter's bindViewHolder method. It will be called to bind the recycler Views or
Drawables to the correct data when they are about to be mounted on screen.
The annotated method has a void return type and will be passed the following arguments when the framework invokes it:
Required:
Optional annotated arguments:
The annotation processor will validate this and other invariants in the API at build time.
For example:
@MountSpec
class ExampleMountSpec {
@OnCreateMountContent
static ColorDrawable onCreateMountContent(
ComponentContext c) {
return new ColorDrawable();
}
@OnMount
static void onMount(
ComponentContext c,
ColorDrawable colorDrawable,
@FromPrepareint color){
colorDrawable.setColor(color);
}
}
OnCreateMountContent
,
OnUnmount