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

The following examples show how to use com.facebook.litho.annotations.ResType#DIMEN_OFFSET . 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: 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 4
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();
}
 
Example 5
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 6
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 7
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);
}