Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions packages/react-native/React/Base/RCTUtils.mm
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#import <objc/runtime.h>
#import <zlib.h>
#import <atomic>
#import <cmath>
#import <vector>

#import <UIKit/UIKit.h>
Expand Down Expand Up @@ -437,20 +438,20 @@ CGSize RCTSwitchSize(void)
CGFloat RCTRoundPixelValue(CGFloat value)
{
CGFloat scale = RCTScreenScale();
return round(value * scale) / scale;
return std::round(value * scale) / scale;
}

CGFloat RCTCeilPixelValue(CGFloat value)
{
CGFloat scale = RCTScreenScale();
return ceil(value * scale) / scale;
return std::ceil(value * scale) / scale;
}

CGSize RCTSizeInPixels(CGSize pointSize, CGFloat scale)
{
return (CGSize){
ceil(pointSize.width * scale),
ceil(pointSize.height * scale),
std::ceil(pointSize.width * scale),
std::ceil(pointSize.height * scale),
};
}

Expand Down
4 changes: 3 additions & 1 deletion packages/react-native/ReactCommon/React-Fabric.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ Pod::Spec.new do |s|
end

s.subspec "attributedstring" do |ss|
ss.dependency "React-renderercss"
ss.dependency "React-Fabric/coreUmbrella"
ss.dependency "React-Fabric/components/viewUmbrella"
ss.dependency "React-renderercss"
ss.source_files = podspec_sources("react/renderer/attributedstring/**/*.{m,mm,cpp,h}", "react/renderer/attributedstring/**/*.{h}")
ss.exclude_files = "react/renderer/attributedstring/tests"
ss.header_dir = "react/renderer/attributedstring"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@

#include <react/cxxstableapi/FrameworksGuard.h>

#include <React/RendererCore.h>
#include <React/Utils.h>
#include <react/renderer/attributedstring/TextAttributes.h>
#include <react/renderer/core/Sealable.h>
#include <react/renderer/debug/DebugStringConvertible.h>
#include <react/renderer/mounting/ShadowView.h>
#include <react/utils/hash_combine.h>

namespace facebook::react {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include <memory>

#include <React/Debug.h>
#include <react/renderer/attributedstring/AttributedString.h>

namespace facebook::react {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

#include <limits>

#include <React/Graphics.h>
#include <React/RendererCore.h>
#include <React/Utils.h>
#include <react/renderer/attributedstring/primitives.h>
#include <react/renderer/debug/DebugStringConvertible.h>
#include <react/renderer/graphics/Float.h>
#include <react/utils/hash_combine.h>

namespace facebook::react {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,12 @@
#include <optional>
#include <vector>

#include <React/Graphics.h>
#include <React/RendererCore.h>
#include <React/Utils.h>
#include <React/View.h>
#include <folly/dynamic.h>
#include <react/renderer/attributedstring/primitives.h>
#include <react/renderer/components/view/AccessibilityPrimitives.h>
#include <react/renderer/core/LayoutPrimitives.h>
#include <react/renderer/core/ReactPrimitives.h>
#include <react/renderer/debug/DebugStringConvertible.h>
#include <react/renderer/graphics/Color.h>
#include <react/renderer/graphics/Float.h>
#include <react/renderer/graphics/Size.h>
#include <react/utils/hash_combine.h>

namespace facebook::react {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,20 @@

#include <react/cxxstableapi/FrameworksGuard.h>

#include <react/debug/react_native_expect.h>
#include <React/CSS.h>
#include <React/Debug.h>
#include <React/RendererCore.h>
#include <React/View.h>
#include <react/featureflags/ReactNativePublicFeatureFlags.h>
#include <react/renderer/attributedstring/AttributedString.h>
#include <react/renderer/attributedstring/ParagraphAttributes.h>
#include <react/renderer/attributedstring/TextAttributes.h>
#include <react/renderer/attributedstring/conversions.h>
#include <react/renderer/attributedstring/primitives.h>
#include <react/renderer/components/view/accessibilityPropsConversions.h>
#include <react/renderer/core/LayoutableShadowNode.h>
#include <react/renderer/core/PropsParserContext.h>
#include <react/renderer/core/ShadowNode.h>
#include <react/renderer/core/conversions.h>
#include <react/renderer/core/graphicsConversions.h>
#include <react/renderer/core/propsConversions.h>
#include <react/renderer/css/CSSFontVariant.h>
#include <react/renderer/css/CSSValueParser.h>
#include <unordered_map>

#ifdef RN_SERIALIZABLE_STATE
#include <React/MapBuffer.h>
#include <folly/json.h>
#include <react/renderer/mapbuffer/MapBuffer.h>
#include <react/renderer/mapbuffer/MapBufferBuilder.h>
#endif

#include <glog/logging.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

#include <react/cxxstableapi/UmbrellaGuard.h>

#include <memory>

#include <react/renderer/components/image/ImageShadowNode.h>
#include <react/renderer/core/ConcreteComponentDescriptor.h>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

#include <react/cxxstableapi/UmbrellaGuard.h>

#include <cstdint>

#include <react/renderer/components/view/ViewEventEmitter.h>
#include <react/renderer/imagemanager/primitives.h>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

#include <react/cxxstableapi/UmbrellaGuard.h>

#include <optional>
#include <string>

#include <react/renderer/components/view/ViewProps.h>
#include <react/renderer/core/PropsParserContext.h>
#include <react/renderer/graphics/Color.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

#include <react/cxxstableapi/UmbrellaGuard.h>

#include <memory>

#include <react/renderer/components/image/ImageEventEmitter.h>
#include <react/renderer/components/image/ImageProps.h>
#include <react/renderer/components/image/ImageState.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@

#include <react/cxxstableapi/UmbrellaGuard.h>

#include <memory>
#include <utility>

#include <react/renderer/imagemanager/ImageRequest.h>
#include <react/renderer/imagemanager/ImageRequestParams.h>
#include <react/renderer/imagemanager/primitives.h>

#ifdef ANDROID
#include <folly/dynamic.h>
#include <react/renderer/mapbuffer/MapBuffer.h>
#include <react/renderer/mapbuffer/MapBufferBuilder.h>
#endif

namespace facebook::react {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

#include <react/renderer/components/image/conversions.h>

#include <glog/logging.h>
#include <react/debug/react_native_expect.h>

#include <string>
#include <unordered_map>

namespace facebook::react {

void fromRawValue(
const PropsParserContext& /* context */,
const RawValue& value,
ImageSource& result) {
if (value.hasType<std::string>()) {
result = {
.type = ImageSource::Type::Remote,
.uri = (std::string)value,
};
return;
}

if (value.hasType<std::unordered_map<std::string, RawValue>>()) {
auto items = (std::unordered_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() &&
// The following checks have to be removed after codegen is shipped.
// See T45151459.
items.at("width").hasType<Float>() &&
items.at("height").hasType<Float>()) {
result.size = {
.width = (Float)items.at("width"),
.height = (Float)items.at("height")};
}

if (items.find("scale") != items.end() &&
// The following checks have to be removed after codegen is shipped.
// See T45151459.
items.at("scale").hasType<Float>()) {
result.scale = (Float)items.at("scale");
} else {
result.scale = items.find("deprecated") != items.end() ? 0.0f : 1.0f;
}

if (items.find("url") != items.end() &&
// The following should be removed after codegen is shipped.
// See T45151459.
items.at("url").hasType<std::string>()) {
result.uri = (std::string)items.at("url");
}

if (items.find("uri") != items.end() &&
// The following should be removed after codegen is shipped.
// See T45151459.
items.at("uri").hasType<std::string>()) {
result.uri = (std::string)items.at("uri");
}

if (items.find("bundle") != items.end() &&
// The following should be removed after codegen is shipped.
// See T45151459.
items.at("bundle").hasType<std::string>()) {
result.bundle = (std::string)items.at("bundle");
result.type = ImageSource::Type::Local;
}

if (items.find("headers") != items.end() &&
items.at("headers")
.hasType<std::unordered_map<std::string, std::string>>()) {
auto headers =
(std::unordered_map<std::string, std::string>)items.at("headers");
for (const auto& header : headers) {
result.headers.emplace_back(header);
}
}

if (items.find("body") != items.end() &&
items.at("body").hasType<std::string>()) {
result.body = (std::string)items.at("body");
}

if (items.find("method") != items.end() &&
items.at("method").hasType<std::string>()) {
result.method = (std::string)items.at("method");
}

if (items.find("cache") != items.end() &&
items.at("cache").hasType<std::string>()) {
auto cache = (std::string)items.at("cache");
if (cache == "reload") {
result.cache = ImageSource::CacheStategy::Reload;
} else if (cache == "force-cache") {
result.cache = ImageSource::CacheStategy::ForceCache;
} else if (cache == "only-if-cached") {
result.cache = ImageSource::CacheStategy::OnlyIfCached;
}
}

return;
}

// The following should be removed after codegen is shipped.
// See T45151459.
result = {};
result.type = ImageSource::Type::Invalid;
}

std::string toString(const ImageSource& value) {
return "{uri: " + value.uri + "}";
}

void fromRawValue(
const PropsParserContext& /* context */,
const RawValue& value,
ImageResizeMode& result) {
react_native_expect(value.hasType<std::string>());
if (!value.hasType<std::string>()) {
LOG(ERROR) << "Unsupported ImageResizeMode type";
// "cover" is default in non-Fabric web and iOS
result = ImageResizeMode::Cover;
return;
}

auto stringValue = (std::string)value;
if (stringValue == "cover") {
result = ImageResizeMode::Cover;
} else if (stringValue == "contain") {
result = ImageResizeMode::Contain;
} else if (stringValue == "stretch") {
result = ImageResizeMode::Stretch;
} else if (stringValue == "center") {
result = ImageResizeMode::Center;
} else if (stringValue == "repeat") {
result = ImageResizeMode::Repeat;
} else if (stringValue == "none") {
result = ImageResizeMode::None;
} else {
LOG(ERROR) << "Unsupported ImageResizeMode value: " << stringValue;
react_native_expect(false);
// "cover" is default in non-Fabric web and iOS
result = ImageResizeMode::Cover;
}
}

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";
case ImageResizeMode::None:
return "none";
default:
LOG(ERROR) << "Unsupported ImageResizeMode value: " << (int)value;
react_native_expect(false);
// "cover" is default in non-Fabric web and iOS
return "cover";
}
}

} // namespace facebook::react
Loading
Loading