mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Remove dependency on PropsParserContext (#42616)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/42616 PropsParserContext is an entity in Core with a lot of baggage. We used it in graphics only to access the `surfaceId` and the `contextContainer`. We don't need to bring to graphics the whole dependencies of core due to these two parts. This change break the dependency by passing along only the elements that we actually need. ## Changelog [Internal] - break dependencies between graphics and core by removing the include of the PropsParserContext Reviewed By: sammy-SC Differential Revision: D52999204 fbshipit-source-id: a4b92fc11238f5caa63e39a6e286273ab671c8de
This commit is contained in:
committed by
Facebook GitHub Bot
parent
5d559c1ff4
commit
5bf5f4b150
@@ -14,6 +14,7 @@
|
||||
#include <react/renderer/core/PropsParserContext.h>
|
||||
#include <react/renderer/core/RawProps.h>
|
||||
#include <react/renderer/graphics/Color.h>
|
||||
#include <react/renderer/graphics/Float.h>
|
||||
#include <react/renderer/graphics/PlatformColorParser.h>
|
||||
#include <react/renderer/graphics/Point.h>
|
||||
#include <react/renderer/graphics/Rect.h>
|
||||
@@ -29,29 +30,7 @@ inline void fromRawValue(
|
||||
const PropsParserContext& context,
|
||||
const RawValue& value,
|
||||
SharedColor& result) {
|
||||
ColorComponents colorComponents = {0, 0, 0, 0};
|
||||
|
||||
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;
|
||||
} 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;
|
||||
} else {
|
||||
result = parsePlatformColor(context, value);
|
||||
return;
|
||||
}
|
||||
|
||||
result = colorFromComponents(colorComponents);
|
||||
fromRawValue(context.contextContainer, context.surfaceId, value, result);
|
||||
}
|
||||
|
||||
#ifdef ANDROID
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* 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/debug/react_native_expect.h>
|
||||
#include <react/renderer/core/RawValue.h>
|
||||
#include <react/renderer/graphics/Color.h>
|
||||
#include <react/utils/ContextContainer.h>
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace facebook::react {
|
||||
using parsePlatformColorFn =
|
||||
SharedColor (*)(const ContextContainer&, int32_t, const RawValue&);
|
||||
|
||||
inline void fromRawValueShared(
|
||||
const ContextContainer& contextContainer,
|
||||
int32_t surfaceId,
|
||||
const RawValue& value,
|
||||
SharedColor& result,
|
||||
parsePlatformColorFn parsePlatformColor) {
|
||||
ColorComponents colorComponents = {0, 0, 0, 0};
|
||||
|
||||
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 {
|
||||
result = parsePlatformColor(contextContainer, surfaceId, value);
|
||||
}
|
||||
}
|
||||
} // namespace facebook::react
|
||||
+18
-7
@@ -8,23 +8,25 @@
|
||||
#pragma once
|
||||
|
||||
#include <fbjni/fbjni.h>
|
||||
#include <react/renderer/core/PropsParserContext.h>
|
||||
#include <react/renderer/core/RawProps.h>
|
||||
#include <react/debug/react_native_expect.h>
|
||||
#include <react/renderer/core/RawValue.h>
|
||||
#include <react/renderer/graphics/Color.h>
|
||||
#include <react/renderer/graphics/fromRawValueShared.h>
|
||||
#include <react/utils/ContextContainer.h>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace facebook::react {
|
||||
|
||||
inline SharedColor parsePlatformColor(
|
||||
const PropsParserContext& context,
|
||||
const ContextContainer& contextContainer,
|
||||
int32_t surfaceId,
|
||||
const RawValue& value) {
|
||||
ColorComponents colorComponents = {0, 0, 0, 0};
|
||||
|
||||
if (value.hasType<
|
||||
std::unordered_map<std::string, std::vector<std::string>>>()) {
|
||||
const auto& fabricUIManager =
|
||||
context.contextContainer.at<jni::global_ref<jobject>>(
|
||||
"FabricUIManager");
|
||||
contextContainer.at<jni::global_ref<jobject>>("FabricUIManager");
|
||||
static auto getColorFromJava =
|
||||
fabricUIManager->getClass()
|
||||
->getMethod<jint(jint, jni::JArrayClass<jni::JString>)>("getColor");
|
||||
@@ -37,8 +39,8 @@ inline SharedColor parsePlatformColor(
|
||||
for (int i = 0; i < resourcePaths.size(); i++) {
|
||||
javaResourcePaths->setElement(i, *jni::make_jstring(resourcePaths[i]));
|
||||
}
|
||||
auto color = getColorFromJava(
|
||||
fabricUIManager, context.surfaceId, *javaResourcePaths);
|
||||
auto color =
|
||||
getColorFromJava(fabricUIManager, surfaceId, *javaResourcePaths);
|
||||
|
||||
auto argb = (int64_t)color;
|
||||
auto ratio = 255.f;
|
||||
@@ -51,4 +53,13 @@ inline SharedColor parsePlatformColor(
|
||||
return {colorFromComponents(colorComponents)};
|
||||
}
|
||||
|
||||
inline void fromRawValue(
|
||||
const ContextContainer& contextContainer,
|
||||
int32_t surfaceId,
|
||||
const RawValue& value,
|
||||
SharedColor& result) {
|
||||
fromRawValueShared(
|
||||
contextContainer, surfaceId, value, result, parsePlatformColor);
|
||||
}
|
||||
|
||||
} // namespace facebook::react
|
||||
|
||||
+16
-4
@@ -7,15 +7,18 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <react/renderer/core/PropsParserContext.h>
|
||||
#include <react/renderer/core/RawProps.h>
|
||||
#include <react/debug/react_native_expect.h>
|
||||
#include <react/renderer/core/RawValue.h>
|
||||
#include <react/renderer/graphics/Color.h>
|
||||
#include <react/renderer/graphics/fromRawValueShared.h>
|
||||
#include <react/utils/ContextContainer.h>
|
||||
|
||||
namespace facebook::react {
|
||||
|
||||
inline SharedColor parsePlatformColor(
|
||||
const PropsParserContext& context,
|
||||
const RawValue& value) {
|
||||
const ContextContainer& /*contextContainer*/,
|
||||
int32_t /*surfaceId*/,
|
||||
const RawValue& /*value*/) {
|
||||
float alpha = 0;
|
||||
float red = 0;
|
||||
float green = 0;
|
||||
@@ -24,4 +27,13 @@ inline SharedColor parsePlatformColor(
|
||||
return {colorFromComponents({red, green, blue, alpha})};
|
||||
}
|
||||
|
||||
inline void fromRawValue(
|
||||
const ContextContainer& contextContainer,
|
||||
int32_t surfaceId,
|
||||
const RawValue& value,
|
||||
SharedColor& result) {
|
||||
fromRawValueShared(
|
||||
contextContainer, surfaceId, value, result, parsePlatformColor);
|
||||
}
|
||||
|
||||
} // namespace facebook::react
|
||||
|
||||
+15
-3
@@ -7,16 +7,19 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <react/renderer/core/PropsParserContext.h>
|
||||
#include <react/renderer/core/RawProps.h>
|
||||
#include <react/debug/react_native_expect.h>
|
||||
#include <react/renderer/core/rawValue.h>
|
||||
#include <react/renderer/graphics/Color.h>
|
||||
#include <react/renderer/graphics/RCTPlatformColorUtils.h>
|
||||
#include <react/renderer/graphics/fromRawValueShared.h>
|
||||
#include <react/utils/ContextContainer.h>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace facebook::react {
|
||||
|
||||
inline SharedColor parsePlatformColor(
|
||||
const PropsParserContext& context,
|
||||
const ContextContainer& /*contextContainer*/,
|
||||
int32_t /*surfaceId*/,
|
||||
const RawValue& value) {
|
||||
if (value.hasType<std::unordered_map<std::string, RawValue>>()) {
|
||||
auto items = (std::unordered_map<std::string, RawValue>)value;
|
||||
@@ -31,4 +34,13 @@ inline SharedColor parsePlatformColor(
|
||||
return clearColor();
|
||||
}
|
||||
|
||||
inline void fromRawValue(
|
||||
const ContextContainer& contextContainer,
|
||||
int32_t surfaceId,
|
||||
const RawValue& value,
|
||||
SharedColor& result) {
|
||||
fromRawValueShared(
|
||||
contextContainer, surfaceId, value, result, parsePlatformColor);
|
||||
}
|
||||
|
||||
} // namespace facebook::react
|
||||
|
||||
Reference in New Issue
Block a user