/** A component that doesn't render anything. */ @LayoutSpec class EmptyComponentSpec { @OnCreateLayout static @Nullable Component onCreateLayout(ComponentContext c) { return null; } }
@LayoutSpec public class PossiblyCrashingSubTitleComponentSpec { @OnCreateLayout static Component onCreateLayout(ComponentContext c, @Prop(resType = STRING) String subtitle) { if (Math.random() >= 0.7) { throw new RuntimeException("Oh no, a random error!"); } return Text.create(c).text(subtitle).textSizeDip(18).build(); } }
/** A simple, "Hello, world" Component for learning the basics of LayoutSpecs. */ @LayoutSpec public class LearningLayoutSpecsComponentSpec { @OnCreateLayout static Component onCreateLayout(ComponentContext c) { return Text.create(c).text("Hello, World!").textSizeDip(50).build(); } }
@LayoutSpec public class TestCrasherOnCreateLayoutWithSizeSpecSpec { @OnCreateLayoutWithSizeSpec protected static Component onCreateLayoutWithSizeSpec( ComponentContext c, final int widthSpec, final int heightSpec) { throw new RuntimeException("onCreateLayoutWithSizeSpec crash"); } }
@LayoutSpec public class TestCrasherOnCreateLayoutSpec { @OnCreateLayout public static Component onCreateLayout(ComponentContext c) { throw new RuntimeException("onCreateLayout crash"); } }
@LayoutSpec public class TitleComponentSpec { @OnCreateLayout static Component onCreateLayout(ComponentContext c, @Prop(resType = STRING) String title) { return Text.create(c) .text(title) .textStyle(BOLD) .textSizeDip(24) .positionDip(YogaEdge.BOTTOM, 16) .build(); } }
@LayoutSpec public class FeedItemCardSpec { @OnCreateLayout static Component onCreateLayout(ComponentContext c, @Prop final Artist artist) { return Column.create(c) .paddingDip(VERTICAL, 8) .paddingDip(HORIZONTAL, 16) .child(Card.create(c).content(FeedItemComponent.create(c).artist(artist))) .build(); } }
@LayoutSpec static class TestDimenResTypeWithBoxFloatArgSpec { @OnCreateLayout public void dimenResTypeWithBoxFloatArg(@Prop(resType = ResType.DIMEN_TEXT) Float size) {} }
@LayoutSpec static class TestSpec { @OnError public void testErrorHandler(ComponentContext c, Exception e) {} }
@LayoutSpec static class ManualErrorHandlerSpec { @OnEvent(ErrorEvent.class) static void __internalOnErrorHandler(ComponentContext c, @FromEvent Exception exception) {} }
@LayoutSpec static class MyLayoutSpec { @OnCreateLayout public Component onCreateLayout(ComponentContext c, @Prop String s) { return null; } }
@LayoutSpec static class TestResTypeWithVarArgsSpec { @OnCreateLayout public void resTypeWithVarArgs( @Prop(varArg = "size", resType = ResType.DIMEN_TEXT) List<Float> sizes) {} }
@LayoutSpec static class TestClass implements EmptyInterface, NonEmptyInterface, ExtendedInterface { @Override public void method() {} }
@LayoutSpec private static class TestWithoutStateSpec<T extends CharSequence> { @OnCreateLayout public void onCreateLayout() {} }
@LayoutSpec static class TestKotlinWildcardsSpec { public static final TestKotlinWildcardsSpec INSTANCE = null; @OnCreateLayout public final Component onCreateLayout( ComponentContext c, @Prop(varArg = "number") java.util.List<? extends java.lang.Number> numbers) { return null; } }
@LayoutSpec public static class DupeLayoutSpec { @OnCreateLayout static void OnCreateLayout(ComponentContext c, @Prop String prop1) {} // Note that prop1 here has the same name but a different type. @OnEvent(TestEvent.class) static void onEvent(@Prop StringBuffer prop1) {} }
@LayoutSpec static class MyLayoutSpec { @OnCreateLayout public static Component onCreateLayout( ComponentContext c, @Prop String s, @Prop Component child, @Prop(resType = ResType.DIMEN_SIZE) float size, @Prop(optional = true) int i) { return Row.create(c).build(); } }
@LayoutSpec private static class TestWithLazyGeneric<T extends CharSequence> { @OnCreateLayout public void onCreateLayout(@State(canUpdateLazily = true) T arg0) {} @OnUpdateState void updateCurrentState() {} }
@LayoutSpec private static class TestWithLazyMethodGeneric { @OnCreateLayout public void onCreateLayout(@Prop int arg0) {} @OnCreateInitialState static <T> void onCreateInitialState(@State(canUpdateLazily = true) T arg1) {} }
@LayoutSpec static class TestKotlinVarArgSpec { public static final TestKotlinVarArgSpec INSTANCE = null; @OnCreateLayout public final Component onCreateLayout( ComponentContext c, @Prop(varArg = "number") java.util.List<? extends java.lang.Number> numbers) { return null; } }