com.facebook.litho.annotations.OnMount Java Examples

The following examples show how to use com.facebook.litho.annotations.OnMount. 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: CardClipSpec.java    From litho with Apache License 2.0 6 votes vote down vote up
@OnMount
static void onMount(
    ComponentContext c,
    CardClipDrawable cardClipDrawable,
    @Prop(optional = true, resType = ResType.COLOR) int clippingColor,
    @Prop(optional = true, resType = ResType.DIMEN_OFFSET) float cornerRadius,
    @Prop(optional = true) boolean disableClipTopLeft,
    @Prop(optional = true) boolean disableClipTopRight,
    @Prop(optional = true) boolean disableClipBottomLeft,
    @Prop(optional = true) boolean disableClipBottomRight) {
  cardClipDrawable.setClippingColor(clippingColor);
  cardClipDrawable.setCornerRadius(cornerRadius);
  int clipEdge =
      (disableClipTopLeft ? TOP_LEFT : NONE)
          | (disableClipTopRight ? TOP_RIGHT : NONE)
          | (disableClipBottomLeft ? BOTTOM_LEFT : NONE)
          | (disableClipBottomRight ? BOTTOM_RIGHT : NONE);
  cardClipDrawable.setDisableClip(clipEdge);
}
 
Example #2
Source File: ProgressSpec.java    From litho with Apache License 2.0 6 votes vote down vote up
@OnMount
static void onMount(
    ComponentContext c,
    ProgressBar progressBar,
    @Prop(optional = true, resType = ResType.COLOR) int color,
    @FromPrepare Drawable resolvedIndeterminateDrawable) {

  if (resolvedIndeterminateDrawable != null) {
    progressBar.setIndeterminateDrawable(resolvedIndeterminateDrawable);
  }

  if (color != Color.TRANSPARENT && progressBar.getIndeterminateDrawable() != null) {
    progressBar
        .getIndeterminateDrawable()
        .mutate()
        .setColorFilter(color, PorterDuff.Mode.MULTIPLY);
  }
}
 
Example #3
Source File: CardShadowSpec.java    From litho with Apache License 2.0 6 votes vote down vote up
@OnMount
static void onMount(
    ComponentContext context,
    CardShadowDrawable cardShadowDrawable,
    @Prop(optional = true, resType = ResType.COLOR) int shadowStartColor,
    @Prop(optional = true, resType = ResType.COLOR) int shadowEndColor,
    @Prop(optional = true, resType = ResType.DIMEN_OFFSET) float cornerRadius,
    @Prop(optional = true, resType = ResType.DIMEN_SIZE) float shadowSize,
    @Prop(optional = true, resType = ResType.DIMEN_OFFSET) float shadowDx,
    @Prop(optional = true, resType = ResType.DIMEN_OFFSET) float shadowDy,
    @Prop(optional = true) boolean hideTopShadow,
    @Prop(optional = true) boolean hideBottomShadow) {

  cardShadowDrawable.setShadowStartColor(shadowStartColor);
  cardShadowDrawable.setShadowEndColor(shadowEndColor);
  cardShadowDrawable.setCornerRadius(cornerRadius);
  cardShadowDrawable.setShadowSize(shadowSize);
  cardShadowDrawable.setHideTopShadow(hideTopShadow);
  cardShadowDrawable.setHideBottomShadow(hideBottomShadow);
  cardShadowDrawable.setShadowDx(shadowDx);
  cardShadowDrawable.setShadowDy(shadowDy);
}
 
Example #4
Source File: PreallocatedMountSpecLifecycleTesterSpec.java    From litho with Apache License 2.0 5 votes vote down vote up
@UiThread
@OnMount
static void onMount(
    ComponentContext context, View view, @Prop List<LifecycleStep.StepInfo> steps) {
  // TODO: (T64290961) Remove the StaticContainer hack for tracing OnCreateMountContent callback.
  if (view == StaticContainer.sLastCreatedView) {
    steps.add(new StepInfo(LifecycleStep.ON_CREATE_MOUNT_CONTENT));
    StaticContainer.sLastCreatedView = null;
  }
  steps.add(new StepInfo(LifecycleStep.ON_MOUNT));
}
 
Example #5
Source File: FrescoVitoImage2Spec.java    From fresco with MIT License 5 votes vote down vote up
@OnMount
static void onMount(
    ComponentContext c,
    final FrescoDrawable2 frescoDrawable,
    @Prop(optional = true) final @Nullable Object callerContext,
    @Prop(optional = true) final @Nullable ImageListener imageListener,
    @CachedValue VitoImageRequest imageRequest,
    @FromPrepare DataSource<Void> prefetchDataSource,
    @FromBoundsDefined Rect viewportDimensions) {
  FrescoVitoProvider.getController()
      .fetch(frescoDrawable, imageRequest, callerContext, imageListener, viewportDimensions);
  if (prefetchDataSource != null) {
    prefetchDataSource.close();
  }
}
 
Example #6
Source File: MountSpecGenerator.java    From litho with Apache License 2.0 5 votes vote down vote up
public static TypeSpecDataHolder generateIsMountSizeDependent(MountSpecModel specModel) {
  TypeSpecDataHolder.Builder dataHolder = TypeSpecDataHolder.newBuilder();

  final SpecMethodModel<DelegateMethod, Void> onMount =
      SpecModelUtils.getMethodModelWithAnnotation(specModel, OnMount.class);

  if (onMount == null) {
    return dataHolder.build();
  }

  for (MethodParamModel methodParamModel : onMount.methodParams) {
    if (methodParamModel instanceof InterStageInputParamModel
        && (SpecModelUtils.hasAnnotation(methodParamModel, FromMeasure.class)
            || SpecModelUtils.hasAnnotation(methodParamModel, FromBoundsDefined.class))) {
      return dataHolder
          .addMethod(
              MethodSpec.methodBuilder("isMountSizeDependent")
                  .addAnnotation(Override.class)
                  .addModifiers(Modifier.PROTECTED)
                  .returns(TypeName.BOOLEAN)
                  .addStatement("return true")
                  .build())
          .build();
    }
  }

  return dataHolder.build();
}
 
Example #7
Source File: TestMountSpec.java    From litho with Apache License 2.0 5 votes vote down vote up
@OnMount
static <S extends View> void onMount(
    ComponentContext c,
    Drawable v,
    @Prop(optional = true) boolean prop2,
    @State(canUpdateLazily = true) long state1,
    @State S state2,
    @FromMeasure Long measureOutput,
    @TreeProp TestTreeProp treeProp) {}
 
Example #8
Source File: MountSpecLifecycleTesterSpec.java    From litho with Apache License 2.0 5 votes vote down vote up
@UiThread
@OnMount
static void onMount(
    ComponentContext context, View view, @Prop LifecycleTracker lifecycleTracker) {
  // TODO: (T64290961) Remove the StaticContainer hack for tracing OnCreateMountContent callback.
  if (view == StaticContainer.sLastCreatedView) {
    lifecycleTracker.addStep(LifecycleStep.ON_CREATE_MOUNT_CONTENT);
    StaticContainer.sLastCreatedView = null;
  }
  lifecycleTracker.addStep(LifecycleStep.ON_MOUNT);
}
 
Example #9
Source File: FrescoImageSpec.java    From litho with Apache License 2.0 5 votes vote down vote up
@OnMount
protected static void onMount(
    ComponentContext c,
    DraweeDrawable<GenericDraweeHierarchy> draweeDrawable,
    @Prop(optional = true) ScalingUtils.ScaleType actualImageScaleType,
    @Prop(optional = true) PointF actualImageFocusPoint,
    @Prop(optional = true) int fadeDuration,
    @Prop(optional = true, resType = DRAWABLE) Drawable failureImage,
    @Prop(optional = true) ScalingUtils.ScaleType failureImageScaleType,
    @Prop(optional = true, resType = DRAWABLE) Drawable placeholderImage,
    @Prop(optional = true) PointF placeholderImageFocusPoint,
    @Prop(optional = true) ScalingUtils.ScaleType placeholderImageScaleType,
    @Prop(optional = true, resType = DRAWABLE) Drawable progressBarImage,
    @Prop(optional = true) ScalingUtils.ScaleType progressBarImageScaleType,
    @Prop(optional = true, resType = DRAWABLE) Drawable retryImage,
    @Prop(optional = true) ScalingUtils.ScaleType retryImageScaleType,
    @Prop(optional = true) RoundingParams roundingParams,
    @Prop(optional = true) ColorFilter colorFilter) {

  GenericDraweeHierarchy draweeHierarchy = draweeDrawable.getDraweeHierarchy();

  FrescoImageHierarchyTools.setupHierarchy(
      actualImageScaleType,
      actualImageFocusPoint,
      fadeDuration,
      failureImage,
      failureImageScaleType,
      placeholderImage,
      placeholderImageFocusPoint,
      placeholderImageScaleType,
      progressBarImage,
      progressBarImageScaleType,
      retryImage,
      retryImageScaleType,
      roundingParams,
      colorFilter,
      draweeHierarchy);

  draweeDrawable.mount();
}
 
Example #10
Source File: MountSpecWithShouldUpdateSpec.java    From litho with Apache License 2.0 5 votes vote down vote up
@OnMount
static void onMount(
    ComponentContext c,
    View v,
    @Prop List<LifecycleStep> operationsOutput,
    @Prop Object objectForShouldUpdate) {
  operationsOutput.add(LifecycleStep.ON_MOUNT);
}
 
Example #11
Source File: SizeSpecMountWrapperComponentSpec.java    From litho with Apache License 2.0 5 votes vote down vote up
@UiThread
@OnMount
static void onMount(
    ComponentContext c,
    FrameLayout wrapperView,
    @State AtomicReference<ComponentTree> componentTreeRef) {
  ((LithoView) wrapperView.getChildAt(0)).setComponentTree(componentTreeRef.get());
}
 
Example #12
Source File: ImageSpec.java    From litho with Apache License 2.0 5 votes vote down vote up
@OnMount
static void onMount(
    ComponentContext c,
    MatrixDrawable matrixDrawable,
    @Prop(resType = ResType.DRAWABLE) Drawable drawable,
    @FromBoundsDefined DrawableMatrix drawableMatrix) {
  matrixDrawable.mount(drawable, drawableMatrix);
}
 
Example #13
Source File: TransparencyEnabledCardClipSpec.java    From litho with Apache License 2.0 5 votes vote down vote up
@OnMount
static void onMount(
    ComponentContext c,
    TransparencyEnabledCardClipDrawable cardClipDrawable,
    @Prop(optional = true, resType = ResType.COLOR) int cardBackgroundColor,
    @Prop(optional = true, resType = ResType.DIMEN_OFFSET) float cornerRadius) {
  cardClipDrawable.setBackgroundColor(cardBackgroundColor);
  cardClipDrawable.setCornerRadius(cornerRadius);
}
 
Example #14
Source File: VerticalScrollSpec.java    From litho with Apache License 2.0 5 votes vote down vote up
@OnMount
static void onMount(
    ComponentContext context,
    final LithoScrollView lithoScrollView,
    @Prop(optional = true) boolean scrollbarEnabled,
    @Prop(optional = true) boolean scrollbarFadingEnabled,
    @Prop(optional = true) boolean nestedScrollingEnabled,
    @Prop(optional = true) boolean incrementalMountEnabled,
    @Prop(optional = true) boolean verticalFadingEdgeEnabled,
    @Prop(optional = true, resType = ResType.DIMEN_SIZE) int fadingEdgeLength,
    @Prop(optional = true) @Nullable OnScrollChangeListener onScrollChangeListener,
    // NOT THE SAME AS LITHO'S interceptTouchHandler COMMON PROP, see class javadocs
    @Prop(optional = true) @Nullable OnInterceptTouchListener onInterceptTouchListener,
    @State ComponentTree childComponentTree,
    @State final ScrollPosition scrollPosition) {
  lithoScrollView.mount(childComponentTree, scrollPosition, incrementalMountEnabled);
  lithoScrollView.setScrollbarFadingEnabled(scrollbarFadingEnabled);
  lithoScrollView.setNestedScrollingEnabled(nestedScrollingEnabled);
  lithoScrollView.setVerticalFadingEdgeEnabled(verticalFadingEdgeEnabled);
  lithoScrollView.setFadingEdgeLength(fadingEdgeLength);

  // On older versions we need to disable the vertical scroll bar as otherwise we run into an NPE
  // that was only fixed in Lollipop - see
  // https://github.com/aosp-mirror/platform_frameworks_base/commit/6c8fef7fb866d244486a962dd82f4a6f26505f16#diff-7c8b4c8147fbbbf69293775bca384f31.
  if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
    lithoScrollView.setVerticalScrollBarEnabled(false);
  } else {
    lithoScrollView.setVerticalScrollBarEnabled(scrollbarEnabled);
  }
  lithoScrollView.setOnScrollChangeListener(onScrollChangeListener);
  lithoScrollView.setOnInterceptTouchListener(onInterceptTouchListener);
}
 
Example #15
Source File: DelegateMethodValidationTest.java    From litho with Apache License 2.0 4 votes vote down vote up
@Test
public void testInterStageInputMethodDoesNotExist() {
  final InterStageInputParamModel interStageInputParamModel =
      mock(InterStageInputParamModel.class);
  when(interStageInputParamModel.getAnnotations())
      .thenReturn(ImmutableList.of((Annotation) () -> FromPrepare.class));
  when(interStageInputParamModel.getName()).thenReturn("interStageInput");
  when(interStageInputParamModel.getTypeName()).thenReturn(TypeName.INT);
  when(interStageInputParamModel.getRepresentedObject()).thenReturn(mMethodParamObject3);
  when(mMountSpecModel.getDelegateMethods())
      .thenReturn(
          ImmutableList.of(
              mOnCreateMountContent,
              SpecMethodModel.<DelegateMethod, Void>builder()
                  .annotations(ImmutableList.of((Annotation) () -> OnMount.class))
                  .modifiers(ImmutableList.of(Modifier.STATIC))
                  .name("onMount")
                  .returnTypeSpec(new TypeSpec(TypeName.VOID))
                  .typeVariables(ImmutableList.of())
                  .methodParams(
                      ImmutableList.of(
                          MockMethodParamModel.newBuilder()
                              .type(ClassNames.COMPONENT_CONTEXT)
                              .representedObject(mMethodParamObject1)
                              .build(),
                          MockMethodParamModel.newBuilder()
                              .type(ClassName.bestGuess("java.lang.MadeUpClass"))
                              .representedObject(mMethodParamObject2)
                              .build(),
                          interStageInputParamModel))
                  .representedObject(mDelegateMethodObject1)
                  .typeModel(null)
                  .build()));

  final List<SpecModelValidationError> validationErrors =
      DelegateMethodValidation.validateMountSpecModel(mMountSpecModel);
  for (SpecModelValidationError validationError : validationErrors) {
    System.out.println(validationError.message);
  }
  assertThat(validationErrors).hasSize(1);
  assertThat(validationErrors.get(0).element).isEqualTo(mMethodParamObject3);
  assertThat(validationErrors.get(0).message)
      .isEqualTo(
          "To use interface com.facebook.litho.annotations.FromPrepare on param interStageInput "
              + "you must have a method annotated with interface "
              + "com.facebook.litho.annotations.OnPrepare that has a param Output<java.lang.Integer> "
              + "interStageInput");
}
 
Example #16
Source File: HorizontalScrollSpec.java    From litho with Apache License 2.0 4 votes vote down vote up
@OnMount
static void onMount(
    final ComponentContext context,
    final HorizontalScrollLithoView horizontalScrollLithoView,
    @Prop(optional = true, resType = ResType.BOOL) boolean scrollbarEnabled,
    @Prop(optional = true) @Nullable HorizontalScrollEventsController eventsController,
    @Prop(optional = true) @Nullable OnScrollChangeListener onScrollChangeListener,
    @State final ScrollPosition lastScrollPosition,
    @State ComponentTree childComponentTree,
    @FromBoundsDefined int componentWidth,
    @FromBoundsDefined int componentHeight,
    @FromBoundsDefined final YogaDirection layoutDirection) {

  horizontalScrollLithoView.setHorizontalScrollBarEnabled(scrollbarEnabled);
  horizontalScrollLithoView.mount(
      childComponentTree,
      lastScrollPosition,
      onScrollChangeListener,
      componentWidth,
      componentHeight);
  final ViewTreeObserver viewTreeObserver = horizontalScrollLithoView.getViewTreeObserver();
  viewTreeObserver.addOnPreDrawListener(
      new ViewTreeObserver.OnPreDrawListener() {
        @Override
        public boolean onPreDraw() {
          horizontalScrollLithoView.getViewTreeObserver().removeOnPreDrawListener(this);

          if (lastScrollPosition.x == LAST_SCROLL_POSITION_UNSET) {
            if (layoutDirection == YogaDirection.RTL) {
              horizontalScrollLithoView.fullScroll(HorizontalScrollView.FOCUS_RIGHT);
            }
            lastScrollPosition.x = horizontalScrollLithoView.getScrollX();
          } else {
            horizontalScrollLithoView.setScrollX(lastScrollPosition.x);
          }

          return true;
        }
      });

  if (eventsController != null) {
    eventsController.setScrollableView(horizontalScrollLithoView);
  }
}
 
Example #17
Source File: GlideImageSpec.java    From litho-glide with MIT License 4 votes vote down vote up
@OnMount
static void onMount(ComponentContext c, ImageView imageView,
    @Prop(optional = true) String imageUrl, @Prop(optional = true) File file,
    @Prop(optional = true) Uri uri, @Prop(optional = true) Integer resourceId,
    @Prop(optional = true) RequestManager glideRequestManager,
    @Prop(optional = true, resType = DRAWABLE) Drawable failureImage,
    @Prop(optional = true, resType = DRAWABLE) Drawable fallbackImage,
    @Prop(optional = true, resType = DRAWABLE) Drawable placeholderImage,
    @Prop(optional = true) DiskCacheStrategy diskCacheStrategy,
    @Prop(optional = true) RequestListener requestListener,
    @Prop(optional = true) boolean asBitmap, @Prop(optional = true) boolean asGif,
    @Prop(optional = true) boolean crossFade, @Prop(optional = true) int crossFadeDuration,
    @Prop(optional = true) boolean centerCrop, @Prop(optional = true) boolean fitCenter,
    @Prop(optional = true) boolean skipMemoryCache, @Prop(optional = true) Target target) {

  if (imageUrl == null && file == null && uri == null && resourceId == null) {
    throw new IllegalArgumentException(
        "You must provide at least one of String, File, Uri or ResourceId");
  }

  if (glideRequestManager == null) {
    glideRequestManager = Glide.with(c.getAndroidContext());
  }

  DrawableTypeRequest request;

  if (imageUrl != null) {
    request = glideRequestManager.load(imageUrl);
  } else if (file != null) {
    request = glideRequestManager.load(file);
  } else if (uri != null) {
    request = glideRequestManager.load(uri);
  } else {
    request = glideRequestManager.load(resourceId);
  }

  if (request == null) {
    throw new IllegalStateException("Could not instantiate DrawableTypeRequest");
  }

  if (diskCacheStrategy != null) {
    request.diskCacheStrategy(diskCacheStrategy);
  }

  if (asBitmap) {
    request.asBitmap();
  }

  if (asGif) {
    request.asGif();
  }

  if (crossFade) {
    request.crossFade();
  }

  if (crossFadeDuration != DEFAULT_INT_VALUE) {
    request.crossFade(crossFadeDuration);
  }

  if (centerCrop) {
    request.centerCrop();
  }

  if (failureImage != null) {
    request.error(failureImage);
  }

  if (fallbackImage != null) {
    request.fallback(fallbackImage);
  }

  if (fitCenter) {
    request.fitCenter();
  }

  if (requestListener != null) {
    request.listener(requestListener);
  }

  if (placeholderImage != null) {
    request.placeholder(placeholderImage);
  }

  request.skipMemoryCache(skipMemoryCache);

  if (target != null) {
    request.into(target);
  } else {
    request.into(imageView);
  }
}
 
Example #18
Source File: DelegateMethodValidation.java    From litho with Apache License 2.0 4 votes vote down vote up
static List<SpecModelValidationError> validateMountSpecModel(MountSpecModel specModel) {
  List<SpecModelValidationError> validationErrors = new ArrayList<>();
  validationErrors.addAll(
      validateMethods(
          specModel,
          DelegateMethodDescriptions.MOUNT_SPEC_DELEGATE_METHODS_MAP,
          DelegateMethodDescriptions.INTER_STAGE_INPUTS_MAP));

  final SpecMethodModel<DelegateMethod, Void> onCreateMountContentModel =
      SpecModelUtils.getMethodModelWithAnnotation(specModel, OnCreateMountContent.class);
  if (onCreateMountContentModel == null) {
    validationErrors.add(
        new SpecModelValidationError(
            specModel.getRepresentedObject(),
            "All MountSpecs need to have a method annotated with @OnCreateMountContent."));
  } else {
    final TypeName mountType = onCreateMountContentModel.returnType;
    ImmutableList<Class<? extends Annotation>> methodsAcceptingMountTypeAsSecondParam =
        ImmutableList.of(OnMount.class, OnBind.class, OnUnbind.class, OnUnmount.class);
    for (Class<? extends Annotation> annotation : methodsAcceptingMountTypeAsSecondParam) {
      final SpecMethodModel<DelegateMethod, Void> method =
          SpecModelUtils.getMethodModelWithAnnotation(specModel, annotation);
      if (method != null
          && (method.methodParams.size() < 2
              || !method.methodParams.get(1).getTypeName().equals(mountType))) {
        validationErrors.add(
            new SpecModelValidationError(
                method.representedObject,
                "The second parameter of a method annotated with "
                    + annotation
                    + " must "
                    + "have the same type as the return type of the method annotated with "
                    + "@OnCreateMountContent (i.e. "
                    + mountType
                    + ")."));
      }
    }
  }

  return validationErrors;
}
 
Example #19
Source File: RecyclerSpec.java    From litho with Apache License 2.0 4 votes vote down vote up
@OnMount
static void onMount(
    ComponentContext c,
    SectionsRecyclerView sectionsRecycler,
    @Prop Binder<RecyclerView> binder,
    @Prop(optional = true) boolean hasFixedSize,
    @Prop(optional = true) boolean clipToPadding,
    @Prop(optional = true) int leftPadding,
    @Prop(optional = true) int rightPadding,
    @Prop(optional = true) int topPadding,
    @Prop(optional = true) int bottomPadding,
    @Prop(optional = true, resType = ResType.COLOR) @Nullable
        Integer refreshProgressBarBackgroundColor,
    @Prop(optional = true, resType = ResType.COLOR) int refreshProgressBarColor,
    @Prop(optional = true) boolean clipChildren,
    @Prop(optional = true) boolean nestedScrollingEnabled,
    @Prop(optional = true) int scrollBarStyle,
    @Prop(optional = true) RecyclerView.ItemDecoration itemDecoration,
    @Prop(optional = true) boolean horizontalFadingEdgeEnabled,
    @Prop(optional = true) boolean verticalFadingEdgeEnabled,
    @Prop(optional = true, resType = ResType.DIMEN_SIZE) int fadingEdgeLength,
    @Prop(optional = true) @IdRes int recyclerViewId,
    @Prop(optional = true) int overScrollMode,
    @Prop(optional = true, isCommonProp = true) CharSequence contentDescription,
    @Prop(optional = true) ItemAnimator itemAnimator) {
  final RecyclerView recyclerView = sectionsRecycler.getRecyclerView();

  if (recyclerView == null) {
    throw new IllegalStateException(
        "RecyclerView not found, it should not be removed from SwipeRefreshLayout");
  }
  recyclerView.setContentDescription(contentDescription);
  recyclerView.setHasFixedSize(hasFixedSize);
  recyclerView.setClipToPadding(clipToPadding);
  sectionsRecycler.setClipToPadding(clipToPadding);
  ViewCompat.setPaddingRelative(
      recyclerView, leftPadding, topPadding, rightPadding, bottomPadding);
  recyclerView.setClipChildren(clipChildren);
  sectionsRecycler.setClipChildren(clipChildren);
  recyclerView.setNestedScrollingEnabled(nestedScrollingEnabled);
  sectionsRecycler.setNestedScrollingEnabled(nestedScrollingEnabled);
  recyclerView.setScrollBarStyle(scrollBarStyle);
  recyclerView.setHorizontalFadingEdgeEnabled(horizontalFadingEdgeEnabled);
  recyclerView.setVerticalFadingEdgeEnabled(verticalFadingEdgeEnabled);
  recyclerView.setFadingEdgeLength(fadingEdgeLength);
  // TODO (t14949498) determine if this is necessary
  recyclerView.setId(recyclerViewId);
  recyclerView.setOverScrollMode(overScrollMode);
  if (refreshProgressBarBackgroundColor != null) {
    sectionsRecycler.setProgressBackgroundColorSchemeColor(refreshProgressBarBackgroundColor);
  }
  sectionsRecycler.setColorSchemeColors(refreshProgressBarColor);

  if (itemDecoration != null) {
    recyclerView.addItemDecoration(itemDecoration);
  }

  sectionsRecycler.setItemAnimator(
      itemAnimator != RecyclerSpec.itemAnimator ? itemAnimator : new NoUpdateItemAnimator());

  binder.mount(recyclerView);
}
 
Example #20
Source File: MountSpecModelFactoryTest.java    From litho with Apache License 2.0 4 votes vote down vote up
@OnMount
static <S extends Object> void onMount(
    @Prop(optional = true) boolean prop5,
    @State(canUpdateLazily = true) long state1,
    @State S state2,
    @TreeProp TestTreeProp treeProp) {}
 
Example #21
Source File: DuplicatePropValidationTest.java    From litho with Apache License 2.0 4 votes vote down vote up
@OnMount
static void onMount(
    ComponentContext c, Drawable drawable, @Prop String prop1, @Prop int prop2) {}
 
Example #22
Source File: DelegateMethodValidationTest.java    From litho with Apache License 2.0 4 votes vote down vote up
@Test
public void testInterStageInputOutputDoesNotExist() {
  final InterStageInputParamModel interStageInputParamModel =
      mock(InterStageInputParamModel.class);
  when(interStageInputParamModel.getAnnotations())
      .thenReturn(ImmutableList.of((Annotation) () -> FromPrepare.class));
  when(interStageInputParamModel.getName()).thenReturn("interStageInput");
  when(interStageInputParamModel.getTypeName()).thenReturn(TypeName.INT);
  when(interStageInputParamModel.getRepresentedObject()).thenReturn(mMethodParamObject3);
  when(mMountSpecModel.getDelegateMethods())
      .thenReturn(
          ImmutableList.of(
              mOnCreateMountContent,
              SpecMethodModel.<DelegateMethod, Void>builder()
                  .annotations(ImmutableList.of((Annotation) () -> OnMount.class))
                  .modifiers(ImmutableList.of(Modifier.STATIC))
                  .name("onMount")
                  .returnTypeSpec(new TypeSpec(TypeName.VOID))
                  .typeVariables(ImmutableList.of())
                  .methodParams(
                      ImmutableList.of(
                          MockMethodParamModel.newBuilder()
                              .name("c")
                              .type(ClassNames.COMPONENT_CONTEXT)
                              .representedObject(mMethodParamObject1)
                              .build(),
                          MockMethodParamModel.newBuilder()
                              .name("param")
                              .type(ClassName.bestGuess("java.lang.MadeUpClass"))
                              .representedObject(mMethodParamObject2)
                              .build(),
                          interStageInputParamModel))
                  .representedObject(mDelegateMethodObject1)
                  .typeModel(null)
                  .build(),
              SpecMethodModel.<DelegateMethod, Void>builder()
                  .annotations(ImmutableList.of((Annotation) () -> OnPrepare.class))
                  .modifiers(ImmutableList.of(Modifier.STATIC))
                  .name("onPrepare")
                  .returnTypeSpec(new TypeSpec(TypeName.VOID))
                  .typeVariables(ImmutableList.of())
                  .methodParams(
                      ImmutableList.of(
                          MockMethodParamModel.newBuilder()
                              .name("c")
                              .type(ClassNames.COMPONENT_CONTEXT)
                              .representedObject(mMethodParamObject1)
                              .build()))
                  .representedObject(mDelegateMethodObject2)
                  .typeModel(null)
                  .build()));

  final List<SpecModelValidationError> validationErrors =
      DelegateMethodValidation.validateMountSpecModel(mMountSpecModel);
  for (final SpecModelValidationError validationError : validationErrors) {
    System.out.println(validationError.message);
  }
  assertThat(validationErrors).hasSize(1);
  assertThat(validationErrors.get(0).element).isEqualTo(mMethodParamObject3);
  assertThat(validationErrors.get(0).message)
      .isEqualTo(
          "To use interface com.facebook.litho.annotations.FromPrepare on param interStageInput "
              + "your method annotated with interface com.facebook.litho.annotations.OnPrepare must "
              + "have a param Output<java.lang.Integer> interStageInput");
}
 
Example #23
Source File: DelegateMethodValidationTest.java    From litho with Apache License 2.0 4 votes vote down vote up
@Test
public void testSecondParameter() {
  when(mMountSpecModel.getDelegateMethods())
      .thenReturn(
          ImmutableList.of(
              mOnCreateMountContent,
              SpecMethodModel.<DelegateMethod, Void>builder()
                  .annotations(ImmutableList.of((Annotation) () -> OnMount.class))
                  .modifiers(ImmutableList.of(Modifier.STATIC))
                  .name("onMount")
                  .returnTypeSpec(new TypeSpec(TypeName.VOID))
                  .typeVariables(ImmutableList.of())
                  .methodParams(
                      ImmutableList.of(
                          MockMethodParamModel.newBuilder()
                              .type(ClassNames.COMPONENT_CONTEXT)
                              .representedObject(mMethodParamObject1)
                              .build(),
                          MockMethodParamModel.newBuilder()
                              .type(ClassNames.OBJECT)
                              .representedObject(mMethodParamObject2)
                              .build()))
                  .representedObject(mDelegateMethodObject1)
                  .typeModel(null)
                  .build(),
              SpecMethodModel.<DelegateMethod, Void>builder()
                  .annotations(ImmutableList.of((Annotation) () -> OnBind.class))
                  .modifiers(ImmutableList.of(Modifier.STATIC))
                  .name("onBind")
                  .returnTypeSpec(new TypeSpec(TypeName.VOID))
                  .typeVariables(ImmutableList.of())
                  .methodParams(
                      ImmutableList.of(
                          MockMethodParamModel.newBuilder()
                              .type(ClassNames.COMPONENT_CONTEXT)
                              .representedObject(mMethodParamObject1)
                              .build(),
                          MockMethodParamModel.newBuilder()
                              .type(ClassNames.OBJECT)
                              .representedObject(mMethodParamObject2)
                              .build()))
                  .representedObject(mDelegateMethodObject2)
                  .typeModel(null)
                  .build()));

  final List<SpecModelValidationError> validationErrors =
      DelegateMethodValidation.validateMountSpecModel(mMountSpecModel);
  assertThat(validationErrors).hasSize(2);
  assertThat(validationErrors.get(0).element).isEqualTo(mDelegateMethodObject1);
  assertThat(validationErrors.get(0).message)
      .isEqualTo(
          "The second parameter of a method annotated with interface "
              + "com.facebook.litho.annotations.OnMount must have the same type as the "
              + "return type of the method annotated with @OnCreateMountContent (i.e. "
              + "java.lang.MadeUpClass).");
  assertThat(validationErrors.get(1).element).isEqualTo(mDelegateMethodObject2);
  assertThat(validationErrors.get(1).message)
      .isEqualTo(
          "The second parameter of a method annotated with interface "
              + "com.facebook.litho.annotations.OnBind must have the same type as the "
              + "return type of the method annotated with @OnCreateMountContent (i.e. "
              + "java.lang.MadeUpClass).");
}
 
Example #24
Source File: TestCrasherOnMountSpec.java    From litho with Apache License 2.0 4 votes vote down vote up
@OnMount
static void onMount(ComponentContext c, LithoView lithoView) {
  throw new RuntimeException("onMount crash");
}
 
Example #25
Source File: SimpleMountSpecTesterSpec.java    From litho with Apache License 2.0 4 votes vote down vote up
@OnMount
static void onMount(
    ComponentContext c, ColorDrawable drawable, @Prop(optional = true) int color) {
  drawable.setColor(color);
}
 
Example #26
Source File: RecordsShouldUpdateSpec.java    From litho with Apache License 2.0 4 votes vote down vote up
@OnMount
static void onMount(
    ComponentContext c,
    View v,
    @Prop Object testProp,
    @Prop List<Diff<Object>> shouldUpdateCalls) {}
 
Example #27
Source File: TextSpec.java    From litho with Apache License 2.0 4 votes vote down vote up
@OnMount
static void onMount(
    ComponentContext c,
    TextDrawable textDrawable,
    @Prop(optional = true, resType = ResType.COLOR) int textColor,
    @Prop(optional = true, resType = ResType.COLOR) int highlightColor,
    @Prop(optional = true) ColorStateList textColorStateList,
    @Prop(optional = true) final EventHandler textOffsetOnTouchHandler,
    @Prop(optional = true) int highlightStartOffset,
    @Prop(optional = true) int highlightEndOffset,
    @Prop(optional = true, resType = ResType.DIMEN_TEXT) float clickableSpanExpandedOffset,
    @Prop(optional = true) boolean clipToBounds,
    @Prop(optional = true) ClickableSpanListener spanListener,
    final @FromBoundsDefined CharSequence processedText,
    @FromBoundsDefined Layout textLayout,
    @FromBoundsDefined Float textLayoutTranslationY,
    @FromBoundsDefined ClickableSpan[] clickableSpans,
    @FromBoundsDefined ImageSpan[] imageSpans) {

  TextDrawable.TextOffsetOnTouchListener textOffsetOnTouchListener = null;

  if (textOffsetOnTouchHandler != null) {
    textOffsetOnTouchListener =
        new TextDrawable.TextOffsetOnTouchListener() {
          @Override
          public void textOffsetOnTouch(int textOffset) {
            Text.dispatchTextOffsetOnTouchEvent(
                textOffsetOnTouchHandler, processedText, textOffset);
          }
        };
  }
  textDrawable.mount(
      processedText,
      textLayout,
      textLayoutTranslationY == null ? 0 : textLayoutTranslationY,
      clipToBounds,
      textColorStateList,
      textColor,
      highlightColor,
      clickableSpans,
      imageSpans,
      spanListener,
      textOffsetOnTouchListener,
      highlightStartOffset,
      highlightEndOffset,
      clickableSpanExpandedOffset,
      c.getLogTag());

  if (processedText instanceof MountableCharSequence) {
    ((MountableCharSequence) processedText).onMount(textDrawable);
  }
}
 
Example #28
Source File: TextInputSpec.java    From litho with Apache License 2.0 4 votes vote down vote up
@OnMount
static void onMount(
    final ComponentContext c,
    EditTextWithEventHandlers editText,
    @Prop(optional = true, resType = ResType.STRING) CharSequence hint,
    @Prop(optional = true, resType = ResType.DRAWABLE) Drawable inputBackground,
    @Prop(optional = true, resType = ResType.DIMEN_OFFSET) float shadowRadius,
    @Prop(optional = true, resType = ResType.DIMEN_OFFSET) float shadowDx,
    @Prop(optional = true, resType = ResType.DIMEN_OFFSET) float shadowDy,
    @Prop(optional = true, resType = ResType.COLOR) int shadowColor,
    @Prop(optional = true) ColorStateList textColorStateList,
    @Prop(optional = true) ColorStateList hintColorStateList,
    @Prop(optional = true, resType = ResType.COLOR) Integer highlightColor,
    @Prop(optional = true, resType = ResType.DIMEN_TEXT) int textSize,
    @Prop(optional = true) Typeface typeface,
    @Prop(optional = true) int textAlignment,
    @Prop(optional = true) int gravity,
    @Prop(optional = true) boolean editable,
    @Prop(optional = true) int inputType,
    @Prop(optional = true) int imeOptions,
    @Prop(optional = true, varArg = "inputFilter") List<InputFilter> inputFilters,
    @Prop(optional = true) boolean multiline,
    @Prop(optional = true) int minLines,
    @Prop(optional = true) int maxLines,
    @Prop(optional = true) TextUtils.TruncateAt ellipsize,
    @Prop(optional = true) int cursorDrawableRes,
    @Prop(optional = true) MovementMethod movementMethod,
    @Prop(optional = true, resType = ResType.STRING) CharSequence error,
    @Prop(optional = true, resType = ResType.DRAWABLE) Drawable errorDrawable,
    @State AtomicReference<CharSequence> savedText,
    @State AtomicReference<EditTextWithEventHandlers> mountedView) {
  mountedView.set(editText);

  setParams(
      editText,
      hint,
      getBackgroundOrDefault(c, inputBackground),
      shadowRadius,
      shadowDx,
      shadowDy,
      shadowColor,
      textColorStateList,
      hintColorStateList,
      highlightColor,
      textSize,
      typeface,
      textAlignment,
      gravity,
      editable,
      inputType,
      imeOptions,
      inputFilters,
      multiline,
      ellipsize,
      minLines,
      maxLines,
      cursorDrawableRes,
      movementMethod,
      // onMount happens:
      // 1. After initState: savedText = initText.
      // 2. After onUnmount: savedText preserved from underlying editText.
      savedText.get(),
      error,
      errorDrawable);
  editText.setTextState(savedText);
}
 
Example #29
Source File: EditTextSpec.java    From litho with Apache License 2.0 4 votes vote down vote up
@OnMount
static void onMount(
    final ComponentContext c,
    EditTextWithEventHandlers editText,
    @Prop(optional = true, resType = ResType.STRING) CharSequence text,
    @Prop(optional = true, resType = ResType.STRING) CharSequence initialText,
    @Prop(optional = true, resType = ResType.STRING) CharSequence hint,
    @Prop(optional = true) TextUtils.TruncateAt ellipsize,
    @Prop(optional = true, resType = ResType.INT) int minLines,
    @Prop(optional = true, resType = ResType.INT) int maxLines,
    @Prop(optional = true, resType = ResType.INT) int maxLength,
    @Prop(optional = true, resType = ResType.DIMEN_OFFSET) float shadowRadius,
    @Prop(optional = true, resType = ResType.DIMEN_OFFSET) float shadowDx,
    @Prop(optional = true, resType = ResType.DIMEN_OFFSET) float shadowDy,
    @Prop(optional = true, resType = ResType.COLOR) int shadowColor,
    @Prop(optional = true, resType = ResType.BOOL) boolean isSingleLine,
    @Prop(optional = true, resType = ResType.COLOR) int textColor,
    @Prop(optional = true) ColorStateList textColorStateList,
    @Prop(optional = true, resType = ResType.COLOR) int hintColor,
    @Prop(optional = true) ColorStateList hintColorStateList,
    @Prop(optional = true, resType = ResType.COLOR) int linkColor,
    @Prop(optional = true, resType = ResType.COLOR) int highlightColor,
    @Prop(optional = true) ColorStateList tintColorStateList,
    @Prop(optional = true, resType = ResType.DIMEN_TEXT) int textSize,
    @Prop(optional = true, resType = ResType.DIMEN_OFFSET) float extraSpacing,
    @Prop(optional = true, resType = ResType.FLOAT) float spacingMultiplier,
    @Prop(optional = true) int textStyle,
    @Prop(optional = true) Typeface typeface,
    @Prop(optional = true) Layout.Alignment textAlignment,
    @Prop(optional = true) int gravity,
    @Prop(optional = true) boolean editable,
    @Prop(optional = true) int selection,
    @Prop(optional = true) int inputType,
    @Prop(optional = true) int rawInputType,
    @Prop(optional = true) int imeOptions,
    @Prop(optional = true) TextView.OnEditorActionListener editorActionListener,
    @Prop(optional = true) boolean isSingleLineWrap,
    @Prop(optional = true) boolean requestFocus,
    @Prop(optional = true) int cursorDrawableRes,
    @Prop(optional = true, varArg = "inputFilter") List<InputFilter> inputFilters,
    @State AtomicReference<EditTextWithEventHandlers> mountedView,
    @State AtomicBoolean configuredInitialText,
    @State(canUpdateLazily = true) CharSequence input) {

  mountedView.set(editText);

  initEditText(
      editText,
      input == null ? text : input,
      // Only set initialText on the EditText during the very first mount.
      configuredInitialText.getAndSet(true) ? null : initialText,
      hint,
      ellipsize,
      inputFilters,
      minLines,
      maxLines,
      maxLength,
      shadowRadius,
      shadowDx,
      shadowDy,
      shadowColor,
      isSingleLine,
      textColor,
      textColorStateList,
      hintColor,
      hintColorStateList,
      linkColor,
      highlightColor,
      tintColorStateList,
      textSize,
      extraSpacing,
      spacingMultiplier,
      textStyle,
      typeface,
      textAlignment,
      gravity,
      editable,
      selection,
      inputType,
      rawInputType,
      imeOptions,
      editorActionListener,
      isSingleLineWrap,
      requestFocus,
      cursorDrawableRes);
}