@Retention(value=RUNTIME)
public @interface FromMeasure
OnMeasure
lifecycle method. The name and type of the argument must match with the inter-stage
output requested.
This can be used in:
OnBoundsDefined
OnMount
OnBind
OnUnbind
OnUnmount
OnPopulateAccessibilityNode
OnPopulateExtraAccessibilityNode
GetExtraAccessibilityNodeAt
GetExtraAccessibilityNodesCount
The annotation processor will validate this and other invariants in the API at build time.
For example:
@MountSpec
public class SubtitleSpec {
@OnMeasure
static void onMeasure(
ComponentContext componentContext,
ComponentLayout layout,
int widthSpec,
int heightSpec,
Size size,
@Prop String text,
Output<Layout> measuredLayout) {
Layout textLayout = createTextLayout(text, widthSpec, heightSpec);
size.width = SizeSpec.resolveSize(widthSpec, textLayout.getWidth());
size.height = SizeSpec.resolveSize(heightSpec, LayoutMeasureUtil.getHeight(textLayout));
if (size.width < 0 || size.height < 0) {
size.width = Math.max(size.width, 0);
size.height = Math.max(size.height, 0);
}
measuredLayout.set(textLayout); // Set the value of output.
}
@OnMount
static void onMount(ComponentContext c,
TextDrawable textDrawable,
@Prop String text,
// Get measured layout from the output set in OnMeasure.
@FromMeasure Layout measuredLayout) {
textDrawable.mount(
text,
textLayout,
0,
null,
Color.BLANK,
Color.GREEN,
null);
}
}