Java Code Examples for com.facebook.yoga.YogaConstants#UNDEFINED

The following examples show how to use com.facebook.yoga.YogaConstants#UNDEFINED . 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: ReactHorizontalScrollViewManager.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(ReactHorizontalScrollView 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: LayoutShadowNode.java    From react-native-GPay with MIT License 6 votes vote down vote up
@ReactPropGroup(
  names = {
    ViewProps.BORDER_WIDTH,
    ViewProps.BORDER_START_WIDTH,
    ViewProps.BORDER_END_WIDTH,
    ViewProps.BORDER_TOP_WIDTH,
    ViewProps.BORDER_BOTTOM_WIDTH,
    ViewProps.BORDER_LEFT_WIDTH,
    ViewProps.BORDER_RIGHT_WIDTH,
  },
  defaultFloat = YogaConstants.UNDEFINED
)
public void setBorderWidths(int index, float borderWidth) {
  if (isVirtual()) {
    return;
  }
  int spacingType = maybeTransformLeftRightToStartEnd(ViewProps.BORDER_SPACING_TYPES[index]);
  setBorder(spacingType, PixelUtil.toPixelFromDIP(borderWidth));
}
 
Example 3
Source File: LayoutShadowNode.java    From react-native-GPay with MIT License 6 votes vote down vote up
void setFromDynamic(Dynamic dynamic) {
  if (dynamic.isNull()) {
    unit = YogaUnit.UNDEFINED;
    value = YogaConstants.UNDEFINED;
  } else if (dynamic.getType() == ReadableType.String) {
    final String s = dynamic.asString();
    if (s.equals("auto")) {
      unit = YogaUnit.AUTO;
      value = YogaConstants.UNDEFINED;
    } else if (s.endsWith("%")) {
      unit = YogaUnit.PERCENT;
      value = Float.parseFloat(s.substring(0, s.length() - 1));
    } else {
      throw new IllegalArgumentException("Unknown value: " + s);
    }
  } else {
    unit = YogaUnit.POINT;
    value = PixelUtil.toPixelFromDIP(dynamic.asDouble());
  }
}
 
Example 4
Source File: Spacing.java    From react-native-GPay with MIT License 6 votes vote down vote up
/**
 * Get the spacing for a direction. This takes into account any default values that have been set.
 *
 * @param spacingType one of {@link #LEFT}, {@link #TOP}, {@link #RIGHT}, {@link #BOTTOM}
 */
public float get(int spacingType) {
  float defaultValue = (spacingType == START || spacingType == END
      ? YogaConstants.UNDEFINED
      : mDefaultValue);

  if (mValueFlags == 0) {
    return defaultValue;
  }

  if ((mValueFlags & sFlagsMap[spacingType]) != 0) {
    return mSpacing[spacingType];
  }

  if (mHasAliasesSet) {
    int secondType = spacingType == TOP || spacingType == BOTTOM ? VERTICAL : HORIZONTAL;
    if ((mValueFlags & sFlagsMap[secondType]) != 0) {
      return mSpacing[secondType];
    } else if ((mValueFlags & sFlagsMap[ALL]) != 0) {
      return mSpacing[ALL];
    }
  }

  return defaultValue;
}
 
Example 5
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 6
Source File: ReactTextAnchorViewManager.java    From react-native-GPay with MIT License 6 votes vote down vote up
@ReactPropGroup(
  names = {
    "borderColor",
    "borderLeftColor",
    "borderRightColor",
    "borderTopColor",
    "borderBottomColor"
  },
  customType = "Color"
)
public void setBorderColor(ReactTextView view, int index, Integer color) {
  float rgbComponent =
      color == null ? YogaConstants.UNDEFINED : (float) ((int) color & 0x00FFFFFF);
  float alphaComponent = color == null ? YogaConstants.UNDEFINED : (float) ((int) color >>> 24);
  view.setBorderColor(SPACING_TYPES[index], rgbComponent, alphaComponent);
}
 
Example 7
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 8
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 9
Source File: Edges.java    From litho with Apache License 2.0 6 votes vote down vote up
private byte getFirstAvailableIndex() {
  if (mValues == null) {
    mValues = new float[] {YogaConstants.UNDEFINED, YogaConstants.UNDEFINED};
    return 0;
  }

  for (int i = 0; i < mValues.length; i++) {
    if (YogaConstants.isUndefined(mValues[i])) {
      return (byte) i;
    }
  }

  // We traversed the array without finding an empty spot. We need to increase the array.
  float[] oldValues = mValues;
  mValues = new float[Math.min(oldValues.length * 2, EDGES_LENGTH)];
  System.arraycopy(oldValues, 0, mValues, 0, oldValues.length);
  Arrays.fill(mValues, oldValues.length, mValues.length, YogaConstants.UNDEFINED);

  return (byte) oldValues.length;
}
 
Example 10
Source File: DefaultInternalNode.java    From litho with Apache License 2.0 5 votes vote down vote up
/** This method marks all resolved layout property values to undefined. */
@Override
public void resetResolvedLayoutProperties() {
  mResolvedTouchExpansionLeft = YogaConstants.UNDEFINED;
  mResolvedTouchExpansionRight = YogaConstants.UNDEFINED;
  mResolvedX = YogaConstants.UNDEFINED;
  mResolvedY = YogaConstants.UNDEFINED;
  mResolvedWidth = YogaConstants.UNDEFINED;
  mResolvedHeight = YogaConstants.UNDEFINED;
}
 
Example 11
Source File: ReactHorizontalScrollViewManager.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(ReactHorizontalScrollView view, int index, float width) {
  if (!YogaConstants.isUndefined(width)) {
    width = PixelUtil.toPixelFromDIP(width);
  }
  view.setBorderWidth(SPACING_TYPES[index], width);
}
 
Example 12
Source File: ReactHorizontalScrollViewManager.java    From react-native-GPay with MIT License 5 votes vote down vote up
@ReactPropGroup(names = {
    "borderColor", "borderLeftColor", "borderRightColor", "borderTopColor", "borderBottomColor"
}, customType = "Color")
public void setBorderColor(ReactHorizontalScrollView view, int index, Integer color) {
  float rgbComponent =
      color == null ? YogaConstants.UNDEFINED : (float) ((int)color & 0x00FFFFFF);
  float alphaComponent = color == null ? YogaConstants.UNDEFINED : (float) ((int)color >>> 24);
  view.setBorderColor(SPACING_TYPES[index], rgbComponent, alphaComponent);
}
 
Example 13
Source File: Spacing.java    From react-native-GPay with MIT License 5 votes vote down vote up
private static float[] newFullSpacingArray() {
  return new float[] {
      YogaConstants.UNDEFINED,
      YogaConstants.UNDEFINED,
      YogaConstants.UNDEFINED,
      YogaConstants.UNDEFINED,
      YogaConstants.UNDEFINED,
      YogaConstants.UNDEFINED,
      YogaConstants.UNDEFINED,
      YogaConstants.UNDEFINED,
      YogaConstants.UNDEFINED,
  };
}
 
Example 14
Source File: ReactScrollViewManager.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(ReactScrollView view, int index, float width) {
  if (!YogaConstants.isUndefined(width)) {
    width = PixelUtil.toPixelFromDIP(width);
  }
  view.setBorderWidth(SPACING_TYPES[index], width);
}
 
Example 15
Source File: Edges.java    From litho with Apache License 2.0 5 votes vote down vote up
public float getRaw(YogaEdge edge) {
  final byte edgeIndex = getIndex(edge.intValue());
  if (edgeIndex == UNDEFINED_INDEX) {
    return YogaConstants.UNDEFINED;
  }

  return mValues[edgeIndex];
}
 
Example 16
Source File: Edges.java    From litho with Apache License 2.0 5 votes vote down vote up
/** @param edgeEnumValue This method can directly accept the YogaEdge.XXX.intValue(). */
// This duplicates the other getRaw instead of calling each other to save on method calls.
public float getRaw(int edgeEnumValue) {
  final byte edgeIndex = getIndex(edgeEnumValue);
  if (edgeIndex == UNDEFINED_INDEX) {
    return YogaConstants.UNDEFINED;
  }

  return mValues[edgeIndex];
}
 
Example 17
Source File: ReactTextInputManager.java    From react-native-GPay with MIT License 5 votes vote down vote up
@ReactPropGroup(names = {
    "borderColor", "borderLeftColor", "borderRightColor", "borderTopColor", "borderBottomColor"
}, customType = "Color")
public void setBorderColor(ReactEditText view, int index, Integer color) {
  float rgbComponent = color == null ? YogaConstants.UNDEFINED : (float) ((int)color & 0x00FFFFFF);
  float alphaComponent = color == null ? YogaConstants.UNDEFINED : (float) ((int)color >>> 24);
  view.setBorderColor(SPACING_TYPES[index], rgbComponent, alphaComponent);
}
 
Example 18
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 19
Source File: LayoutShadowNode.java    From react-native-GPay with MIT License 4 votes vote down vote up
@ReactProp(name = ViewProps.ASPECT_RATIO, defaultFloat = YogaConstants.UNDEFINED)
public void setAspectRatio(float aspectRatio) {
  setStyleAspectRatio(aspectRatio);
}
 
Example 20
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;
}