Java Code Examples for com.facebook.react.bridge.Dynamic#getType()

The following examples show how to use com.facebook.react.bridge.Dynamic#getType() . 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: 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 2
Source File: ReactDrawerLayoutManager_1d0b39_t.java    From coming with MIT License 6 votes vote down vote up
@ReactProp(name = "drawerPosition")
public void setDrawerPosition(ReactDrawerLayout view, Dynamic drawerPosition) {
  if (drawerPosition.isNull()) {
    view.setDrawerPosition(Gravity.START);
  } else if (drawerPosition.getType() == ReadableType.Number) {
    final int drawerPositionNum = drawerPosition.asInt();

    if (Gravity.START == drawerPositionNum || Gravity.END == drawerPositionNum) {
      view.setDrawerPosition(drawerPositionNum);
    } else {
      throw new JSApplicationIllegalArgumentException("Unknown drawerPosition " + drawerPositionNum);
    }
  } else if (drawerPosition.getType() == ReadableType.String) {
    final String drawerPositionStr = drawerPosition.asString();

    if (drawerPositionStr.equals("left")) {
      view.setDrawerPosition(Gravity.START);
    } else if (drawerPositionStr.equals("right")) {
      view.setDrawerPosition(Gravity.END);
    } else {
      throw new JSApplicationIllegalArgumentException("drawerPosition must be 'left' or 'right', received" + drawerPositionStr);
    }
  } else {
    throw new JSApplicationIllegalArgumentException("drawerPosition must be a string or int");
  }
}
 
Example 3
Source File: FrescoBasedReactTextInlineImageShadowNode.java    From react-native-GPay with MIT License 5 votes vote down vote up
/**
 * Besides width/height, all other layout props on inline images are ignored
 */
@Override
public void setWidth(Dynamic width) {
  if (width.getType() == ReadableType.Number) {
    mWidth = (float) width.asDouble();
  } else {
    throw new JSApplicationIllegalArgumentException(
        "Inline images must not have percentage based width");
  }
}
 
Example 4
Source File: FrescoBasedReactTextInlineImageShadowNode.java    From react-native-GPay with MIT License 5 votes vote down vote up
@Override
public void setHeight(Dynamic height) {
  if (height.getType() == ReadableType.Number) {
    mHeight = (float) height.asDouble();
  } else {
    throw new JSApplicationIllegalArgumentException(
        "Inline images must not have percentage based height");
  }
}