protected static void applyLayoutParams()

in android/src/main/java/com/facebook/yoga/android/YogaLayout.java [384:625]


  protected static void applyLayoutParams(LayoutParams layoutParameters, YogaNode node, View view) {
    // JELLY_BEAN_MR1 (17) is the first version supporting getLayoutDirection()
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
      Configuration configuration = view.getResources().getConfiguration();
      if (configuration.getLayoutDirection() == LAYOUT_DIRECTION_RTL) {
        node.setDirection(YogaDirection.RTL);
      }
    }

    Drawable background = view.getBackground();
    if (background != null) {
      final Rect backgroundPadding = new Rect();
      if (background.getPadding(backgroundPadding)) {
        node.setPadding(YogaEdge.LEFT, backgroundPadding.left);
        node.setPadding(YogaEdge.TOP, backgroundPadding.top);
        node.setPadding(YogaEdge.RIGHT, backgroundPadding.right);
        node.setPadding(YogaEdge.BOTTOM, backgroundPadding.bottom);
      }
    }

    for (int i = 0; i < layoutParameters.numericAttributes.size(); i++) {
      final int attribute = layoutParameters.numericAttributes.keyAt(i);
      final float value = layoutParameters.numericAttributes.valueAt(i);

      if (attribute == R.styleable.yoga_yg_alignContent) {
        node.setAlignContent(YogaAlign.fromInt(Math.round(value)));
      } else if (attribute == R.styleable.yoga_yg_alignItems) {
        node.setAlignItems(YogaAlign.fromInt(Math.round(value)));
      } else if (attribute == R.styleable.yoga_yg_alignSelf) {
        node.setAlignSelf(YogaAlign.fromInt(Math.round(value)));
      } else if (attribute == R.styleable.yoga_yg_aspectRatio) {
        node.setAspectRatio(value);
      } else if (attribute == R.styleable.yoga_yg_borderLeft) {
        node.setBorder(YogaEdge.LEFT, value);
      } else if (attribute == R.styleable.yoga_yg_borderTop) {
        node.setBorder(YogaEdge.TOP, value);
      } else if (attribute == R.styleable.yoga_yg_borderRight) {
        node.setBorder(YogaEdge.RIGHT, value);
      } else if (attribute == R.styleable.yoga_yg_borderBottom) {
        node.setBorder(YogaEdge.BOTTOM, value);
      } else if (attribute == R.styleable.yoga_yg_borderStart) {
        node.setBorder(YogaEdge.START, value);
      } else if (attribute == R.styleable.yoga_yg_borderEnd) {
        node.setBorder(YogaEdge.END, value);
      } else if (attribute == R.styleable.yoga_yg_borderHorizontal) {
        node.setBorder(YogaEdge.HORIZONTAL, value);
      } else if (attribute == R.styleable.yoga_yg_borderVertical) {
        node.setBorder(YogaEdge.VERTICAL, value);
      } else if (attribute == R.styleable.yoga_yg_borderAll) {
        node.setBorder(YogaEdge.ALL, value);
      } else if (attribute == R.styleable.yoga_yg_direction) {
        node.setDirection(YogaDirection.fromInt(Math.round(value)));
      } else if (attribute == R.styleable.yoga_yg_display) {
        node.setDisplay(YogaDisplay.fromInt(Math.round(value)));
      } else if (attribute == R.styleable.yoga_yg_flex) {
        node.setFlex(value);
      } else if (attribute == R.styleable.yoga_yg_flexBasis) {
        node.setFlexBasis(value);
      } else if (attribute == R.styleable.yoga_yg_flexDirection) {
        node.setFlexDirection(YogaFlexDirection.fromInt(Math.round(value)));
      } else if (attribute == R.styleable.yoga_yg_flexGrow) {
        node.setFlexGrow(value);
      } else if (attribute == R.styleable.yoga_yg_flexShrink) {
        node.setFlexShrink(value);
      } else if (attribute == R.styleable.yoga_yg_height) {
        node.setHeight(value);
      } else if (attribute == R.styleable.yoga_yg_marginLeft) {
        node.setMargin(YogaEdge.LEFT, value);
      } else if (attribute == R.styleable.yoga_yg_justifyContent) {
        node.setJustifyContent(YogaJustify.fromInt(Math.round(value)));
      } else if (attribute == R.styleable.yoga_yg_marginTop) {
        node.setMargin(YogaEdge.TOP, value);
      } else if (attribute == R.styleable.yoga_yg_marginRight) {
        node.setMargin(YogaEdge.RIGHT, value);
      } else if (attribute == R.styleable.yoga_yg_marginBottom) {
        node.setMargin(YogaEdge.BOTTOM, value);
      } else if (attribute == R.styleable.yoga_yg_marginStart) {
        node.setMargin(YogaEdge.START, value);
      } else if (attribute == R.styleable.yoga_yg_marginEnd) {
        node.setMargin(YogaEdge.END, value);
      } else if (attribute == R.styleable.yoga_yg_marginHorizontal) {
        node.setMargin(YogaEdge.HORIZONTAL, value);
      } else if (attribute == R.styleable.yoga_yg_marginVertical) {
        node.setMargin(YogaEdge.VERTICAL, value);
      } else if (attribute == R.styleable.yoga_yg_marginAll) {
        node.setMargin(YogaEdge.ALL, value);
      } else if (attribute == R.styleable.yoga_yg_maxHeight) {
        node.setMaxHeight(value);
      } else if (attribute == R.styleable.yoga_yg_maxWidth) {
        node.setMaxWidth(value);
      } else if (attribute == R.styleable.yoga_yg_minHeight) {
        node.setMinHeight(value);
      } else if (attribute == R.styleable.yoga_yg_minWidth) {
        node.setMinWidth(value);
      } else if (attribute == R.styleable.yoga_yg_overflow) {
        node.setOverflow(YogaOverflow.fromInt(Math.round(value)));
      } else if (attribute == R.styleable.yoga_yg_paddingLeft) {
        node.setPadding(YogaEdge.LEFT, value);
      } else if (attribute == R.styleable.yoga_yg_paddingTop) {
        node.setPadding(YogaEdge.TOP, value);
      } else if (attribute == R.styleable.yoga_yg_paddingRight) {
        node.setPadding(YogaEdge.RIGHT, value);
      } else if (attribute == R.styleable.yoga_yg_paddingBottom) {
        node.setPadding(YogaEdge.BOTTOM, value);
      } else if (attribute == R.styleable.yoga_yg_paddingStart) {
        node.setPadding(YogaEdge.START, value);
      } else if (attribute == R.styleable.yoga_yg_paddingEnd) {
        node.setPadding(YogaEdge.END, value);
      } else if (attribute == R.styleable.yoga_yg_paddingHorizontal) {
        node.setPadding(YogaEdge.HORIZONTAL, value);
      } else if (attribute == R.styleable.yoga_yg_paddingVertical) {
        node.setPadding(YogaEdge.VERTICAL, value);
      } else if (attribute == R.styleable.yoga_yg_paddingAll) {
        node.setPadding(YogaEdge.ALL, value);
      } else if (attribute == R.styleable.yoga_yg_positionLeft) {
        node.setPosition(YogaEdge.LEFT, value);
      } else if (attribute == R.styleable.yoga_yg_positionTop) {
        node.setPosition(YogaEdge.TOP, value);
      } else if (attribute == R.styleable.yoga_yg_positionRight) {
        node.setPosition(YogaEdge.RIGHT, value);
      } else if (attribute == R.styleable.yoga_yg_positionBottom) {
        node.setPosition(YogaEdge.BOTTOM, value);
      } else if (attribute == R.styleable.yoga_yg_positionStart) {
        node.setPosition(YogaEdge.START, value);
      } else if (attribute == R.styleable.yoga_yg_positionEnd) {
        node.setPosition(YogaEdge.END, value);
      } else if (attribute == R.styleable.yoga_yg_positionHorizontal) {
        node.setPosition(YogaEdge.HORIZONTAL, value);
      } else if (attribute == R.styleable.yoga_yg_positionVertical) {
        node.setPosition(YogaEdge.VERTICAL, value);
      } else if (attribute == R.styleable.yoga_yg_positionAll) {
        node.setPosition(YogaEdge.ALL, value);
      } else if (attribute == R.styleable.yoga_yg_positionType) {
        node.setPositionType(YogaPositionType.fromInt(Math.round(value)));
      } else if (attribute == R.styleable.yoga_yg_width) {
        node.setWidth(value);
      } else if (attribute == R.styleable.yoga_yg_wrap) {
        node.setWrap(YogaWrap.fromInt(Math.round(value)));
      }
    }

    for (int i = 0; i < layoutParameters.stringAttributes.size(); i++) {
      final int attribute = layoutParameters.stringAttributes.keyAt(i);
      final String value = layoutParameters.stringAttributes.valueAt(i);

      if (value.equals("auto")) {
        if (attribute == R.styleable.yoga_yg_marginLeft) {
          node.setMarginAuto(YogaEdge.LEFT);
        } else if (attribute == R.styleable.yoga_yg_marginTop) {
          node.setMarginAuto(YogaEdge.TOP);
        } else if (attribute == R.styleable.yoga_yg_marginRight) {
          node.setMarginAuto(YogaEdge.RIGHT);
        } else if (attribute == R.styleable.yoga_yg_marginBottom) {
          node.setMarginAuto(YogaEdge.BOTTOM);
        } else if (attribute == R.styleable.yoga_yg_marginStart) {
          node.setMarginAuto(YogaEdge.START);
        } else if (attribute == R.styleable.yoga_yg_marginEnd) {
          node.setMarginAuto(YogaEdge.END);
        } else if (attribute == R.styleable.yoga_yg_marginHorizontal) {
          node.setMarginAuto(YogaEdge.HORIZONTAL);
        } else if (attribute == R.styleable.yoga_yg_marginVertical) {
          node.setMarginAuto(YogaEdge.VERTICAL);
        } else if (attribute == R.styleable.yoga_yg_marginAll) {
          node.setMarginAuto(YogaEdge.ALL);
        }
      }

      if (value.endsWith("%")) {
        final float numericValue = Float.parseFloat(value.substring(0, value.length()-1));

        if (attribute == R.styleable.yoga_yg_flexBasis) {
          node.setFlexBasisPercent(numericValue);
        } else if (attribute == R.styleable.yoga_yg_height) {
          node.setHeightPercent(numericValue);
        } else if (attribute == R.styleable.yoga_yg_marginLeft) {
          node.setMarginPercent(YogaEdge.LEFT, numericValue);
        } else if (attribute == R.styleable.yoga_yg_marginTop) {
          node.setMarginPercent(YogaEdge.TOP, numericValue);
        } else if (attribute == R.styleable.yoga_yg_marginRight) {
          node.setMarginPercent(YogaEdge.RIGHT, numericValue);
        } else if (attribute == R.styleable.yoga_yg_marginBottom) {
          node.setMarginPercent(YogaEdge.BOTTOM, numericValue);
        } else if (attribute == R.styleable.yoga_yg_marginStart) {
          node.setMarginPercent(YogaEdge.START, numericValue);
        } else if (attribute == R.styleable.yoga_yg_marginEnd) {
          node.setMarginPercent(YogaEdge.END, numericValue);
        } else if (attribute == R.styleable.yoga_yg_marginHorizontal) {
          node.setMarginPercent(YogaEdge.HORIZONTAL, numericValue);
        } else if (attribute == R.styleable.yoga_yg_marginVertical) {
          node.setMarginPercent(YogaEdge.VERTICAL, numericValue);
        } else if (attribute == R.styleable.yoga_yg_marginAll) {
          node.setMarginPercent(YogaEdge.ALL, numericValue);
        } else if (attribute == R.styleable.yoga_yg_maxHeight) {
          node.setMaxHeightPercent(numericValue);
        } else if (attribute == R.styleable.yoga_yg_maxWidth) {
          node.setMaxWidthPercent(numericValue);
        } else if (attribute == R.styleable.yoga_yg_minHeight) {
          node.setMinHeightPercent(numericValue);
        } else if (attribute == R.styleable.yoga_yg_minWidth) {
          node.setMinWidthPercent(numericValue);
        } else if (attribute == R.styleable.yoga_yg_paddingLeft) {
          node.setPaddingPercent(YogaEdge.LEFT, numericValue);
        } else if (attribute == R.styleable.yoga_yg_paddingTop) {
          node.setPaddingPercent(YogaEdge.TOP, numericValue);
        } else if (attribute == R.styleable.yoga_yg_paddingRight) {
          node.setPaddingPercent(YogaEdge.RIGHT, numericValue);
        } else if (attribute == R.styleable.yoga_yg_paddingBottom) {
          node.setPaddingPercent(YogaEdge.BOTTOM, numericValue);
        } else if (attribute == R.styleable.yoga_yg_paddingStart) {
          node.setPaddingPercent(YogaEdge.START, numericValue);
        } else if (attribute == R.styleable.yoga_yg_paddingEnd) {
          node.setPaddingPercent(YogaEdge.END, numericValue);
        } else if (attribute == R.styleable.yoga_yg_paddingHorizontal) {
          node.setPaddingPercent(YogaEdge.HORIZONTAL, numericValue);
        } else if (attribute == R.styleable.yoga_yg_paddingVertical) {
          node.setPaddingPercent(YogaEdge.VERTICAL, numericValue);
        } else if (attribute == R.styleable.yoga_yg_paddingAll) {
          node.setPaddingPercent(YogaEdge.ALL, numericValue);
        } else if (attribute == R.styleable.yoga_yg_positionLeft) {
          node.setPositionPercent(YogaEdge.LEFT, numericValue);
        } else if (attribute == R.styleable.yoga_yg_positionTop) {
          node.setPositionPercent(YogaEdge.TOP, numericValue);
        } else if (attribute == R.styleable.yoga_yg_positionRight) {
          node.setPositionPercent(YogaEdge.RIGHT, numericValue);
        } else if (attribute == R.styleable.yoga_yg_positionBottom) {
          node.setPositionPercent(YogaEdge.BOTTOM, numericValue);
        } else if (attribute == R.styleable.yoga_yg_positionStart) {
          node.setPositionPercent(YogaEdge.START, numericValue);
        } else if (attribute == R.styleable.yoga_yg_positionEnd) {
          node.setPositionPercent(YogaEdge.END, numericValue);
        } else if (attribute == R.styleable.yoga_yg_positionHorizontal) {
          node.setPositionPercent(YogaEdge.HORIZONTAL, numericValue);
        } else if (attribute == R.styleable.yoga_yg_positionVertical) {
          node.setPositionPercent(YogaEdge.VERTICAL, numericValue);
        } else if (attribute == R.styleable.yoga_yg_positionAll) {
          node.setPositionPercent(YogaEdge.ALL, numericValue);
        } else if (attribute == R.styleable.yoga_yg_width) {
          node.setWidthPercent(numericValue);
        }
      }
    }
  }