com.facebook.litho.annotations.OnCreateLayout Java Examples
The following examples show how to use
com.facebook.litho.annotations.OnCreateLayout.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RtlColorWidthBorderSpec.java From litho with Apache License 2.0 | 6 votes |
@OnCreateLayout static Component onCreateLayout(ComponentContext c) { return Row.create(c) .layoutDirection(YogaDirection.RTL) .child(Text.create(c).textSizeSp(20).text("This component is RTL")) .border( Border.create(c) .color(YogaEdge.START, NiceColor.RED) .color(YogaEdge.TOP, NiceColor.YELLOW) .color(YogaEdge.END, NiceColor.GREEN) .color(YogaEdge.BOTTOM, NiceColor.BLUE) .widthDip(YogaEdge.START, 2) .widthDip(YogaEdge.TOP, 4) .widthDip(YogaEdge.END, 8) .widthDip(YogaEdge.BOTTOM, 16) .build()) .build(); }
Example #2
Source File: BlocksSameTransitionKeyComponentSpec.java From litho with Apache License 2.0 | 6 votes |
@OnCreateLayout static Component onCreateLayout( ComponentContext c, @State boolean state, @State boolean running, @State Set<String> runningAnimations) { return Column.create(c) .child(Row.create(c).child(Text.create(c).text(running ? "RUNNING" : "STOPPED"))) .child( Column.create(c) .alignItems(!state ? YogaAlign.FLEX_START : YogaAlign.FLEX_END) .child( Text.create(c) .heightDip(50) .widthDip(50) .text(runningAnimations.toString()) .backgroundColor(Color.parseColor("#ee1111")) .alpha(!state ? 1.0f : 0.2f) .transitionKey(TRANSITION_KEY) .build())) .clickHandler(BlocksSameTransitionKeyComponent.onClick(c)) .build(); }
Example #3
Source File: ExpandableElementOtherSpec.java From litho with Apache License 2.0 | 6 votes |
@OnCreateLayout static Component onCreateLayout( ComponentContext c, @Prop String messageText, @Prop String timestamp, @Prop(optional = true) boolean seen, @State Boolean expanded) { final boolean isExpanded = expanded == null ? false : expanded; return Column.create(c) .paddingDip(YogaEdge.TOP, 8) .transitionKey(ExpandableElementUtil.TRANSITION_MSG_PARENT) .transitionKeyType(Transition.TransitionKeyType.GLOBAL) .clickHandler(ExpandableElementOther.onClick(c)) .child(ExpandableElementUtil.maybeCreateTopDetailComponent(c, isExpanded, timestamp)) .child( Column.create(c) .transitionKey(ExpandableElementUtil.TRANSITION_TEXT_MESSAGE_WITH_BOTTOM) .transitionKeyType(Transition.TransitionKeyType.GLOBAL) .child( Row.create(c) .paddingDip(YogaEdge.END, 5) .child(createSenderTile(c)) .child(createMessageContent(c, messageText))) .child(ExpandableElementUtil.maybeCreateBottomDetailComponent(c, isExpanded, seen))) .build(); }
Example #4
Source File: AlternateWidthBorderSpec.java From litho with Apache License 2.0 | 6 votes |
@OnCreateLayout static Component onCreateLayout(ComponentContext c) { return Row.create(c) .child( Text.create(c) .textSizeSp(20) .text("This component has all borders specified to the same color, but not width")) .border( Border.create(c) .color(YogaEdge.ALL, NiceColor.MAGENTA) .widthDip(YogaEdge.LEFT, 2) .widthDip(YogaEdge.TOP, 4) .widthDip(YogaEdge.RIGHT, 8) .widthDip(YogaEdge.BOTTOM, 16) .build()) .build(); }
Example #5
Source File: VaryingRadiiBorderSpec.java From litho with Apache License 2.0 | 6 votes |
@OnCreateLayout static Component onCreateLayout(ComponentContext c) { return Row.create(c) .child(Text.create(c).textSizeSp(20).text("This component has varying corner radii")) .border( Border.create(c) .widthDip(YogaEdge.ALL, 3) .color(YogaEdge.LEFT, Color.BLACK) .color(YogaEdge.TOP, NiceColor.GREEN) .color(YogaEdge.BOTTOM, NiceColor.BLUE) .color(YogaEdge.RIGHT, NiceColor.RED) .radiusDip(Corner.TOP_LEFT, 10) .radiusDip(Corner.TOP_RIGHT, 5) .radiusDip(Corner.BOTTOM_RIGHT, 20) .radiusDip(Corner.BOTTOM_LEFT, 30) .build()) .build(); }
Example #6
Source File: PathExampleComponentSpec.java From litho with Apache License 2.0 | 6 votes |
@OnCreateLayout static Component onCreateLayout( ComponentContext c, @State DynamicValue<Float> translationX, @State DynamicValue<Float> translationY) { return Column.create(c) .alignItems(YogaAlign.CENTER) .justifyContent(YogaJustify.CENTER) .paddingDip(YogaEdge.ALL, 50) .child( // Create the component we will animate. Apply the DynamicValues to it. Text.create(c) .text("\u26BE") .textSizeSp(50) .translationX(translationX) .translationY(translationY)) .visibleHandler(ContinuousExampleComponent.onVisible(c)) .build(); }
Example #7
Source File: AlternateColorBorderSpec.java From litho with Apache License 2.0 | 6 votes |
@OnCreateLayout static Component onCreateLayout(ComponentContext c) { return Row.create(c) .child( Text.create(c) .textSizeSp(20) .text("This component has all borders specified to the same width, but not colors")) .border( Border.create(c) .color(YogaEdge.LEFT, NiceColor.RED) .color(YogaEdge.TOP, NiceColor.YELLOW) .color(YogaEdge.RIGHT, NiceColor.GREEN) .color(YogaEdge.BOTTOM, NiceColor.BLUE) .widthDip(YogaEdge.ALL, 5) .build()) .build(); }
Example #8
Source File: DelegateMethodValidationTest.java From litho with Apache License 2.0 | 6 votes |
@Test public void testDelegateMethodIsNotStaticWithKotlinSingleton() { when(mLayoutSpecModel.getSpecElementType()).thenReturn(SpecElementType.KOTLIN_SINGLETON); when(mLayoutSpecModel.getDelegateMethods()) .thenReturn( ImmutableList.of( SpecMethodModel.<DelegateMethod, Void>builder() .annotations(ImmutableList.of((Annotation) () -> OnCreateLayout.class)) .modifiers(ImmutableList.of()) .name("name") .returnTypeSpec(new TypeSpec(ClassNames.COMPONENT)) .typeVariables(ImmutableList.of()) .methodParams( ImmutableList.of( MockMethodParamModel.newBuilder() .type(ClassNames.COMPONENT_CONTEXT) .representedObject(mMethodParamObject1) .build())) .representedObject(mDelegateMethodObject1) .typeModel(null) .build())); final List<SpecModelValidationError> validationErrors = DelegateMethodValidation.validateLayoutSpecModel(mLayoutSpecModel); assertThat(validationErrors).isEmpty(); }
Example #9
Source File: ListRowComponentSpec.java From litho with Apache License 2.0 | 6 votes |
@OnCreateLayout static Component onCreateLayout(ComponentContext c, @Prop ListRow row) { return Column.create(c) .paddingDip(YogaEdge.VERTICAL, 8) .paddingDip(YogaEdge.HORIZONTAL, 32) .child( Card.create(c) .content( Column.create(c) .marginDip(YogaEdge.ALL, 32) .child(TitleComponent.create(c).title(row.title)) .child(PossiblyCrashingSubTitleComponent.create(c).subtitle(row.subtitle)) .build()) .build()) .build(); }
Example #10
Source File: SpinnerSpec.java From litho with Apache License 2.0 | 6 votes |
@OnCreateLayout static Component onCreateLayout( ComponentContext c, @State String selection, @State boolean isShowingDropDown, @Prop(resType = ResType.DIMEN_TEXT, optional = true) float selectedTextSize, @Prop(resType = ResType.COLOR, optional = true) int selectedTextColor, @Prop(resType = ResType.DRAWABLE, optional = true) @Nullable Drawable caret) { caret = caret == null ? new CaretDrawable(c.getAndroidContext(), DEFAULT_CARET_COLOR) : caret; selectedTextSize = selectedTextSize == -1 ? spToPx(c.getAndroidContext(), DEFAULT_TEXT_SIZE_SP) : selectedTextSize; return Row.create(c) .minHeightDip(SPINNER_HEIGHT) .justifyContent(YogaJustify.SPACE_BETWEEN) .paddingDip(START, MARGIN_SMALL) .backgroundAttr(android.R.attr.selectableItemBackground) .clickHandler(Spinner.onClick(c)) .child(createSelectedItemText(c, selection, (int) selectedTextSize, selectedTextColor)) .child(createCaret(c, caret, isShowingDropDown)) .accessibilityRole(AccessibilityRole.DROP_DOWN_LIST) .build(); }
Example #11
Source File: LayoutSpecLifecycleTesterSpec.java From litho with Apache License 2.0 | 6 votes |
@OnCreateLayout static Component onCreateLayout( ComponentContext c, @Prop List<LifecycleStep.StepInfo> steps, @Prop(optional = true) @Nullable Caller caller, @State String state, @CachedValue int expensiveValue) { steps.add(new StepInfo(LifecycleStep.ON_CREATE_LAYOUT)); if (state == null) { throw new IllegalStateException("OnCreateLayout called without initialised state."); } if (caller != null) { caller.set(c, steps); } return Column.create(c).build(); }
Example #12
Source File: ErrorRootComponentSpec.java From litho with Apache License 2.0 | 5 votes |
@OnCreateLayout static Component onCreateLayout(ComponentContext c, @Prop List<ListRow> dataModels) { return RecyclerCollectionComponent.create(c) .disablePTR(true) .section( DataDiffSection.<ListRow>create(new SectionContext(c)) .data(dataModels) .renderEventHandler(ErrorRootComponent.onRender(c)) .build()) .paddingDip(YogaEdge.TOP, 8) .build(); }
Example #13
Source File: AttachDetachTesterSpec.java From litho with Apache License 2.0 | 5 votes |
@OnCreateLayout static Component onCreateLayout( ComponentContext c, @Prop List<String> steps, @Prop(optional = true) AttachDetachTester.Builder[] children) { final Row.Builder containerBuilder = Row.create(c); if (children != null) { for (AttachDetachTester.Builder child : children) { containerBuilder.child(child.steps(steps)); } } return containerBuilder.build(); }
Example #14
Source File: OneByOneLeftRightBlocksComponentSpec.java From litho with Apache License 2.0 | 5 votes |
@OnCreateLayout static Component onCreateLayout(ComponentContext c, @State int state) { final boolean redLeft = state == 0 || state == 4 || state == 5; final boolean blueLeft = state == 0 || state == 1 || state == 5; final boolean greenLeft = state == 0 || state == 1 || state == 2; return Column.create(c) .child( Column.create(c) .alignItems(redLeft ? YogaAlign.FLEX_START : YogaAlign.FLEX_END) .child( Row.create(c) .heightDip(40) .widthDip(40) .backgroundColor(Color.parseColor("#ee1111")) .transitionKey(TRANSITION_KEY_RED) .build())) .child( Column.create(c) .alignItems(blueLeft ? YogaAlign.FLEX_START : YogaAlign.FLEX_END) .child( Row.create(c) .heightDip(40) .widthDip(40) .backgroundColor(Color.parseColor("#1111ee")) .transitionKey(TRANSITION_KEY_BLUE) .build())) .child( Column.create(c) .alignItems(greenLeft ? YogaAlign.FLEX_START : YogaAlign.FLEX_END) .child( Row.create(c) .heightDip(40) .widthDip(40) .backgroundColor(Color.parseColor("#11ee11")) .transitionKey(TRANSITION_KEY_GREEN) .build())) .clickHandler(OneByOneLeftRightBlocksComponent.onClick(c)) .build(); }
Example #15
Source File: DelegateMethodValidation.java From litho with Apache License 2.0 | 5 votes |
static List<SpecModelValidationError> validateLayoutSpecModel(LayoutSpecModel specModel) { List<SpecModelValidationError> validationErrors = new ArrayList<>(); validationErrors.addAll( validateMethods( specModel, DelegateMethodDescriptions.LAYOUT_SPEC_DELEGATE_METHODS_MAP, DelegateMethodDescriptions.INTER_STAGE_INPUTS_MAP)); final SpecMethodModel<DelegateMethod, Void> onCreateLayoutModel = SpecModelUtils.getMethodModelWithAnnotation(specModel, OnCreateLayout.class); final SpecMethodModel<DelegateMethod, Void> onCreateLayoutWithSizeSpecModel = SpecModelUtils.getMethodModelWithAnnotation(specModel, OnCreateLayoutWithSizeSpec.class); if (onCreateLayoutModel == null && onCreateLayoutWithSizeSpecModel == null) { validationErrors.add( new SpecModelValidationError( specModel.getRepresentedObject(), "You need to have a method annotated with either @OnCreateLayout " + "or @OnCreateLayoutWithSizeSpec in your spec. In most cases, @OnCreateLayout " + "is what you want.")); } else if (onCreateLayoutModel != null && onCreateLayoutWithSizeSpecModel != null) { validationErrors.add( new SpecModelValidationError( specModel.getRepresentedObject(), "Your LayoutSpec should have a method annotated with either @OnCreateLayout " + "or @OnCreateLayoutWithSizeSpec, but not both. In most cases, @OnCreateLayout " + "is what you want.")); } return validationErrors; }
Example #16
Source File: TransitionEndCallbackTestComponentSpec.java From litho with Apache License 2.0 | 5 votes |
@OnCreateLayout static Component onCreateLayout(ComponentContext c, @Prop Caller caller, @State boolean state) { caller.set(c); Component component = null; switch (caller.testType) { case SAME_KEY: component = getSameKeyTestComponent(c, state); break; case DISAPPEAR: component = getDisappearComponent(c, state); break; } return component; }
Example #17
Source File: PossiblyCrashingSubTitleComponentSpec.java From litho with Apache License 2.0 | 5 votes |
@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(); }
Example #18
Source File: RootDiffingComponentSpec.java From litho with Apache License 2.0 | 5 votes |
@OnCreateLayout static Component onCreateLayout(ComponentContext c) { return Column.create(c) .child( RecyclerCollectionComponent.create(c) .section(TopDiffingGroupSection.create(new SectionContext(c)).build()) .flexGrow(1f) .build()) .build(); }
Example #19
Source File: TitleComponentSpec.java From litho with Apache License 2.0 | 5 votes |
@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(); }
Example #20
Source File: PlaygroundComponentSpec.java From litho with Apache License 2.0 | 5 votes |
@OnCreateLayout static Component onCreateLayout(ComponentContext c) { return Column.create(c) .backgroundColor(Color.WHITE) .child(Text.create(c).textSizeSp(20).text("Playground sample")) .build(); }
Example #21
Source File: VerticalDashPathEffectBorderSpec.java From litho with Apache License 2.0 | 5 votes |
@OnCreateLayout static Component onCreateLayout(ComponentContext c) { return Row.create(c) .child( Text.create(c) .textSizeSp(20) .text("This component has a dash path effect on its vertical edges")) .border( Border.create(c) .color(YogaEdge.VERTICAL, NiceColor.RED) .widthDip(YogaEdge.ALL, 5) .dashEffect(new float[] {20f, 5f}, 0f) .build()) .build(); }
Example #22
Source File: CustomEventTriggerExampleComponentSpec.java From litho with Apache License 2.0 | 5 votes |
@OnCreateLayout static Component onCreateLayout(ComponentContext c) { final Handle textInputHandle = new Handle(); return Column.create(c) .child( Text.create(c, android.R.attr.buttonStyle, 0) .text("Trigger custom event") .clickHandler(CustomEventTriggerExampleComponent.onClick(c, textInputHandle))) .child(ComponentWithCustomEventTriggerComponent.create(c).handle(textInputHandle)) .build(); }
Example #23
Source File: ToggleMoveBlocksExampleComponentSpec.java From litho with Apache License 2.0 | 5 votes |
@OnCreateLayout static Component onCreateLayout(ComponentContext c, @State int state, @State boolean running) { final boolean redLeft = state == 0 || state == 4 || state == 5; final boolean blueLeft = state == 0 || state == 1 || state == 5; final boolean greenLeft = state == 0 || state == 1 || state == 2; return Column.create(c) .child(Row.create(c).child(Text.create(c).text(running ? "RUNNING" : "STOPPED"))) .child( Column.create(c) .alignItems(redLeft ? YogaAlign.FLEX_START : YogaAlign.FLEX_END) .child( Row.create(c) .heightDip(40) .widthDip(40) .backgroundColor(Color.parseColor("#ee1111")) .transitionKey(TRANSITION_KEY_RED) .build())) .child( Column.create(c) .alignItems(blueLeft ? YogaAlign.FLEX_START : YogaAlign.FLEX_END) .child( Row.create(c) .heightDip(40) .widthDip(40) .backgroundColor(Color.parseColor("#1111ee")) .transitionKey(TRANSITION_KEY_BLUE) .build())) .child( Column.create(c) .alignItems(greenLeft ? YogaAlign.FLEX_START : YogaAlign.FLEX_END) .child( Row.create(c) .heightDip(40) .widthDip(40) .backgroundColor(Color.parseColor("#11ee11")) .transitionKey(TRANSITION_KEY_GREEN) .build())) .clickHandler(ToggleMoveBlocksExampleComponent.onClick(c)) .build(); }
Example #24
Source File: SingleComponentMovesTransitionSpec.java From litho with Apache License 2.0 | 5 votes |
@OnCreateLayout static Component onCreateLayout(ComponentContext c, @State boolean shouldAlignStart) { return Column.create(c) .paddingDip(YogaEdge.ALL, 20) .alignItems(shouldAlignStart ? YogaAlign.FLEX_START : YogaAlign.FLEX_END) .child(Row.create(c).heightDip(SIZE_DP).widthDip(SIZE_DP).backgroundColor(Color.RED)) .clickHandler(SingleComponentMovesTransition.onClick(c)) .build(); }
Example #25
Source File: UpDownBlocksComponentSpec.java From litho with Apache License 2.0 | 5 votes |
@OnCreateLayout static Component onCreateLayout(ComponentContext c, @State boolean top) { return Row.create(c) .heightDip(200) .alignItems(top ? YogaAlign.FLEX_START : YogaAlign.FLEX_END) .child( Row.create(c) .heightDip(40) .flexGrow(1) .backgroundColor(Color.parseColor("#ee1111")) .transitionKey("red") .build()) .child( Row.create(c) .heightDip(40) .flexGrow(1) .backgroundColor(Color.parseColor("#1111ee")) .transitionKey("blue") .build()) .child( Row.create(c) .heightDip(40) .flexGrow(1) .backgroundColor(Color.parseColor("#11ee11")) .transitionKey("green") .build()) .clickHandler(UpDownBlocksComponent.onClick(c)) .build(); }
Example #26
Source File: DemoListComponentSpec.java From litho-picasso with MIT License | 5 votes |
@OnCreateLayout static Component onCreateLayout(ComponentContext c) { final RecyclerBinder recyclerBinder = new RecyclerBinder.Builder().layoutInfo( new LinearLayoutInfo(c, OrientationHelper.VERTICAL, false)).build(c); Demos.addAllToBinder(recyclerBinder, c); return Recycler.create(c) .binder(recyclerBinder) .flexShrink(0) .testKey(MAIN_SCREEN) .build(); }
Example #27
Source File: FeedItemComponentSpec.java From litho-picasso with MIT License | 5 votes |
@OnCreateLayout static Component onCreateLayout(ComponentContext c, @Prop final ArtistDatum artist, @Prop final RecyclerBinder binder) { return Column.create(c) .child(Column.create(c) .child(artist.getImages().length == 1 ? getImageComponent(c, artist) : getRecyclerComponent(c, binder)) .child(TitleComponent.create(c).title(artist.getName())) .child(ActionsComponent.create(c))) .child(FooterComponent.create(c).text(artist.getBiography())) .build(); }
Example #28
Source File: LearningPropsComponentSpec.java From litho with Apache License 2.0 | 5 votes |
@OnCreateLayout static Component onCreateLayout(ComponentContext c, @Prop String text1, @Prop String text2) { return Column.create(c) .child(Text.create(c).text(text1).textSizeDip(50)) .child( Text.create(c).text(text2).textColorRes(android.R.color.holo_green_dark).textSizeSp(30)) .build(); }
Example #29
Source File: StateContainerGeneratorTest.java From litho with Apache License 2.0 | 5 votes |
@OnCreateLayout public void onCreateLayout( @Prop boolean arg0, @State int arg1, @Param Object arg2, @TreeProp long arg3, @State(canUpdateLazily = true) boolean arg4) {}
Example #30
Source File: FeedItemComponentSpec.java From litho-glide with MIT License | 5 votes |
@OnCreateLayout static Component onCreateLayout(ComponentContext c, @Prop final ArtistDatum artist, @Prop final RecyclerBinder binder) { return Column.create(c) .child(Column.create(c) .child(artist.getImages().length == 1 ? getImageComponent(c, artist) : getRecyclerComponent(c, binder)) .child(TitleComponent.create(c).title(artist.getName())) .child(ActionsComponent.create(c))) .child(FooterComponent.create(c).text(artist.getBiography())) .build(); }