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

The following examples show how to use com.facebook.litho.annotations.ResType#COLOR . 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: 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 3
Source File: SpinnerSpec.java    From litho with Apache License 2.0 6 votes vote down vote up
@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 4
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 5
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 6
Source File: RecyclerSpec.java    From litho with Apache License 2.0 5 votes vote down vote up
@OnUnmount
static void onUnmount(
    ComponentContext context,
    SectionsRecyclerView sectionsRecycler,
    @Prop Binder<RecyclerView> binder,
    @Prop(optional = true) RecyclerView.ItemDecoration itemDecoration,
    @Prop(optional = true, resType = ResType.COLOR) @Nullable
        Integer refreshProgressBarBackgroundColor,
    @Prop(optional = true) SnapHelper snapHelper) {
  final RecyclerView recyclerView = sectionsRecycler.getRecyclerView();

  if (recyclerView == null) {
    throw new IllegalStateException(
        "RecyclerView not found, it should not be removed from SwipeRefreshLayout "
            + "before unmounting");
  }

  recyclerView.setId(RecyclerSpec.recyclerViewId);

  if (refreshProgressBarBackgroundColor != null) {
    sectionsRecycler.setProgressBackgroundColorSchemeColor(
        DEFAULT_REFRESH_SPINNER_BACKGROUND_COLOR);
  }

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

  binder.unmount(recyclerView);

  if (snapHelper != null) {
    snapHelper.attachToRecyclerView(null);
  }

  sectionsRecycler.resetItemAnimator();
}
 
Example 7
Source File: ProgressSpec.java    From litho with Apache License 2.0 5 votes vote down vote up
@OnUnmount
static void onUnmount(
    ComponentContext c,
    ProgressBar progressBar,
    @Prop(optional = true, resType = ResType.COLOR) int color,
    @FromPrepare Drawable resolvedIndeterminateDrawable) {

  // restore the color first, since it acts on the indeterminateDrawable
  if (color != Color.TRANSPARENT && progressBar.getIndeterminateDrawable() != null) {
    progressBar.getIndeterminateDrawable().mutate().clearColorFilter();
  }

  progressBar.setIndeterminateDrawable(null);
}
 
Example 8
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 9
Source File: TileComponentSpec.java    From litho with Apache License 2.0 5 votes vote down vote up
@OnCreateLayout
static Component onCreateLayout(
    ComponentContext c, @Prop String text, @Prop(resType = ResType.COLOR) int bgColor) {
  return Column.create(c)
      .alignContent(YogaAlign.CENTER)
      .alignItems(YogaAlign.CENTER)
      .justifyContent(YogaJustify.CENTER)
      .widthDip(50)
      .heightDip(50)
      .backgroundColor(bgColor)
      .child(Text.create(c).textSizeSp(30).text(text))
      .build();
}
 
Example 10
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 11
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;
}
 
Example 12
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 13
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 14
Source File: TextInputSpec.java    From litho with Apache License 2.0 4 votes vote down vote up
@OnMeasure
static void onMeasure(
    ComponentContext c,
    ComponentLayout layout,
    int widthSpec,
    int heightSpec,
    Size size,
    @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) TextUtils.TruncateAt ellipsize,
    @Prop(optional = true) int minLines,
    @Prop(optional = true) int maxLines,
    @Prop(optional = true) int cursorDrawableRes,
    @Prop(optional = true, resType = ResType.STRING) CharSequence error,
    @Prop(optional = true, resType = ResType.DRAWABLE) Drawable errorDrawable,
    @State AtomicReference<CharSequence> savedText,
    @State int measureSeqNumber) {

  // The height should be the measured height of EditText with relevant params
  final EditText forMeasure = new ForMeasureEditText(c.getAndroidContext());
  // If text contains Spans, we don't want it to be mutable for the measurement case
  CharSequence text = savedText.get();
  if (text instanceof Spannable) {
    text = text.toString();
  }
  setParams(
      forMeasure,
      hint,
      getBackgroundOrDefault(
          c, inputBackground == UNSET_DRAWABLE ? forMeasure.getBackground() : inputBackground),
      shadowRadius,
      shadowDx,
      shadowDy,
      shadowColor,
      textColorStateList,
      hintColorStateList,
      highlightColor,
      textSize,
      typeface,
      textAlignment,
      gravity,
      editable,
      inputType,
      imeOptions,
      inputFilters,
      multiline,
      ellipsize,
      minLines,
      maxLines,
      cursorDrawableRes,
      forMeasure.getMovementMethod(),
      // onMeasure happens:
      // 1. After initState before onMount: savedText = initText.
      // 2. After onMount before onUnmount: savedText preserved from underlying editText.
      text,
      error,
      errorDrawable);
  forMeasure.measure(
      MeasureUtils.getViewMeasureSpec(widthSpec), MeasureUtils.getViewMeasureSpec(heightSpec));

  size.height = forMeasure.getMeasuredHeight();

  // For width we always take all available space, or collapse to 0 if unspecified.
  if (SizeSpec.getMode(widthSpec) == SizeSpec.UNSPECIFIED) {
    size.width = 0;
  } else {
    size.width = Math.min(SizeSpec.getSize(widthSpec), forMeasure.getMeasuredWidth());
  }
}
 
Example 15
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 16
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);
}
 
Example 17
Source File: TransparencyEnabledCardSpec.java    From litho with Apache License 2.0 4 votes vote down vote up
@OnCreateLayout
static Component onCreateLayout(
    ComponentContext c,
    @Prop Component content,
    @Prop(optional = true, resType = ResType.COLOR) int cardBackgroundColor,
    @Prop(optional = true, resType = ResType.COLOR) int clippingColor,
    @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_OFFSET) float elevation,
    @Prop(optional = true, resType = ResType.DIMEN_OFFSET) int shadowBottomOverride,
    @Prop(optional = true) boolean disableClipTopLeft,
    @Prop(optional = true) boolean disableClipTopRight,
    @Prop(optional = true) boolean disableClipBottomLeft,
    @Prop(optional = true) boolean disableClipBottomRight) {

  final Resources resources = c.getResources();

  if (cornerRadius == -1) {
    cornerRadius = pixels(resources, DEFAULT_CORNER_RADIUS_DP);
  }

  if (elevation == -1) {
    elevation = pixels(resources, DEFAULT_SHADOW_SIZE_DP);
  }

  final int shadowTop = getShadowTop(elevation);
  final int shadowBottom =
      shadowBottomOverride == -1 ? getShadowBottom(elevation) : shadowBottomOverride;
  final int shadowLeft = getShadowLeft(elevation);
  final int shadowRight = getShadowRight(elevation);

  return Column.create(c)
      .child(
          Column.create(c)
              .marginPx(LEFT, shadowLeft)
              .marginPx(RIGHT, shadowRight)
              .marginPx(TOP, disableClipTopLeft && disableClipTopRight ? 0 : shadowTop)
              .marginPx(
                  BOTTOM, disableClipBottomLeft && disableClipBottomRight ? 0 : shadowBottom)
              .backgroundColor(clippingColor)
              .child(
                  TransparencyEnabledCardClip.create(c)
                      .cardBackgroundColor(cardBackgroundColor)
                      .cornerRadiusPx(cornerRadius)
                      .positionType(ABSOLUTE)
                      .positionPx(ALL, 0))
              .child(content))
      .child(
          elevation > 0
              ? CardShadow.create(c)
                  .shadowStartColor(shadowStartColor)
                  .shadowEndColor(shadowEndColor)
                  .cornerRadiusPx(cornerRadius)
                  .shadowSizePx(elevation)
                  .hideTopShadow(disableClipTopLeft && disableClipTopRight)
                  .hideBottomShadow(disableClipBottomLeft && disableClipBottomRight)
                  .positionType(ABSOLUTE)
                  .positionPx(ALL, 0)
              : null)
      .build();
}