com.facebook.yoga.YogaConstants Java Examples

The following examples show how to use com.facebook.yoga.YogaConstants. 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: 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 #2
Source File: EdgesTest.java    From litho with Apache License 2.0 6 votes vote down vote up
@Test
public void testInsertingOneEdgeMultipleTimes() {
  mEdges.set(YogaEdge.TOP, 1);
  mEdges.set(YogaEdge.TOP, 2);
  mEdges.set(YogaEdge.TOP, 3);
  mEdges.set(YogaEdge.TOP, 4);
  mEdges.set(YogaEdge.TOP, 5);

  long bits = ~0;
  bits &= ~((long) (0xF) << (YogaEdge.TOP.intValue() * 4));
  bits |= ((long) 0 << (YogaEdge.TOP.intValue() * 4));
  assertThat(getEdgesToValuesIndex()).isEqualTo(bits);

  assertThat(getValuesArray().length).isEqualTo(2);
  assertThat(getValuesArray()[0]).isEqualTo(5);
  assertThat(YogaConstants.isUndefined(getValuesArray()[1])).isTrue();
}
 
Example #3
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 #4
Source File: ReactViewManager.java    From react-native-GPay with MIT License 6 votes vote down vote up
@ReactPropGroup(
  names = {
    ViewProps.BORDER_COLOR,
    ViewProps.BORDER_LEFT_COLOR,
    ViewProps.BORDER_RIGHT_COLOR,
    ViewProps.BORDER_TOP_COLOR,
    ViewProps.BORDER_BOTTOM_COLOR,
    ViewProps.BORDER_START_COLOR,
    ViewProps.BORDER_END_COLOR
  },
  customType = "Color"
)
public void setBorderColor(ReactViewGroup 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 #5
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 #6
Source File: EdgesTest.java    From litho with Apache License 2.0 6 votes vote down vote up
@Test
public void testUnsettingAndSettingNewEdgesReusesArraySpace() {
  mEdges.set(YogaEdge.TOP, 1);
  mEdges.set(YogaEdge.LEFT, 2);
  mEdges.set(YogaEdge.ALL, 5);
  mEdges.set(YogaEdge.LEFT, YogaConstants.UNDEFINED);
  mEdges.set(YogaEdge.BOTTOM, 4);

  long bits = ~0;
  bits &= ~((long) (0xF) << (YogaEdge.TOP.intValue() * 4));
  bits &= ~((long) (0xF) << (YogaEdge.ALL.intValue() * 4));
  bits &= ~((long) (0xF) << (YogaEdge.BOTTOM.intValue() * 4));
  bits |= ((long) 0 << (YogaEdge.TOP.intValue() * 4));
  bits |= ((long) 1 << (YogaEdge.BOTTOM.intValue() * 4));
  bits |= ((long) 2 << (YogaEdge.ALL.intValue() * 4));
  assertThat(getEdgesToValuesIndex()).isEqualTo(bits);

  assertThat(getValuesArray().length).isEqualTo(4);
  assertThat(getValuesArray()[0]).isEqualTo(1);
  assertThat(getValuesArray()[1]).isEqualTo(4);
  assertThat(getValuesArray()[2]).isEqualTo(5);
  assertThat(getValuesArray()[3]).isNaN();
}
 
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: 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 #10
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 #11
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 #12
Source File: ReactImageManager.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(ReactImageView 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 #13
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 #14
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 #15
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 #16
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 #17
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 #18
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 #19
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 #20
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 #21
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 #22
Source File: DefaultInternalNode.java    From litho with Apache License 2.0 5 votes vote down vote up
@Px
@Override
public int getHeight() {
  if (YogaConstants.isUndefined(mResolvedHeight)) {
    mResolvedHeight = mYogaNode.getLayoutHeight();
  }

  return (int) mResolvedHeight;
}
 
Example #23
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 #24
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 #25
Source File: DefaultInternalNode.java    From litho with Apache License 2.0 5 votes vote down vote up
@Override
public int getTouchExpansionRight() {
  if (!shouldApplyTouchExpansion()) {
    return 0;
  }

  if (YogaConstants.isUndefined(mResolvedTouchExpansionRight)) {
    mResolvedTouchExpansionRight = resolveHorizontalEdges(mTouchExpansion, YogaEdge.RIGHT);
  }

  return FastMath.round(mResolvedTouchExpansionRight);
}
 
Example #26
Source File: DefaultInternalNode.java    From litho with Apache License 2.0 5 votes vote down vote up
@Override
public int getTouchExpansionLeft() {
  if (!shouldApplyTouchExpansion()) {
    return 0;
  }

  if (YogaConstants.isUndefined(mResolvedTouchExpansionLeft)) {
    mResolvedTouchExpansionLeft = resolveHorizontalEdges(mTouchExpansion, YogaEdge.LEFT);
  }

  return FastMath.round(mResolvedTouchExpansionLeft);
}
 
Example #27
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 #28
Source File: EdgesTest.java    From litho with Apache License 2.0 5 votes vote down vote up
@Test
public void testUnsettingAnEdge() {
  mEdges.set(YogaEdge.TOP, 1);
  mEdges.set(YogaEdge.TOP, 2);
  mEdges.set(YogaEdge.TOP, YogaConstants.UNDEFINED);

  long bits = ~0;
  assertThat(getEdgesToValuesIndex()).isEqualTo(bits);

  assertThat(getValuesArray().length).isEqualTo(2);
  assertThat(YogaConstants.isUndefined(getValuesArray()[0])).isTrue();
  assertThat(YogaConstants.isUndefined(getValuesArray()[1])).isTrue();
}
 
Example #29
Source File: EdgesTest.java    From litho with Apache License 2.0 5 votes vote down vote up
@Test
public void testUnsettingNotTheFirstEdge() {
  mEdges.set(YogaEdge.TOP, 1);
  mEdges.set(YogaEdge.LEFT, 2);
  mEdges.set(YogaEdge.LEFT, YogaConstants.UNDEFINED);

  long bits = ~0;
  bits &= ~((long) (0xF) << (YogaEdge.TOP.intValue() * 4));
  bits |= ((long) 0 << (YogaEdge.TOP.intValue() * 4));
  assertThat(getEdgesToValuesIndex()).isEqualTo(bits);

  assertThat(getValuesArray().length).isEqualTo(2);
  assertThat(getValuesArray()[0]).isEqualTo(1);
  assertThat(getValuesArray()[1]).isNaN();
}
 
Example #30
Source File: DefaultInternalNode.java    From litho with Apache License 2.0 5 votes vote down vote up
@Override
public void setStyleHeightFromSpec(int heightSpec) {
  switch (SizeSpec.getMode(heightSpec)) {
    case SizeSpec.UNSPECIFIED:
      mYogaNode.setHeight(YogaConstants.UNDEFINED);
      break;
    case SizeSpec.AT_MOST:
      mYogaNode.setMaxHeight(SizeSpec.getSize(heightSpec));
      break;
    case SizeSpec.EXACTLY:
      mYogaNode.setHeight(SizeSpec.getSize(heightSpec));
      break;
  }
}