OnMount

annotation class OnMount

A method annotated with 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:

  1. ComponentContext
  2. {MountContent} - must be the same type as the return type of the method annotated with OnCreateMountContent, which is either a View or a Drawable

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);
  }
}

See also

Functions

Link copied to clipboard
abstract fun annotationType(): Class<out Annotation>
Link copied to clipboard
abstract fun equals(p: Any): Boolean
Link copied to clipboard
abstract fun hashCode(): Int
Link copied to clipboard
abstract fun toString(): String