com.facebook.litho.annotations.FromEvent Java Examples
The following examples show how to use
com.facebook.litho.annotations.FromEvent.
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: SharedElementsComponentSpec.java From litho with Apache License 2.0 | 6 votes |
@OnEvent(ClickEvent.class) static void onClickEvent( ComponentContext c, @FromEvent View view, @Param int color, @State boolean landLitho) { Activity activity = (Activity) c.getAndroidContext(); Intent intent = new Intent(c.getAndroidContext(), DetailActivity.class); intent.putExtra(INTENT_COLOR_KEY, color); intent.putExtra(INTENT_LAND_LITHO, landLitho); ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation( activity, new Pair<View, String>(view, SQUARE_TRANSITION_NAME), new Pair<View, String>( activity.getWindow().getDecorView().findViewWithTag(TITLE_TRANSITION_NAME), TITLE_TRANSITION_NAME)); activity.startActivity(intent, options.toBundle()); }
Example #2
Source File: ComposedAnimationsComponentSpec.java From litho with Apache License 2.0 | 6 votes |
@OnEvent(RenderEvent.class) static RenderInfo onRender(ComponentContext c, @FromEvent int index) { final int numDemos = 5; Component component; // Keep alternating between demos switch (index % numDemos) { case 0: component = StoryFooterComponent.create(c).key("footer").build(); break; case 1: component = UpDownBlocksComponent.create(c).build(); break; case 2: component = LeftRightBlocksComponent.create(c).build(); break; case 3: component = OneByOneLeftRightBlocksComponent.create(c).build(); break; case 4: component = LeftRightBlocksSequenceComponent.create(c).build(); break; default: throw new RuntimeException("Bad index: " + index); } return ComponentRenderInfo.create().component(component).build(); }
Example #3
Source File: ListSectionSpec.java From litho with Apache License 2.0 | 6 votes |
@OnEvent(RenderEvent.class) static RenderInfo onRender(final SectionContext c, @FromEvent Integer model) { if (model.intValue() == 1) { return ViewRenderInfo.create() .viewBinder( new SimpleViewBinder<TextView>() { @Override public void bind(TextView textView) { textView.setText("I'm a view in a Litho world"); } }) .viewCreator(VIEW_CREATOR) .build(); } return ComponentRenderInfo.create() .component( ListItem.create(c) .color(model % 2 == 0 ? Color.WHITE : Color.LTGRAY) .title(model + ". Hello, world!") .subtitle("Litho tutorial") .build()) .build(); }
Example #4
Source File: BorderEffectsComponentSpec.java From litho with Apache License 2.0 | 6 votes |
@OnEvent(RenderEvent.class) static RenderInfo onRender(ComponentContext c, @FromEvent Class<? extends Component> model) { try { Method createMethod = model.getMethod("create", ComponentContext.class); Component.Builder componentBuilder = (Component.Builder) createMethod.invoke(null, c); return ComponentRenderInfo.create().component(componentBuilder.build()).build(); } catch (NoSuchMethodException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { return ComponentRenderInfo.create() .component(Text.create(c).textSizeDip(32).text(ex.getLocalizedMessage()).build()) .build(); } }
Example #5
Source File: HorizontalScrollWithSnapComponentSpec.java From litho with Apache License 2.0 | 6 votes |
@OnEvent(RenderEvent.class) static RenderInfo onRender(ComponentContext c, @FromEvent Object model, @FromEvent int index) { return ComponentRenderInfo.create() .component( Row.create(c) .justifyContent(YogaJustify.CENTER) .widthDip(120) .heightDip(120) .backgroundColor((int) model) .child( Text.create(c) .textSizeSp(20) .textColor(Color.LTGRAY) .text(Integer.toString(index)) .verticalGravity(VerticalGravity.CENTER))) .build(); }
Example #6
Source File: TransitionEndCallbackTestComponentSpec.java From litho with Apache License 2.0 | 6 votes |
@OnEvent(TransitionEndEvent.class) static void onTransitionEnd( ComponentContext c, @FromEvent String transitionKey, @FromEvent AnimatedProperty property, @State boolean state, @Prop Caller caller) { switch (caller.testType) { case SAME_KEY: if (property == AnimatedProperties.X) { caller.transitionEndMessage = ANIM_X; } else { caller.transitionEndMessage = ANIM_ALPHA; } break; case DISAPPEAR: caller.transitionEndMessage = !state ? ANIM_DISAPPEAR : ""; break; } }
Example #7
Source File: TestMountSpec.java From litho with Apache License 2.0 | 5 votes |
@OnEvent(ClickEvent.class) static void testLayoutEvent( ComponentContext c, @Prop Object prop3, @Prop char prop5, @FromEvent View view, @Param int param1, @State(canUpdateLazily = true) long state1, @CachedValue int cached) {}
Example #8
Source File: DemoListItemComponentSpec.java From litho with Apache License 2.0 | 5 votes |
@OnEvent(ClickEvent.class) static void onClick( ComponentContext c, @FromEvent View view, @Prop final DemoListActivity.DemoListDataModel model, @Prop final int[] currentIndices) { final Intent intent = new Intent( c.getAndroidContext(), model.datamodels == null ? model.klass : DemoListActivity.class); intent.putExtra(DemoListActivity.INDICES, currentIndices); c.getAndroidContext().startActivity(intent); }
Example #9
Source File: BlocksSameTransitionKeyComponentSpec.java From litho with Apache License 2.0 | 5 votes |
@OnEvent(TransitionEndEvent.class) static void onTransitionEndEvent( ComponentContext c, @State Set<String> runningAnimations, @FromEvent String transitionKey, @FromEvent AnimatedProperty property) { if (property == AnimatedProperties.X) { BlocksSameTransitionKeyComponent.updateRunningAnimations(c, ANIM_X); BlocksSameTransitionKeyComponent.updateStateSync(c, false); } else { BlocksSameTransitionKeyComponent.updateRunningAnimations(c, ANIM_ALPHA); } }
Example #10
Source File: DemoListComponentSpec.java From litho with Apache License 2.0 | 5 votes |
@OnEvent(RenderEvent.class) static RenderInfo onRender( ComponentContext c, @Prop @Nullable int[] parentIndices, @FromEvent DemoListActivity.DemoListDataModel model, @FromEvent int index) { return ComponentRenderInfo.create() .component( DemoListItemComponent.create(c) .model(model) .currentIndices(getUpdatedIndices(parentIndices, index)) .build()) .build(); }
Example #11
Source File: DemoListComponentSpec.java From litho with Apache License 2.0 | 5 votes |
/** * Called during DataDiffSection's diffing to determine if two objects represent the same item. * See {@link androidx.recyclerview.widget.DiffUtil.Callback#areItemsTheSame(int, int)} for more * info. * * @return true if the two objects in the event represent the same item. */ @OnEvent(OnCheckIsSameItemEvent.class) static boolean isSameItem( ComponentContext c, @FromEvent DemoListActivity.DemoListDataModel previousItem, @FromEvent DemoListActivity.DemoListDataModel nextItem) { return previousItem == nextItem; }
Example #12
Source File: DemoListComponentSpec.java From litho with Apache License 2.0 | 5 votes |
/** * Called during DataDiffSection's diffing to determine if two objects contain the same data. This * is used to detect of contents of an item have changed. See {@link * androidx.recyclerview.widget.DiffUtil.Callback#areContentsTheSame(int, int)} for more info. * * @return true if the two objects contain the same data. */ @OnEvent(OnCheckIsSameContentEvent.class) static boolean isSameContent( ComponentContext c, @FromEvent DemoListActivity.DemoListDataModel previousItem, @FromEvent DemoListActivity.DemoListDataModel nextItem) { // We're only displaying the name so checking if that's equal here is enough for our use case. return previousItem == null ? nextItem == null : previousItem.name == null ? nextItem.name == null : nextItem.name.equals(previousItem.name); }
Example #13
Source File: FastScrollHandleComponentSpec.java From litho with Apache License 2.0 | 5 votes |
@OnEvent(TouchEvent.class) static boolean onTouchEvent( ComponentContext c, @FromEvent View view, @FromEvent MotionEvent motionEvent, @State ScrollController scrollController) { return scrollController.onTouch(view, motionEvent); }
Example #14
Source File: OnClickCallbackComponentSpec.java From litho with Apache License 2.0 | 5 votes |
@OnEvent(ClickEvent.class) static void onClick( final ComponentContext c, final @Prop View.OnClickListener callback, final @FromEvent View view) { callback.onClick(view); }
Example #15
Source File: EventGeneratorTest.java From litho with Apache License 2.0 | 5 votes |
@OnEvent(Object.class) public void testEventMethod1( @Prop boolean arg0, @State int arg1, @Param Object arg2, @Param T arg3, @FromEvent long arg4, @Param @Nullable T arg6) {}
Example #16
Source File: FullGroupSectionSpec.java From litho with Apache License 2.0 | 5 votes |
@OnEvent(ClickEvent.class) static void testEvent( SectionContext c, @FromEvent(baseClass = View.class) TextView view, @Param int someParam, @State(canUpdateLazily = true) Object state2, @Prop(optional = true) String prop2) {}
Example #17
Source File: TestLayoutSpec.java From litho with Apache License 2.0 | 5 votes |
@OnEvent(ClickEvent.class) static void testLayoutEvent( ComponentContext c, @FromEvent View view, @Param int param1, @Prop @Nullable Object prop3, @Prop char prop5, @Prop(isCommonProp = true) float aspectRatio, @Prop(isCommonProp = true, overrideCommonPropBehavior = true) boolean focusable, @State(canUpdateLazily = true) long state1) {}
Example #18
Source File: TestGroupSectionSpec.java From litho with Apache License 2.0 | 5 votes |
@OnEvent(OnCheckIsSameItemEvent.class) protected static boolean onCheckIsSameItem( SectionContext c, @FromEvent Object previousItem, @FromEvent Object nextItem, @Prop(optional = true) Comparator isSameItemComparator) { return isSameItemComparator.compare(previousItem, nextItem) == 0; }
Example #19
Source File: HideableDataDiffSectionSpec.java From litho with Apache License 2.0 | 5 votes |
@OnEvent(RenderEvent.class) protected static RenderInfo onRenderEvent( SectionContext c, @FromEvent int index, @FromEvent Object model, @FromEvent Bundle loggingExtras, @Prop EventHandler<RenderWithHideItemHandlerEvent> renderWithHideItemHandler) { return HideableDataDiffSection.dispatchRenderWithHideItemHandlerEvent( renderWithHideItemHandler, index, model, HideableDataDiffSection.onHideItem(c), loggingExtras); }
Example #20
Source File: HideableDataDiffSectionSpec.java From litho with Apache License 2.0 | 5 votes |
@OnEvent(HideItemEvent.class) public static void onHideItem( SectionContext c, @FromEvent Object model, @Prop EventHandler<GetUniqueIdentifierEvent> getUniqueIdentifierHandler) { HideableDataDiffSection.onBlacklistUpdateSync(c, model, getUniqueIdentifierHandler); }
Example #21
Source File: ErrorEventHandlerGenerator.java From litho with Apache License 2.0 | 5 votes |
/** * Generate a spec method model which corresponds to a source error declaration like this: * * <pre><code> * {@literal @}OnEvent(ErrorEvent.class) * static void __internalOnErrorEvent(ComponentContext c, @FromEvent Exception exception) {} * </code></pre> * * This is used to automatically generate this method stub when an <code>@OnError</code> * declaration is used. */ public static SpecMethodModel<EventMethod, EventDeclarationModel> generateErrorEventHandlerDefinition() { return SpecMethodModel.<EventMethod, EventDeclarationModel>builder() .modifiers(ImmutableList.of(Modifier.STATIC)) .name(EventCaseGenerator.INTERNAL_ON_ERROR_HANDLER_NAME) .returnTypeSpec(new TypeSpec(TypeName.VOID)) .typeVariables(ImmutableList.of()) .methodParams( ImmutableList.of( new SimpleMethodParamModel( new TypeSpec(ClassNames.COMPONENT_CONTEXT), "c", ImmutableList.of(), ImmutableList.of(), null), new SimpleMethodParamModel( new TypeSpec(ClassName.bestGuess("java.lang.Exception")), "exception", ImmutableList.of((Annotation) () -> FromEvent.class), ImmutableList.of(), null))) .typeModel( new EventDeclarationModel( ClassNames.ERROR_EVENT, TypeName.VOID, ImmutableList.of( new FieldModel( FieldSpec.builder( ClassName.bestGuess("java.lang.Exception"), "exception", Modifier.PUBLIC) .build(), null)), null)) .build(); }
Example #22
Source File: EventValidation.java From litho with Apache License 2.0 | 5 votes |
private static boolean hasPermittedAnnotation(MethodParamModel methodParam) { return MethodParamModelUtils.isAnnotatedWith(methodParam, FromEvent.class) || MethodParamModelUtils.isAnnotatedWith(methodParam, Prop.class) || MethodParamModelUtils.isAnnotatedWith(methodParam, InjectProp.class) || MethodParamModelUtils.isAnnotatedWith(methodParam, TreeProp.class) || MethodParamModelUtils.isAnnotatedWith(methodParam, CachedValue.class) || MethodParamModelUtils.isAnnotatedWith(methodParam, State.class) || MethodParamModelUtils.isAnnotatedWith(methodParam, Param.class); }
Example #23
Source File: EventValidation.java From litho with Apache License 2.0 | 5 votes |
private static boolean isFromEventTypeSpecifiedInAnnotation( MethodParamModel methodParamModel, TypeName eventFieldType) { FromEvent fromEvent = (FromEvent) MethodParamModelUtils.getAnnotation(methodParamModel, FromEvent.class); TypeName baseClassType; try { baseClassType = ClassName.get(fromEvent.baseClass()); } catch (MirroredTypeException mte) { baseClassType = ClassName.get(mte.getTypeMirror()); } return baseClassType.equals(eventFieldType); }
Example #24
Source File: StoryCardsWithHeaderSectionSpec.java From litho with Apache License 2.0 | 5 votes |
@OnEvent(RenderEvent.class) static RenderInfo renderStory(SectionContext c, @FromEvent String model, @FromEvent int index) { return ComponentRenderInfo.create() .component( StoryCardComponent.create(c) .content(model) .header( StoryHeaderComponent.create(c) .title("Story #" + index) .subtitle("subtitle") .build()) .build()) .build(); }
Example #25
Source File: TTIMarkerSectionSpec.java From litho with Apache License 2.0 | 5 votes |
@OnEvent(RenderEvent.class) static RenderInfo onRender(final SectionContext c, @FromEvent String model) { return ComponentRenderInfo.create() .component(Text.create(c).text(model).textSizeSp(14).build()) .renderCompleteHandler(TTIMarkerSection.onRenderComplete(c, RENDER_MARKER)) .build(); }
Example #26
Source File: TTIMarkerSectionSpec.java From litho with Apache License 2.0 | 5 votes |
@OnEvent(RenderCompleteEvent.class) static void onRenderComplete( SectionContext c, @Param String renderMarker, @FromEvent RenderCompleteEvent.RenderState renderState, @FromEvent long timestampMillis) { final boolean hasMounted = renderState == RenderCompleteEvent.RenderState.RENDER_DRAWN; Toast.makeText(c.getAndroidContext(), renderMarker, Toast.LENGTH_SHORT).show(); }
Example #27
Source File: DemoListItemComponentSpec.java From litho-glide with MIT License | 5 votes |
@OnEvent(ClickEvent.class) static void onClick( ComponentContext c, @FromEvent View view, @Prop final String name) { final Intent intent = new Intent(c.getAndroidContext(), DemoActivity.class); intent.putExtra("demoName", name); c.getAndroidContext().startActivity(intent); }
Example #28
Source File: DemoListItemComponentSpec.java From litho-picasso with MIT License | 5 votes |
@OnEvent(ClickEvent.class) static void onClick( ComponentContext c, @FromEvent View view, @Prop final String name) { final Intent intent = new Intent(c.getAndroidContext(), DemoActivity.class); intent.putExtra("demoName", name); c.getAndroidContext().startActivity(intent); }
Example #29
Source File: SimpleListSectionSpec.java From fresco with MIT License | 5 votes |
@OnEvent(RenderEvent.class) static RenderInfo onRender(final SectionContext c, @FromEvent Data model) { return ComponentRenderInfo.create() .component( SimpleListItem.create(c) .profilePicture(model.profilePicture) .mainPicture(model.mainPicture) .title(model.title)) .build(); }
Example #30
Source File: SimpleGallerySectionSpec.java From fresco with MIT License | 5 votes |
@OnEvent(RenderEvent.class) static RenderInfo onRender(final SectionContext c, @FromEvent Uri model) { return ComponentRenderInfo.create() .component( FrescoVitoImage2.create(c) .uri(model) .imageOptions(IMAGE_OPTIONS) .paddingDip(YogaEdge.ALL, 2)) .build(); }