YGFloatOptional yogaStyleOptionalFloatFromDynamic(const folly::dynamic &value) {
  if (value.isNumber()) {
    return YGFloatOptional(value.asDouble());
  } else if (value.isString()) {
    const auto stringValue = value.asString();
    if (stringValue == "auto") {
      return YGFloatOptional();
    }
  }

  abort();
}
Exemplo n.º 2
0
std::function<void(folly::dynamic)> makeCallback(
    std::weak_ptr<Instance> instance, const folly::dynamic& callbackId) {
  if (!callbackId.isNumber()) {
    throw std::invalid_argument("Expected callback(s) as final argument");
  }

  auto id = callbackId.asInt();
  return [winstance = std::move(instance), id](folly::dynamic args) {
    if (auto instance = winstance.lock()) {
      instance->callJSCallback(id, std::move(args));
    }
  };
}
YGValue yogaStyleValueFromDynamic(const folly::dynamic &value) {
  if (value.isNumber()) {
    float x = value.asDouble();
    return { x, YGUnitPoint };
  } else if (value.isString()) {
    const auto stringValue = value.asString();
    if (stringValue == "auto") {
      return { YGUndefined, YGUnitAuto };
    } else {
      if (stringValue.back() == '%') {
        return { folly::to<float>(stringValue.substr(stringValue.length() - 1)), YGUnitPercent };
      } else {
        return { folly::to<float>(stringValue), YGUnitPoint };
      }
    }
  }

  return YGValueUndefined;
}