Valentin Shergin 94d49e544d Fabric: Codemod: All <fabric/... includes were renamed to <react/...
Summary: We are moving to more stable APIs removing all mentiones of the effort name from the codebase.

Reviewed By: mdvacca

Differential Revision: D12912894

fbshipit-source-id: 4a0c6b9e7454b8b14e62d419e9e9311dc0c56e7a
2018-11-10 14:22:15 -08:00

108 lines
2.4 KiB
C++

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#pragma once
#include <folly/dynamic.h>
#include <react/graphics/conversions.h>
#include <react/imagemanager/primitives.h>
namespace facebook {
namespace react {
inline void fromDynamic(const folly::dynamic &value, ImageSource &result) {
if (value.isString()) {
result = {.type = ImageSource::Type::Remote, .uri = value.asString()};
return;
}
if (value.isObject()) {
result = {};
result.type = ImageSource::Type::Remote;
if (value.count("__packager_asset")) {
result.type = ImageSource::Type::Local;
}
if (value.count("width") && value.count("height")) {
fromDynamic(value, result.size);
}
if (value.count("scale")) {
result.scale = (Float)value["scale"].asDouble();
} else {
result.scale = value.count("deprecated") ? 0.0 : 1.0;
}
if (value.count("url")) {
result.uri = value["url"].asString();
}
if (value.count("uri")) {
result.uri = value["uri"].asString();
}
if (value.count("bundle")) {
result.bundle = value["bundle"].asString();
result.type = ImageSource::Type::Local;
}
return;
}
abort();
}
inline std::string toString(const ImageSource &value) {
return "{uri: " + value.uri + "}";
}
inline void fromDynamic(const folly::dynamic &value, ImageResizeMode &result) {
assert(value.isString());
auto stringValue = value.asString();
if (stringValue == "cover") {
result = ImageResizeMode::Cover;
return;
}
if (stringValue == "contain") {
result = ImageResizeMode::Contain;
return;
}
if (stringValue == "stretch") {
result = ImageResizeMode::Stretch;
return;
}
if (stringValue == "center") {
result = ImageResizeMode::Center;
return;
}
if (stringValue == "repeat") {
result = ImageResizeMode::Repeat;
return;
}
abort();
}
inline std::string toString(const ImageResizeMode &value) {
switch (value) {
case ImageResizeMode::Cover:
return "cover";
case ImageResizeMode::Contain:
return "contain";
case ImageResizeMode::Stretch:
return "stretch";
case ImageResizeMode::Center:
return "center";
case ImageResizeMode::Repeat:
return "repeat";
}
}
} // namespace react
} // namespace facebook