mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-06-16 06:42:37 +08:00
Summary: This pull request removes the designated initializers in `react/components/image/**` to improve portability. [General] [Changed] - Fabric: Remove designated initializers in Image Pull Request resolved: https://github.com/facebook/react-native/pull/23439 Differential Revision: D14298888 Pulled By: shergin fbshipit-source-id: 9b6ad5fdcec4d3b19b8d69afac80ce18d37f31e6
114 lines
2.7 KiB
C++
114 lines
2.7 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 <better/map.h>
|
|
#include <folly/dynamic.h>
|
|
#include <react/graphics/conversions.h>
|
|
#include <react/imagemanager/primitives.h>
|
|
|
|
namespace facebook {
|
|
namespace react {
|
|
|
|
inline void fromRawValue(const RawValue &value, ImageSource &result) {
|
|
if (value.hasType<std::string>()) {
|
|
result = {
|
|
/* .type = */ ImageSource::Type::Remote,
|
|
/* .uri = */ (std::string)value,
|
|
};
|
|
return;
|
|
}
|
|
|
|
if (value.hasType<better::map<std::string, RawValue>>()) {
|
|
auto items = (better::map<std::string, RawValue>)value;
|
|
result = {};
|
|
|
|
result.type = ImageSource::Type::Remote;
|
|
|
|
if (items.find("__packager_asset") != items.end()) {
|
|
result.type = ImageSource::Type::Local;
|
|
}
|
|
|
|
if (items.find("width") != items.end() &&
|
|
items.find("height") != items.end()) {
|
|
result.size = {(Float)items.at("width"), (Float)items.at("height")};
|
|
}
|
|
|
|
if (items.find("scale") != items.end()) {
|
|
result.scale = (Float)items.at("scale");
|
|
} else {
|
|
result.scale = items.find("deprecated") != items.end() ? 0.0 : 1.0;
|
|
}
|
|
|
|
if (items.find("url") != items.end()) {
|
|
result.uri = (std::string)items.at("url");
|
|
}
|
|
|
|
if (items.find("uri") != items.end()) {
|
|
result.uri = (std::string)items.at("uri");
|
|
}
|
|
|
|
if (items.find("bundle") != items.end()) {
|
|
result.bundle = (std::string)items.at("bundle");
|
|
result.type = ImageSource::Type::Local;
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
abort();
|
|
}
|
|
|
|
inline std::string toString(const ImageSource &value) {
|
|
return "{uri: " + value.uri + "}";
|
|
}
|
|
|
|
inline void fromRawValue(const RawValue &value, ImageResizeMode &result) {
|
|
assert(value.hasType<std::string>());
|
|
auto stringValue = (std::string)value;
|
|
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
|