com.facebook.litho.annotations.FromBoundsDefined Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of litho-annotations Show documentation
Show all versions of litho-annotations Show documentation
The annotations that are used in the Litho library
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.facebook.litho.annotations;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/**
* {@code FromBoundsDefined} is used to pass objects from the {@link OnBoundsDefined} lifecycle
* methods of {@link MountSpec} to lifecycle methods called successively such as {@link OnMount} or
* {@link OnBind} method, use {@code FromBoundsDefined} with the same type and name to retrieve your
* previously set
*
* To use it, simply declare a parameter of type {@code com.facebook.litho.Output<>} within the
* method annotated with {@link OnBoundsDefined}. {@code 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 {@code FromBoundsDefined} with the same type and name to
* retrieve your previously set object.
*
*
This can be used in:
*
*
* - {@link OnMount}
*
- {@link OnBind}
*
- {@link OnUnbind}
*
- {@link OnUnmount}
*
- {@link OnPopulateAccessibilityNode}
*
- {@link OnPopulateExtraAccessibilityNode}
*
- {@link GetExtraAccessibilityNodeAt}
*
- {@link GetExtraAccessibilityNodesCount}
*
*
* Example:
*
*
{@literal @MountSpec}
* public class MyComponentSpec {
*
* {@literal @}OnCreateMountContent
* MyDrawable onCreateMountContent(Context context) {
* return new MyDrawable(c);
* }
*
*
* {@literal @}OnBoundsDefined
* void onBoundsDefined(
* ComponentContext c,
* ComponentLayout layout,
* Output<MyFromBoundsDefinedObject> fromBoundsDefinedObject) {
* MyFromBoundsDefinedObject myFromBoundsDefinedObject = new MyFromBoundsDefinedObject();
* fromBoundsDefinedObject.set(myFromBoundsDefinedObject);
* }
*
* {@literal @}OnMount
* void onMount(
* ComponentContext c,
* MyDrawable myDrawable,
* {@literal @}FromBoundsDefined MyFromBoundsDefinedObject fromBoundsDefinedObject) {
* fromBoundsDefinedObject.doSomething();
* }
*
* }
*
*/
@Retention(RetentionPolicy.SOURCE)
public @interface FromBoundsDefined {}