Java Code Examples for com.facebook.yoga.YogaConstants#isUndefined()

The following examples show how to use com.facebook.yoga.YogaConstants#isUndefined() . 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: ReactTextInputManager.java    From react-native-GPay with MIT License 6 votes vote down vote up
@ReactPropGroup(names = {
    ViewProps.BORDER_RADIUS,
    ViewProps.BORDER_TOP_LEFT_RADIUS,
    ViewProps.BORDER_TOP_RIGHT_RADIUS,
    ViewProps.BORDER_BOTTOM_RIGHT_RADIUS,
    ViewProps.BORDER_BOTTOM_LEFT_RADIUS
}, defaultFloat = YogaConstants.UNDEFINED)
public void setBorderRadius(ReactEditText view, int index, float borderRadius) {
  if (!YogaConstants.isUndefined(borderRadius)) {
    borderRadius = PixelUtil.toPixelFromDIP(borderRadius);
  }

  if (index == 0) {
    view.setBorderRadius(borderRadius);
  } else {
    view.setBorderRadius(borderRadius, index - 1);
  }
}
 
Example 2
Source File: ReactViewManager.java    From react-native-GPay with MIT License 6 votes vote down vote up
@ReactPropGroup(
  names = {
    ViewProps.BORDER_WIDTH,
    ViewProps.BORDER_LEFT_WIDTH,
    ViewProps.BORDER_RIGHT_WIDTH,
    ViewProps.BORDER_TOP_WIDTH,
    ViewProps.BORDER_BOTTOM_WIDTH,
    ViewProps.BORDER_START_WIDTH,
    ViewProps.BORDER_END_WIDTH,
  },
  defaultFloat = YogaConstants.UNDEFINED
)
public void setBorderWidth(ReactViewGroup view, int index, float width) {
  if (!YogaConstants.isUndefined(width) && width < 0) {
    width = YogaConstants.UNDEFINED;
  }

  if (!YogaConstants.isUndefined(width)) {
    width = PixelUtil.toPixelFromDIP(width);
  }

  view.setBorderWidth(SPACING_TYPES[index], width);
}
 
Example 3
Source File: DefaultInternalNode.java    From litho with Apache License 2.0 6 votes vote down vote up
private float resolveHorizontalEdges(Edges spacing, YogaEdge edge) {
  final boolean isRtl = (mYogaNode.getLayoutDirection() == YogaDirection.RTL);

  final YogaEdge resolvedEdge;
  switch (edge) {
    case LEFT:
      resolvedEdge = (isRtl ? YogaEdge.END : YogaEdge.START);
      break;

    case RIGHT:
      resolvedEdge = (isRtl ? YogaEdge.START : YogaEdge.END);
      break;

    default:
      throw new IllegalArgumentException("Not an horizontal padding edge: " + edge);
  }

  float result = spacing.getRaw(resolvedEdge);
  if (YogaConstants.isUndefined(result)) {
    result = spacing.get(edge);
  }

  return result;
}
 
Example 4
Source File: ReactScrollViewManager.java    From react-native-GPay with MIT License 6 votes vote down vote up
@ReactPropGroup(names = {
    ViewProps.BORDER_RADIUS,
    ViewProps.BORDER_TOP_LEFT_RADIUS,
    ViewProps.BORDER_TOP_RIGHT_RADIUS,
    ViewProps.BORDER_BOTTOM_RIGHT_RADIUS,
    ViewProps.BORDER_BOTTOM_LEFT_RADIUS
}, defaultFloat = YogaConstants.UNDEFINED)
public void setBorderRadius(ReactScrollView view, int index, float borderRadius) {
  if (!YogaConstants.isUndefined(borderRadius)) {
    borderRadius = PixelUtil.toPixelFromDIP(borderRadius);
  }

  if (index == 0) {
    view.setBorderRadius(borderRadius);
  } else {
    view.setBorderRadius(borderRadius, index - 1);
  }
}
 
Example 5
Source File: Spacing.java    From react-native-GPay with MIT License 6 votes vote down vote up
/**
 * Set a spacing value.
 *
 * @param spacingType one of {@link #LEFT}, {@link #TOP}, {@link #RIGHT}, {@link #BOTTOM},
 *        {@link #VERTICAL}, {@link #HORIZONTAL}, {@link #ALL}
 * @param value the value for this direction
 * @return {@code true} if the spacing has changed, or {@code false} if the same value was already
 *         set
 */
public boolean set(int spacingType, float value) {
  if (!FloatUtil.floatsEqual(mSpacing[spacingType], value)) {
    mSpacing[spacingType] = value;

    if (YogaConstants.isUndefined(value)) {
      mValueFlags &= ~sFlagsMap[spacingType];
    } else {
      mValueFlags |= sFlagsMap[spacingType];
    }

    mHasAliasesSet =
        (mValueFlags & sFlagsMap[ALL]) != 0 ||
        (mValueFlags & sFlagsMap[VERTICAL]) != 0 ||
        (mValueFlags & sFlagsMap[HORIZONTAL]) != 0;

    return true;
  }

  return false;
}
 
Example 6
Source File: ReactTextAnchorViewManager.java    From react-native-GPay with MIT License 6 votes vote down vote up
@ReactPropGroup(
  names = {
    ViewProps.BORDER_WIDTH,
    ViewProps.BORDER_LEFT_WIDTH,
    ViewProps.BORDER_RIGHT_WIDTH,
    ViewProps.BORDER_TOP_WIDTH,
    ViewProps.BORDER_BOTTOM_WIDTH,
  },
  defaultFloat = YogaConstants.UNDEFINED
)
public void setBorderWidth(ReactTextView view, int index, float width) {
  if (!YogaConstants.isUndefined(width)) {
    width = PixelUtil.toPixelFromDIP(width);
  }
  view.setBorderWidth(SPACING_TYPES[index], width);
}
 
Example 7
Source File: ReactTextAnchorViewManager.java    From react-native-GPay with MIT License 6 votes vote down vote up
@ReactPropGroup(
  names = {
    ViewProps.BORDER_RADIUS,
    ViewProps.BORDER_TOP_LEFT_RADIUS,
    ViewProps.BORDER_TOP_RIGHT_RADIUS,
    ViewProps.BORDER_BOTTOM_RIGHT_RADIUS,
    ViewProps.BORDER_BOTTOM_LEFT_RADIUS
  },
  defaultFloat = YogaConstants.UNDEFINED
)
public void setBorderRadius(ReactTextView view, int index, float borderRadius) {
  if (!YogaConstants.isUndefined(borderRadius)) {
    borderRadius = PixelUtil.toPixelFromDIP(borderRadius);
  }

  if (index == 0) {
    view.setBorderRadius(borderRadius);
  } else {
    view.setBorderRadius(borderRadius, index - 1);
  }
}
 
Example 8
Source File: ReactTextInputManager.java    From react-native-GPay with MIT License 5 votes vote down vote up
@ReactPropGroup(names = {
    ViewProps.BORDER_WIDTH,
    ViewProps.BORDER_LEFT_WIDTH,
    ViewProps.BORDER_RIGHT_WIDTH,
    ViewProps.BORDER_TOP_WIDTH,
    ViewProps.BORDER_BOTTOM_WIDTH,
}, defaultFloat = YogaConstants.UNDEFINED)
public void setBorderWidth(ReactEditText view, int index, float width) {
  if (!YogaConstants.isUndefined(width)) {
    width = PixelUtil.toPixelFromDIP(width);
  }
  view.setBorderWidth(SPACING_TYPES[index], width);
}
 
Example 9
Source File: ReactImageView.java    From react-native-GPay with MIT License 5 votes vote down vote up
private void cornerRadii(float[] computedCorners) {
  float defaultBorderRadius = !YogaConstants.isUndefined(mBorderRadius) ? mBorderRadius : 0;

  computedCorners[0] = mBorderCornerRadii != null && !YogaConstants.isUndefined(mBorderCornerRadii[0]) ? mBorderCornerRadii[0] : defaultBorderRadius;
  computedCorners[1] = mBorderCornerRadii != null && !YogaConstants.isUndefined(mBorderCornerRadii[1]) ? mBorderCornerRadii[1] : defaultBorderRadius;
  computedCorners[2] = mBorderCornerRadii != null && !YogaConstants.isUndefined(mBorderCornerRadii[2]) ? mBorderCornerRadii[2] : defaultBorderRadius;
  computedCorners[3] = mBorderCornerRadii != null && !YogaConstants.isUndefined(mBorderCornerRadii[3]) ? mBorderCornerRadii[3] : defaultBorderRadius;
}
 
Example 10
Source File: DefaultInternalNode.java    From litho with Apache License 2.0 5 votes vote down vote up
@Px
@Override
public int getWidth() {
  if (YogaConstants.isUndefined(mResolvedWidth)) {
    mResolvedWidth = mYogaNode.getLayoutWidth();
  }

  return (int) mResolvedWidth;
}
 
Example 11
Source File: DefaultInternalNode.java    From litho with Apache License 2.0 5 votes vote down vote up
@Px
@Override
public int getX() {
  if (YogaConstants.isUndefined(mResolvedX)) {
    mResolvedX = mYogaNode.getLayoutX();
  }

  return (int) mResolvedX;
}
 
Example 12
Source File: ReactShadowNodeImpl.java    From react-native-GPay with MIT License 5 votes vote down vote up
@Override
public void setPaddingPercent(int spacingType, float percent) {
  assertNotSealed();
  mPadding[spacingType] = percent;
  mPaddingIsPercent[spacingType] = !YogaConstants.isUndefined(percent);
  updatePadding();
}
 
Example 13
Source File: DefaultInternalNode.java    From litho with Apache License 2.0 5 votes vote down vote up
@Px
@Override
public int getY() {
  if (YogaConstants.isUndefined(mResolvedY)) {
    mResolvedY = mYogaNode.getLayoutY();
  }

  return (int) mResolvedY;
}
 
Example 14
Source File: ReactViewBackgroundDrawable.java    From react-native-GPay with MIT License 5 votes vote down vote up
@Override
public void getOutline(Outline outline) {
  if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
    super.getOutline(outline);
    return;
  }
  if ((!YogaConstants.isUndefined(mBorderRadius) && mBorderRadius > 0) || mBorderCornerRadii != null) {
    updatePath();

    outline.setConvexPath(mPathForBorderRadiusOutline);
  } else {
    outline.setRect(getBounds());
  }
}
 
Example 15
Source File: ReactViewBackgroundDrawable.java    From react-native-GPay with MIT License 5 votes vote down vote up
public boolean hasRoundedBorders() {
  if (!YogaConstants.isUndefined(mBorderRadius) && mBorderRadius > 0) {
    return true;
  }

  if (mBorderCornerRadii != null) {
    for (final float borderRadii : mBorderCornerRadii) {
      if (!YogaConstants.isUndefined(borderRadii) && borderRadii > 0) {
        return true;
      }
    }
  }

  return false;
}
 
Example 16
Source File: ReactViewManager.java    From react-native-GPay with MIT License 5 votes vote down vote up
@ReactPropGroup(names = {
    ViewProps.BORDER_RADIUS,
    ViewProps.BORDER_TOP_LEFT_RADIUS,
    ViewProps.BORDER_TOP_RIGHT_RADIUS,
    ViewProps.BORDER_BOTTOM_RIGHT_RADIUS,
    ViewProps.BORDER_BOTTOM_LEFT_RADIUS,
    ViewProps.BORDER_TOP_START_RADIUS,
    ViewProps.BORDER_TOP_END_RADIUS,
    ViewProps.BORDER_BOTTOM_START_RADIUS,
    ViewProps.BORDER_BOTTOM_END_RADIUS,
  },
  defaultFloat = YogaConstants.UNDEFINED
)
public void setBorderRadius(ReactViewGroup view, int index, float borderRadius) {
  if (!YogaConstants.isUndefined(borderRadius) && borderRadius < 0) {
    borderRadius = YogaConstants.UNDEFINED;
  }

  if (!YogaConstants.isUndefined(borderRadius)) {
    borderRadius = PixelUtil.toPixelFromDIP(borderRadius);
  }

  if (index == 0) {
    view.setBorderRadius(borderRadius);
  } else {
    view.setBorderRadius(borderRadius, index - 1);
  }
}
 
Example 17
Source File: ReactViewBackgroundDrawable.java    From react-native-GPay with MIT License 4 votes vote down vote up
private boolean isBorderColorDefined(int position) {
  final float rgb = mBorderRGB != null ? mBorderRGB.get(position) : YogaConstants.UNDEFINED;
  final float alpha = mBorderAlpha != null ? mBorderAlpha.get(position) : YogaConstants.UNDEFINED;
  return !YogaConstants.isUndefined(rgb) && !YogaConstants.isUndefined(alpha);
}
 
Example 18
Source File: Edges.java    From litho with Apache License 2.0 4 votes vote down vote up
public boolean set(YogaEdge yogaEdge, float value) {
  final int edgeIntValue = yogaEdge.intValue();
  if (!floatsEqual(getRaw(edgeIntValue), value)) {
    final byte edgeIndex = getIndex(edgeIntValue);

    // If we need to "unset" a previously set edge.
    if (YogaConstants.isUndefined(value)) {
      // UNSET index:
      // Set the 4 bits representing the edge as undefined ('1111').
      mEdgesToValuesIndex |= ((long) UNDEFINED_INDEX << (edgeIntValue * 4));
      mValues[edgeIndex] = YogaConstants.UNDEFINED;

      // If we need to insert a new edge value.
    } else if (edgeIndex == UNDEFINED_INDEX) {
      final byte newIndex = getFirstAvailableIndex();
      if (newIndex >= EDGES_LENGTH) {
        throw new IllegalStateException(
            "The newIndex for the array cannot be bigger than the amount of Yoga Edges.");
      }
      // SETS index:
      // Clear the bits at the index position.
      mEdgesToValuesIndex &= ~((long) (0xF) << (edgeIntValue * 4));
      // Then set the actual 4 bits value of the index. Leaving this as two steps for clarity.
      mEdgesToValuesIndex |= ((long) newIndex << (edgeIntValue * 4));
      mValues[newIndex] = value;

      // Otherwise we need to overwrite an existing value.
    } else {
      mValues[edgeIndex] = value;
    }

    // 1. It moves the right most 3 "4bits set" represeting ALL, VERTICAL and HORIZONTAL
    //    to the first 3 "4bits set" position of our long array (0xFFF).
    // 2. It converts the array from long to int.
    // 3. It inverts the bits of the current array. UNDEFINED_INDEX is 0xF or "1111".
    //    When an UNDEFINED_INDEX is inverted, we expect all zeros "0000".
    // 4. Now the inverted array is masked with 0xFFF to get only the values we
    //    are interested into.
    // 5. If the result is equal to 0, we know that ALL, VERTICAL and HORIZONTAL were
    //    all containing UNDEFINED_INDEXes. If that's not the case, we have an alias
    //    set and will set the mHasAliasesSet flag to true.
    mHasAliasesSet = (~((int) (mEdgesToValuesIndex >> ALIASES_RIGHT_SHIFT)) & ALIASES_MASK) != 0;

    return true;
  }

  return false;
}
 
Example 19
Source File: ReactViewBackgroundDrawable.java    From react-native-GPay with MIT License 4 votes vote down vote up
/** For rounded borders we use default "borderWidth" property. */
public float getFullBorderWidth() {
  return (mBorderWidth != null && !YogaConstants.isUndefined(mBorderWidth.getRaw(Spacing.ALL))) ?
      mBorderWidth.getRaw(Spacing.ALL) : 0f;
}
 
Example 20
Source File: ReactViewBackgroundDrawable.java    From react-native-GPay with MIT License 4 votes vote down vote up
public float getFullBorderRadius() {
  return YogaConstants.isUndefined(mBorderRadius) ? 0 : mBorderRadius;
}