@Retention(value=RUNTIME)
public @interface LayoutSpec
The class annotated with LayoutSpec must implement a method with the OnCreateLayout or OnCreateLayoutWithSizeSpec annotation. It may also implement methods
with the following annotations:
OnCreateInitialState
OnCreateTreeProp
OnCreateTransition
OnUpdateState
OnEvent
OnLoadStyle
OnEnteredRange
OnExitedRange
OnRegisterRanges
OnCalculateCachedValue
ShouldUpdate
Example:
@LayoutSpec
public class CounterSpec {
@OnCreateLayout
static Component onCreateLayout(
ComponentContext c,
@Prop int id,
@State int count) {
return Row.create(c)
.backgroundColor(Color.WHITE)
.heightDip(64)
.paddingDip(YogaEdge.ALL, 8)
.child(
Text.create(c)
.text(" + ")
.clickHandler(Counter.onClick(c))
)
.child(
Text.create(c)
.text(String.valueOf(count))
)
.build();
}
@OnCreateInitialState
static void onCreateInitialState(
ComponentContext c,
StateValue<Integer> count) {
count.set(0);
}
@OnEvent(ClickEvent.class)
static void onClick(ComponentContext c, @Prop int id) {
Counter.increment(c, id);
}
@OnUpdateState
static void increment(StateValue<Integer> count, @Param int counterId) {
count.set(count.get() + 1);
}
}
If you want to create a component that mounts its own content, then use MountSpec
instead. See more docs at https://fblitho.com
Prop,
TreeProp,
InjectProp,
State,
Param,
FromPreviousCreateLayout| Modifier and Type | Optional Element and Description |
|---|---|
java.lang.Class<?>[] |
events |
boolean |
isPublic |
boolean |
isPureRender |
java.lang.String |
simpleNameDelegate |
java.lang.Class<?>[] |
triggers |
java.lang.String |
value
Class name of the generated component.
|
public abstract java.lang.String value
In order to avoid confusion, this should only be used if you have a very good reason for it. For instance to avoid naming collisions.
public abstract boolean isPublic
public abstract boolean isPureRender
public abstract java.lang.Class<?>[] events
public abstract java.lang.Class<?>[] triggers
public abstract java.lang.String simpleNameDelegate