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
15 changes: 12 additions & 3 deletions packages/react-native/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -288,21 +288,29 @@ let reactJsErrorHandler = RNTarget(
dependencies: [.reactNativeDependencies, .jsi, .reactFeatureFlags, .reactDebug, .reactTurboModuleBridging]
)

/// React-renderercss.podspec
let reactRendererCss = RNTarget(
name: .reactRendererCss,
path: "ReactCommon/react/renderer/css",
excludedPaths: ["tests"],
dependencies: [.reactNativeDependencies, .reactDebug, .reactUtils]
)

/// React-graphicsApple
/// This represents the React-graphicsApple BUCK module
let reactGraphicsApple = RNTarget(
name: .reactGraphicsApple,
path: "ReactCommon/react/renderer/graphics/platform/ios",
linkedFrameworks: ["UIKit", "CoreGraphics"],
dependencies: [.reactDebug, .jsi, .reactUtils, .reactNativeDependencies]
dependencies: [.reactDebug, .jsi, .reactUtils, .reactNativeDependencies, .reactRendererCss]
)

/// React-graphics.podspec
let reactGraphics = RNTarget(
name: .reactGraphics,
path: "ReactCommon/react/renderer/graphics",
excludedPaths: ["platform", "tests"],
dependencies: [.reactNativeDependencies, .jsi, .reactJsiExecutor, .reactRendererDebug, .reactUtils, .reactGraphicsApple]
dependencies: [.reactNativeDependencies, .jsi, .reactJsiExecutor, .reactRendererDebug, .reactUtils, .reactGraphicsApple, .reactRendererCss]
)

/// ReactCommon.podspec
Expand Down Expand Up @@ -492,7 +500,7 @@ let reactFabric = RNTarget(
"observers/resize/tests",
"scheduler/tests",
],
dependencies: [.reactNativeDependencies, .reactJsiExecutor, .rctTypesafety, .reactTurboModuleCore, .jsi, .logger, .reactDebug, .reactFeatureFlags, .reactUtils, .reactRuntimeScheduler, .reactCxxReact, .reactRendererDebug, .reactGraphics, .yoga, .reactJsInspectorTracing],
dependencies: [.reactNativeDependencies, .reactJsiExecutor, .rctTypesafety, .reactTurboModuleCore, .jsi, .logger, .reactDebug, .reactFeatureFlags, .reactUtils, .reactRuntimeScheduler, .reactCxxReact, .reactRendererDebug, .reactGraphics, .reactRendererCss, .yoga, .reactJsInspectorTracing],
sources: ["animated", "animationbackend", "animations", "attributedstring", "core", "componentregistry", "componentregistry/native", "components/root", "components/view", "components/view/platform/cxx", "components/scrollview", "components/scrollview/platform/cxx", "components/scrollview/platform/ios", "components/legacyviewmanagerinterop", "components/legacyviewmanagerinterop/platform/ios", "dom", "scheduler", "mounting", "observers/events", "observers/intersection", "observers/mutation", "observers/resize", "telemetry", "consistency", "leakchecker", "uimanager", "uimanager/consistency", "viewtransition"]
)

Expand Down Expand Up @@ -714,6 +722,7 @@ let targets = [
reactPerformanceTimeline,
reactRuntimeScheduler,
rctTypesafety,
reactRendererCss,
reactGraphics,
reactGraphicsApple,
reactImageManager,
Expand Down
2 changes: 2 additions & 0 deletions packages/react-native/ReactCommon/React-Fabric.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ Pod::Spec.new do |s|
end

s.subspec "attributedstring" do |ss|
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 Expand Up @@ -224,6 +225,7 @@ Pod::Spec.new do |s|
end

ss.subspec "intersection" do |sss|
sss.dependency "React-renderercss"
sss.source_files = podspec_sources("react/renderer/observers/intersection/**/*.{m,mm,cpp,h}", "react/renderer/observers/intersection/**/*.h")
sss.exclude_files = "react/renderer/observers/intersection/tests"
sss.header_dir = "react/renderer/observers/intersection"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ target_link_libraries(react_renderer_attributedstring
react_debug
rrc_view
react_renderer_core
react_renderer_css
react_renderer_debug
react_renderer_graphics
react_renderer_mapbuffer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,17 @@ target_include_directories(react_renderer_graphics INTERFACE ${REACT_COMMON_DIR}

react_native_android_selector(fbjni fbjni "")
target_link_libraries(react_renderer_graphics
glog
${fbjni}
folly_runtime
react_cxxstableapi
react_debug
react_renderer_debug
react_utils
PUBLIC
${fbjni}
folly_runtime
react_cxxstableapi
react_renderer_debug
react_utils
PRIVATE
glog
react_debug
react_featureflags
react_renderer_css
)
target_compile_reactnative_options(react_renderer_graphics PRIVATE)
target_compile_options(react_renderer_graphics PRIVATE -Wpedantic)
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Pod::Spec.new do |s|
s.dependency "React-utils"
s.dependency "React-rendererdebug"
s.dependency "React-cxxstableapi"
s.dependency "React-renderercss"

depend_on_js_engine(s)
add_rn_third_party_dependencies(s)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* 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/graphics/fromRawValueShared.h>

#include <react/debug/react_native_expect.h>
#include <react/featureflags/ReactNativeFeatureFlags.h>
#include <react/renderer/css/CSSColor.h>
#include <react/renderer/css/CSSValueParser.h>

namespace facebook::react {

void fromRawValueShared(
const ContextContainer& contextContainer,
int32_t surfaceId,
const RawValue& value,
SharedColor& result,
parsePlatformColorFn parsePlatformColor) {
ColorComponents colorComponents = {
.red = 0, .green = 0, .blue = 0, .alpha = 0};

if (ReactNativeFeatureFlags::enableNativeCSSParsing() &&
value.hasType<std::string>()) {
auto cssColor = parseCSSProperty<CSSColor>((std::string)value);
if (std::holds_alternative<CSSColor>(cssColor)) {
auto c = std::get<CSSColor>(cssColor);
result = hostPlatformColorFromRGBA(c.r, c.g, c.b, c.a);
return;
}
// Unparseable string - fall through to parsePlatformColor
result = parsePlatformColor(contextContainer, surfaceId, value);
} else if (value.hasType<int>()) {
auto argb = (int64_t)value;
auto ratio = 255.f;
colorComponents.alpha = ((argb >> 24) & 0xFF) / ratio;
colorComponents.red = ((argb >> 16) & 0xFF) / ratio;
colorComponents.green = ((argb >> 8) & 0xFF) / ratio;
colorComponents.blue = (argb & 0xFF) / ratio;

result = colorFromComponents(colorComponents);
} else if (value.hasType<std::vector<float>>()) {
auto items = (std::vector<float>)value;
auto length = items.size();
react_native_expect(length == 3 || length == 4);
colorComponents.red = items.at(0);
colorComponents.green = items.at(1);
colorComponents.blue = items.at(2);
colorComponents.alpha = length == 4 ? items.at(3) : 1.0f;

result = colorFromComponents(colorComponents);
} else {
if (value.hasType<std::unordered_map<std::string, RawValue>>()) {
const auto& items = (std::unordered_map<std::string, RawValue>)value;
if (items.find("space") != items.end()) {
colorComponents.red = (float)items.at("r");
colorComponents.green = (float)items.at("g");
colorComponents.blue = (float)items.at("b");
colorComponents.alpha = (float)items.at("a");
colorComponents.colorSpace = getDefaultColorSpace();
std::string space = (std::string)items.at("space");
if (space == "display-p3") {
colorComponents.colorSpace = ColorSpace::DisplayP3;
} else if (space == "srgb") {
colorComponents.colorSpace = ColorSpace::sRGB;
}
result = colorFromComponents(colorComponents);
return;
}
}
result = parsePlatformColor(contextContainer, surfaceId, value);
}
}

} // namespace facebook::react
Original file line number Diff line number Diff line change
Expand Up @@ -8,74 +8,19 @@
#pragma once

#include <react/cxxstableapi/UmbrellaGuard.h>
#include <react/debug/react_native_expect.h>
#include <react/featureflags/ReactNativePublicFeatureFlags.h>
#include <react/renderer/core/RawValue.h>
#include <react/renderer/css/CSSColor.h>
#include <react/renderer/css/CSSValueParser.h>
#include <react/renderer/graphics/Color.h>
#include <react/utils/ContextContainer.h>

namespace facebook::react {

using parsePlatformColorFn = SharedColor (*)(const ContextContainer &, int32_t, const RawValue &);

inline void fromRawValueShared(
void fromRawValueShared(
const ContextContainer &contextContainer,
int32_t surfaceId,
const RawValue &value,
SharedColor &result,
parsePlatformColorFn parsePlatformColor)
{
ColorComponents colorComponents = {0, 0, 0, 0};

if (ReactNativeFeatureFlags_DO_NOT_USE::enableNativeCSSParsing() && value.hasType<std::string>()) {
auto cssColor = parseCSSProperty<CSSColor>((std::string)value);
if (std::holds_alternative<CSSColor>(cssColor)) {
auto c = std::get<CSSColor>(cssColor);
result = hostPlatformColorFromRGBA(c.r, c.g, c.b, c.a);
return;
}
// Unparseable string - fall through to parsePlatformColor
result = parsePlatformColor(contextContainer, surfaceId, value);
} else if (value.hasType<int>()) {
auto argb = (int64_t)value;
auto ratio = 255.f;
colorComponents.alpha = ((argb >> 24) & 0xFF) / ratio;
colorComponents.red = ((argb >> 16) & 0xFF) / ratio;
colorComponents.green = ((argb >> 8) & 0xFF) / ratio;
colorComponents.blue = (argb & 0xFF) / ratio;

result = colorFromComponents(colorComponents);
} else if (value.hasType<std::vector<float>>()) {
auto items = (std::vector<float>)value;
auto length = items.size();
react_native_expect(length == 3 || length == 4);
colorComponents.red = items.at(0);
colorComponents.green = items.at(1);
colorComponents.blue = items.at(2);
colorComponents.alpha = length == 4 ? items.at(3) : 1.0f;
parsePlatformColorFn parsePlatformColor);

result = colorFromComponents(colorComponents);
} else {
if (value.hasType<std::unordered_map<std::string, RawValue>>()) {
const auto &items = (std::unordered_map<std::string, RawValue>)value;
if (items.find("space") != items.end()) {
colorComponents.red = (float)items.at("r");
colorComponents.green = (float)items.at("g");
colorComponents.blue = (float)items.at("b");
colorComponents.alpha = (float)items.at("a");
colorComponents.colorSpace = getDefaultColorSpace();
std::string space = (std::string)items.at("space");
if (space == "display-p3") {
colorComponents.colorSpace = ColorSpace::DisplayP3;
} else if (space == "srgb") {
colorComponents.colorSpace = ColorSpace::sRGB;
}
result = colorFromComponents(colorComponents);
return;
}
}
result = parsePlatformColor(contextContainer, surfaceId, value);
}
}
} // namespace facebook::react
Loading
Loading