Java Code Examples for com.facebook.litho.annotations.ResType#DIMEN_SIZE

The following examples show how to use com.facebook.litho.annotations.ResType#DIMEN_SIZE . 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: 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 2
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 3
Source File: CircleSpec.java    From litho with Apache License 2.0 5 votes vote down vote up
@OnCreateLayout
static Component onCreateLayout(
    ComponentContext c,
    @Prop(resType = ResType.DIMEN_SIZE) int radius,
    @Prop(resType = ResType.COLOR) int color) {
  final int dim = 2 * radius;
  return Row.create(c)
      .heightPx(dim)
      .widthPx(dim)
      .background(buildRoundedRect(radius, color))
      .build();
}
 
Example 4
Source File: TestLayoutSpecModelFactoryTest.java    From litho with Apache License 2.0 5 votes vote down vote up
@OnCreateLayout
public static Component onCreateLayout(
    ComponentContext c,
    @Prop String s,
    @Prop Component child,
    @Prop(resType = ResType.DIMEN_SIZE) float size,
    @Prop(optional = true) int i) {
  return Row.create(c).build();
}
 
Example 5
Source File: BasicLayoutSpec.java    From litho with Apache License 2.0 5 votes vote down vote up
@OnCreateLayout
static Component onCreateLayout(
    ComponentContext context,
    @Prop String myStringProp,
    @Prop(resType = ResType.COLOR) int myRequiredColorProp,
    @Prop(resType = ResType.DIMEN_SIZE) float myDimenSizeProp,
    @Prop Component child) {
  return null;
}
 
Example 6
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 7
Source File: RecyclerSpec.java    From litho with Apache License 2.0 4 votes vote down vote up
@ShouldUpdate(onMount = true)
protected static boolean shouldUpdate(
    @Prop Diff<Binder<RecyclerView>> binder,
    @Prop(optional = true) Diff<Boolean> hasFixedSize,
    @Prop(optional = true) Diff<Boolean> clipToPadding,
    @Prop(optional = true) Diff<Integer> leftPadding,
    @Prop(optional = true) Diff<Integer> rightPadding,
    @Prop(optional = true) Diff<Integer> topPadding,
    @Prop(optional = true) Diff<Integer> bottomPadding,
    @Prop(optional = true, resType = ResType.COLOR)
        Diff<Integer> refreshProgressBarBackgroundColor,
    @Prop(optional = true, resType = ResType.COLOR) Diff<Integer> refreshProgressBarColor,
    @Prop(optional = true) Diff<Boolean> clipChildren,
    @Prop(optional = true) Diff<Integer> scrollBarStyle,
    @Prop(optional = true) Diff<RecyclerView.ItemDecoration> itemDecoration,
    @Prop(optional = true) Diff<Boolean> horizontalFadingEdgeEnabled,
    @Prop(optional = true) Diff<Boolean> verticalFadingEdgeEnabled,
    @Prop(optional = true, resType = ResType.DIMEN_SIZE) Diff<Integer> fadingEdgeLength,
    @Prop(optional = true) Diff<ItemAnimator> itemAnimator,
    @State Diff<Integer> measureVersion) {

  if (measureVersion.getPrevious().intValue() != measureVersion.getNext().intValue()) {
    return true;
  }

  if (binder.getPrevious() != binder.getNext()) {
    return true;
  }

  if (!hasFixedSize.getPrevious().equals(hasFixedSize.getNext())) {
    return true;
  }

  if (!clipToPadding.getPrevious().equals(clipToPadding.getNext())) {
    return true;
  }

  if (!leftPadding.getPrevious().equals(leftPadding.getNext())) {
    return true;
  }

  if (!rightPadding.getPrevious().equals(rightPadding.getNext())) {
    return true;
  }

  if (!topPadding.getPrevious().equals(topPadding.getNext())) {
    return true;
  }

  if (!bottomPadding.getPrevious().equals(bottomPadding.getNext())) {
    return true;
  }

  if (!clipChildren.getPrevious().equals(clipChildren.getNext())) {
    return true;
  }

  if (!scrollBarStyle.getPrevious().equals(scrollBarStyle.getNext())) {
    return true;
  }

  if (!horizontalFadingEdgeEnabled.getPrevious().equals(horizontalFadingEdgeEnabled.getNext())) {
    return true;
  }

  if (!verticalFadingEdgeEnabled.getPrevious().equals(verticalFadingEdgeEnabled.getNext())) {
    return true;
  }

  if (!fadingEdgeLength.getPrevious().equals(fadingEdgeLength.getNext())) {
    return true;
  }

  Integer previousRefreshBgColor = refreshProgressBarBackgroundColor.getPrevious();
  Integer nextRefreshBgColor = refreshProgressBarBackgroundColor.getNext();
  if (previousRefreshBgColor == null
      ? nextRefreshBgColor != null
      : !previousRefreshBgColor.equals(nextRefreshBgColor)) {
    return true;
  }

  if (!refreshProgressBarColor.getPrevious().equals(refreshProgressBarColor.getNext())) {
    return true;
  }

  final ItemAnimator previousItemAnimator = itemAnimator.getPrevious();
  final ItemAnimator nextItemAnimator = itemAnimator.getNext();

  if (previousItemAnimator == null
      ? nextItemAnimator != null
      : !previousItemAnimator.getClass().equals(nextItemAnimator.getClass())) {
    return true;
  }

  final RecyclerView.ItemDecoration previous = itemDecoration.getPrevious();
  final RecyclerView.ItemDecoration next = itemDecoration.getNext();
  final boolean itemDecorationIsEqual =
      (previous == null) ? (next == null) : previous.equals(next);

  return !itemDecorationIsEqual;
}