PropDefault
PropDefault
can be used for setting the default value of an optional Prop in a LayoutSpec or MountSpec. The field must be a constant (i.e. static final) with the same name and type as the Prop
.
For example:
@LayoutSpec
class SomeSpec {
@PropDefault
static final String name = "John Doe"; // default value for name
@OnCreateLayout
static Component onCreateLayout(
ComponentContext c,
@Prop(optional = true) String name) {
return Text.create(c)
.text(title.getTitle())
.textSizeSp(16)
.marginDip(YogaEdge.BOTTOM, 4)
.build();
}
}
Content copied to clipboard