com.facebook.litho.ClickEvent Java Examples

The following examples show how to use com.facebook.litho.ClickEvent. 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: FullGroupSection.java    From litho with Apache License 2.0 6 votes vote down vote up
@Override
public Object dispatchOnEvent(final EventHandler eventHandler, final Object eventState) {
  int id = eventHandler.id;
  switch (id) {
    case -1204074200:
      {
        ClickEvent _event = (ClickEvent) eventState;
        testEvent(
            eventHandler.mHasEventDispatcher,
            (SectionContext) eventHandler.params[0],
            (TextView) _event.view,
            (int) eventHandler.params[1]);
        return null;
      }
    default:
      return null;
  }
}
 
Example #2
Source File: TestMount.java    From litho with Apache License 2.0 6 votes vote down vote up
@Override
public Object dispatchOnEvent(final EventHandler eventHandler, final Object eventState) {
  int id = eventHandler.id;
  switch (id) {
    case 1328162206:
      {
        ClickEvent _event = (ClickEvent) eventState;
        testLayoutEvent(
            eventHandler.mHasEventDispatcher,
            (ComponentContext) eventHandler.params[0],
            (View) _event.view,
            (int) eventHandler.params[1]);
        return null;
      }
    case -1048037474:
      {
        dispatchErrorEvent(
            (com.facebook.litho.ComponentContext) eventHandler.params[0],
            (com.facebook.litho.ErrorEvent) eventState);
        return null;
      }
    default:
      return null;
  }
}
 
Example #3
Source File: TestLayoutSpec.java    From litho with Apache License 2.0 6 votes vote down vote up
@OnCreateLayout
static <S extends View> Component onCreateLayout(
    ComponentContext context,
    @Prop @Nullable Object prop3,
    @Prop char[] prop4,
    @Prop EventHandler<ClickEvent> handler,
    @Prop Component child,
    @Prop(optional = true) boolean prop2,
    @Prop(resType = ResType.STRING, optional = true, varArg = "name") List<String> names,
    @State(canUpdateLazily = true) long state1,
    @State S state2,
    @State int state3,
    @TreeProp TestTreeProp treeProp,
    @CachedValue int cached) {
  return null;
}
 
Example #4
Source File: SharedElementsComponentSpec.java    From litho with Apache License 2.0 6 votes vote down vote up
@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 #5
Source File: FeedItemComponentSpecSubComponentTest.java    From litho with Apache License 2.0 6 votes vote down vote up
@Test
public void footerHasNoClickHandler() {
  final ComponentContext c = mComponentsRule.getContext();
  final Component component = makeComponentWithTextInSubcomponent("Any Text");

  // Components commonly have conditional handlers assigned. Using the clickHandler matcher
  // we can assert whether or not a given component has a handler attached to them.
  //noinspection unchecked
  assertThat(c, component)
      .extractingSubComponentAt(0)
      .has(
          subComponentWith(
              c,
              TestFooterComponent.matcher(c)
                  .clickHandler(IsNull.<EventHandler<ClickEvent>>nullValue(null))
                  .build()));
}
 
Example #6
Source File: HorizontalScrollRootComponentSpec.java    From litho with Apache License 2.0 6 votes vote down vote up
@OnEvent(ClickEvent.class)
static void onClick(
    ComponentContext c,
    @State(canUpdateLazily = true) int prependCounter,
    @State(canUpdateLazily = true) int appendCounter,
    @State ImmutableList<Pair<String, Integer>> items,
    @Param boolean isPrepend) {
  final ArrayList<Pair<String, Integer>> updatedItems = new ArrayList<>(items);
  if (isPrepend) {
    updatedItems.add(0, new Pair<>("Prepend#" + prependCounter, 0xFF7CFC00));
    HorizontalScrollRootComponent.lazyUpdatePrependCounter(c, ++prependCounter);
  } else {
    updatedItems.add(new Pair<>("Append#" + appendCounter, 0xFF6495ED));
    HorizontalScrollRootComponent.lazyUpdateAppendCounter(c, ++appendCounter);
  }
  HorizontalScrollRootComponent.updateItems(
      c, new ImmutableList.Builder<Pair<String, Integer>>().addAll(updatedItems).build());
}
 
Example #7
Source File: DemoListItemComponentTest.java    From litho with Apache License 2.0 6 votes vote down vote up
@Test
public void testComponentOnSyntheticEventClick() {
  final Class activityClassToLaunch = PlaygroundActivity.class;
  final Component component =
      DemoListItemComponent.create(mComponentsRule.getContext())
          .model(new DemoListActivity.DemoListDataModel("My Component", activityClassToLaunch))
          .currentIndices(null)
          .build();

  // Here, we make use of Litho's internal event infrastructure and manually dispatch the event.
  final ComponentContext componentContext =
      withComponentScope(mComponentsRule.getContext(), component);
  component.dispatchOnEvent(DemoListItemComponent.onClick(componentContext), new ClickEvent());

  final Intent nextIntent =
      shadowOf(ApplicationProvider.<Application>getApplicationContext()).getNextStartedActivity();
  assertThat(nextIntent.getComponent().getClassName()).isSameAs(activityClassToLaunch.getName());
}
 
Example #8
Source File: HorizontalScrollScrollerComponentSpec.java    From litho with Apache License 2.0 5 votes vote down vote up
@OnEvent(ClickEvent.class)
static void onClick(
    ComponentContext c,
    @Prop RecyclerCollectionEventsController eventsController,
    @Param boolean forward) {
  if (forward) {
    eventsController.requestScrollToNextPosition(true);
  } else {
    eventsController.requestScrollToPreviousPosition(true);
  }
}
 
Example #9
Source File: ExamplesActivityComponentSpec.java    From litho with Apache License 2.0 5 votes vote down vote up
private Populator addRow(String renderText, EventHandler<ClickEvent> clickEventHandler) {
  recyclerBinder.insertItemAt(
      position,
      ExamplesRowComponent.create(c)
          .text(renderText)
          .clickEventHandler(clickEventHandler)
          .build());
  position++;

  return this;
}
 
Example #10
Source File: ExpandingPickerComponentSpec.java    From litho with Apache License 2.0 5 votes vote down vote up
@OnEvent(ClickEvent.class)
static void onClickEvent(
    ComponentContext c,
    @State AtomicReference<Animator> animatorRef,
    @State AtomicReference<Boolean> isExpanded,
    @State DynamicValue<Float> expandedAmount,
    @State DynamicValue<Float> contractButtonRotation,
    @State DynamicValue<Float> contractButtonScale,
    @State DynamicValue<Float> contractButtonAlpha,
    @State DynamicValue<Float> expandButtonScale,
    @State DynamicValue<Float> expandButtonAlpha,
    @State DynamicValue<Float> menuButtonAlpha) {

  Animator oldAnimator = animatorRef.get();
  if (oldAnimator != null) {
    oldAnimator.cancel();
  }

  Animator newAnimator =
      createExpandCollapseAnimator(
          !Boolean.TRUE.equals(isExpanded.get()),
          expandedAmount,
          contractButtonRotation,
          contractButtonScale,
          contractButtonAlpha,
          expandButtonScale,
          expandButtonAlpha,
          menuButtonAlpha);
  isExpanded.set(!Boolean.TRUE.equals(isExpanded.get()));
  animatorRef.set(newAnimator);
  newAnimator.start();
}
 
Example #11
Source File: TestMountSpec.java    From litho with Apache License 2.0 5 votes vote down vote up
@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 #12
Source File: TestLayout.java    From litho with Apache License 2.0 5 votes vote down vote up
public static EventHandler<ClickEvent> testLayoutEvent(ComponentContext c, int param1) {
  return newEventHandler(
      c,
      1328162206,
      new Object[] {
        c, param1,
      });
}
 
Example #13
Source File: TestLayout.java    From litho with Apache License 2.0 5 votes vote down vote up
@Override
public Object acceptTriggerEvent(
    final EventTrigger eventTrigger, final Object eventState, final Object[] params) {
  int id = eventTrigger.mId;
  switch (id) {
    case -1670292499:
      {
        ClickEvent _event = (ClickEvent) eventState;
        onClickEventTrigger(eventTrigger.mTriggerTarget, _event.view);
        return null;
      }
    default:
      return null;
  }
}
 
Example #14
Source File: LearningStateComponentSpecTest.java    From litho with Apache License 2.0 5 votes vote down vote up
@Test
public void testNoComponentOnClick() {
  final ComponentContext c = mComponentsRule.getContext();
  final Component component = LearningStateComponent.create(c).canClick(false).build();

  LithoAssertions.assertThat(c, component)
      .has(
          SubComponentExtractor.subComponentWith(
              c,
              TestText.matcher(c)
                  .clickHandler(IsNull.<EventHandler<ClickEvent>>nullValue(null))
                  .build()));
}
 
Example #15
Source File: DemoListItemComponentSpec.java    From litho with Apache License 2.0 5 votes vote down vote up
@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 #16
Source File: TestMount.java    From litho with Apache License 2.0 5 votes vote down vote up
@Override
public Object acceptTriggerEvent(
    final EventTrigger eventTrigger, final Object eventState, final Object[] params) {
  int id = eventTrigger.mId;
  switch (id) {
    case -830639048:
      {
        ClickEvent _event = (ClickEvent) eventState;
        onClickEventTrigger(eventTrigger.mTriggerTarget, _event.view);
        return null;
      }
    default:
      return null;
  }
}
 
Example #17
Source File: BounceExampleComponentSpec.java    From litho with Apache License 2.0 5 votes vote down vote up
@OnEvent(ClickEvent.class)
static void onClick(
    ComponentContext c,
    @State AtomicReference<Animator> animatorRef,
    @State DynamicValue<Float> translationY) {
  Animator oldAnimator = animatorRef.get();
  if (oldAnimator != null) {
    oldAnimator.cancel();
  }

  final Animator newAnimator = createBounceAnimator(c, translationY);
  animatorRef.set(newAnimator);
  newAnimator.start();
}
 
Example #18
Source File: TestMount.java    From litho with Apache License 2.0 5 votes vote down vote up
public static void onClickEventTrigger(ComponentContext c, String key, View view) {
  int methodId = -830639048;
  EventTrigger trigger = getEventTrigger(c, methodId, key);
  if (trigger == null) {
    return;
  }
  ClickEvent _eventState = new ClickEvent();
  _eventState.view = view;
  trigger.dispatchOnTrigger(_eventState, new Object[] {});
}
 
Example #19
Source File: TestLayout.java    From litho with Apache License 2.0 5 votes vote down vote up
public static void onClickEventTrigger(ComponentContext c, String key, View view) {
  int methodId = -1670292499;
  EventTrigger trigger = getEventTrigger(c, methodId, key);
  if (trigger == null) {
    return;
  }
  ClickEvent _eventState = new ClickEvent();
  _eventState.view = view;
  trigger.dispatchOnTrigger(_eventState, new Object[] {});
}
 
Example #20
Source File: DemoListItemComponentSpec.java    From litho-glide with MIT License 5 votes vote down vote up
@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 #21
Source File: TestMount.java    From litho with Apache License 2.0 5 votes vote down vote up
public static EventHandler<ClickEvent> testLayoutEvent(ComponentContext c, int param1) {
  return newEventHandler(
      c,
      1328162206,
      new Object[] {
        c, param1,
      });
}
 
Example #22
Source File: ExamplesActivityComponentSpec.java    From litho with Apache License 2.0 5 votes vote down vote up
@OnEvent(ClickEvent.class)
static void onClickProps(
    ComponentContext c,
    @Prop ExamplesLithoLabActivity.LabExampleController labExampleController) {
  labExampleController.setContentComponent(
      LearningPropsComponent.create(c).text1("Props, world!").text2("World, props!").build());
}
 
Example #23
Source File: TestLayoutSpec.java    From litho with Apache License 2.0 5 votes vote down vote up
@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 #24
Source File: ExamplesActivityComponentSpec.java    From litho with Apache License 2.0 5 votes vote down vote up
@OnEvent(ClickEvent.class)
static void onClickClickEvents(
    ComponentContext c,
    @Prop ExamplesLithoLabActivity.LabExampleController labExampleController) {
  labExampleController.setContentComponent(
      LearningClickEventsComponent.create(c)
          .secondChildString("Prop passed in from parent.")
          .build());
}
 
Example #25
Source File: FullGroupSectionSpec.java    From litho with Apache License 2.0 5 votes vote down vote up
@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 #26
Source File: LifecycleDelegateComponentSpec.java    From litho with Apache License 2.0 5 votes vote down vote up
@OnEvent(ClickEvent.class)
static void onClickStateUpdate(ComponentContext c, @State Random random, @Param boolean isSync) {
  if (isSync) {
    LifecycleDelegateComponent.updateBricksSync(c, random);
  } else {
    LifecycleDelegateComponent.updateBricksAsync(c, random);
  }
}
 
Example #27
Source File: FullGroupSection.java    From litho with Apache License 2.0 5 votes vote down vote up
public static EventHandler<ClickEvent> testEvent(SectionContext c, int someParam) {
  return newEventHandler(
      c,
      -1204074200,
      new Object[] {
        c, someParam,
      });
}
 
Example #28
Source File: VerySimpleGroupSectionSpecTest.java    From litho with Apache License 2.0 5 votes vote down vote up
@Test
public void testClickHandler() throws Exception {
  Section s =
      mTester.prepare(
          VerySimpleGroupSection.create(mTester.getContext()).numberOfDummy(4).build());

  SectionsTestHelper.dispatchEvent(
      s, VerySimpleGroupSection.onImageClick(mTester.getScopedContext(s)), new ClickEvent());

  VerySimpleGroupSection.VerySimpleGroupSectionStateContainer stateContainer =
      mTester.getStateContainer(s);

  assertThat(stateContainer.extra).isEqualTo(3);
}
 
Example #29
Source File: LithoClassNamesTest.java    From litho with Apache License 2.0 5 votes vote down vote up
@Test
public void names() {
  Assert.assertEquals(ClickEvent.class.getName(), LithoClassNames.CLICK_EVENT_CLASS_NAME);
  Assert.assertEquals(
      ComponentContext.class.getName(), LithoClassNames.COMPONENT_CONTEXT_CLASS_NAME);
  Assert.assertEquals(Section.class.getName(), LithoClassNames.SECTION_CLASS_NAME);
  Assert.assertEquals(SectionContext.class.getName(), LithoClassNames.SECTION_CONTEXT_CLASS_NAME);
}
 
Example #30
Source File: OnClickCallbackComponentSpec.java    From litho with Apache License 2.0 5 votes vote down vote up
@OnEvent(ClickEvent.class)
static void onClick(
    final ComponentContext c,
    final @Prop View.OnClickListener callback,
    final @FromEvent View view) {
  callback.onClick(view);
}