Skip to content
Closed
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
3 changes: 3 additions & 0 deletions packages/react-native/ReactCommon/React-Fabric.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ Pod::Spec.new do |s|
end

s.subspec "attributedstring" do |ss|
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 @@ -12,6 +12,7 @@
#import <objc/runtime.h>
#import <react/renderer/graphics/RCTPlatformColorUtils.h>
#import <react/utils/ManagedObjectWrapper.h>
#import <cmath>
#import <string>

using namespace facebook::react;
Expand Down Expand Up @@ -86,9 +87,10 @@ bool UIColorIsP3ColorSpace(const std::shared_ptr<void> &uiColor)
int32_t ColorFromColorComponents(const facebook::react::ColorComponents &components)
{
float ratio = 255;
auto color = ((int32_t)round((float)components.alpha * ratio) & 0xff) << 24 |
((int)round((float)components.red * ratio) & 0xff) << 16 |
((int)round((float)components.green * ratio) & 0xff) << 8 | ((int)round((float)components.blue * ratio) & 0xff);
auto color = ((int32_t)std::round((float)components.alpha * ratio) & 0xff) << 24 |
((int)std::round((float)components.red * ratio) & 0xff) << 16 |
((int)std::round((float)components.green * ratio) & 0xff) << 8 |
((int)std::round((float)components.blue * ratio) & 0xff);
return color;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* 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/imagemanager/primitives.h>

#if RN_DEBUG_STRING_CONVERTIBLE
#include <react/renderer/debug/debugStringConvertibleUtils.h>
#endif

namespace facebook::react {

#if RN_DEBUG_STRING_CONVERTIBLE
SharedDebugStringConvertibleList ImageSource::getDebugProps(
const std::string& prefix) const {
ImageSource imageSource{};

SharedDebugStringConvertibleList headersList;
for (const auto& header : headers) {
headersList.push_back(debugStringConvertibleItem(
prefix + "-header-" + header.first, header.second));
}

return headersList +
SharedDebugStringConvertibleList{
debugStringConvertibleItem(
prefix + "-type", toString(type), toString(imageSource.type)),
debugStringConvertibleItem(prefix + "-uri", uri, imageSource.uri),
debugStringConvertibleItem(
prefix + "-bundle", bundle, imageSource.bundle),
debugStringConvertibleItem(
prefix + "-scale", scale, imageSource.scale),
debugStringConvertibleItem(
prefix + "-size",
react::toString(size),
react::toString(imageSource.size)),
debugStringConvertibleItem(prefix + "-body", body, imageSource.body),
debugStringConvertibleItem(
prefix + "-method", method, imageSource.method),
debugStringConvertibleItem(
prefix + "-cache", toString(cache), toString(imageSource.cache)),
};
}
#endif

} // namespace facebook::react
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
#include <React/Graphics.h>
#include <React/RendererCore.h>
#include <React/RendererDebug.h>
#include <react/renderer/debug/debugStringConvertibleUtils.h>
#include <react/renderer/debug/DebugStringConvertible.h>
#include <react/renderer/debug/flags.h>

namespace facebook::react {

Expand Down Expand Up @@ -96,27 +97,7 @@ class ImageSource {
#endif

#if RN_DEBUG_STRING_CONVERTIBLE
SharedDebugStringConvertibleList getDebugProps(const std::string &prefix) const
{
ImageSource imageSource{};

SharedDebugStringConvertibleList headersList;
for (const auto &header : headers) {
headersList.push_back(debugStringConvertibleItem(prefix + "-header-" + header.first, header.second));
}

return headersList +
SharedDebugStringConvertibleList{
debugStringConvertibleItem(prefix + "-type", toString(type), toString(imageSource.type)),
debugStringConvertibleItem(prefix + "-uri", uri, imageSource.uri),
debugStringConvertibleItem(prefix + "-bundle", bundle, imageSource.bundle),
debugStringConvertibleItem(prefix + "-scale", scale, imageSource.scale),
debugStringConvertibleItem(prefix + "-size", react::toString(size), react::toString(imageSource.size)),
debugStringConvertibleItem(prefix + "-body", body, imageSource.body),
debugStringConvertibleItem(prefix + "-method", method, imageSource.method),
debugStringConvertibleItem(prefix + "-cache", toString(cache), toString(imageSource.cache)),
};
}
SharedDebugStringConvertibleList getDebugProps(const std::string &prefix) const;

std::string toString(const Type &typeValue) const
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#import "RCTTextLayoutManager.h"

#import <array>
#import <cmath>

#import "RCTAttributedTextUtils.h"

Expand Down Expand Up @@ -186,8 +187,8 @@ - (void)drawAttributedString:(AttributedString)attributedString
// remains visible at small sizes and proportionate at
// large ones. ~`fontSize / 12` plus a 1.5pt floor.
CGFloat thickness = MAX(fontSize / 12.0f, 1.5f);
CGFloat wavyWavelength = 1.0f + 2.0f * round(2.0f * thickness + 0.5f);
CGFloat wavyCpDistance = 0.5f + round(3.0f * thickness + 0.5f);
CGFloat wavyWavelength = 1.0f + 2.0f * std::round(2.0f * thickness + 0.5f);
CGFloat wavyCpDistance = 0.5f + std::round(3.0f * thickness + 0.5f);

NSRange targetGlyphRange = [layoutManager glyphRangeForCharacterRange:attrRange
actualCharacterRange:nullptr];
Expand Down
Loading