-
Notifications
You must be signed in to change notification settings - Fork 24.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove dependency on
PropsParserContext
(#42616)
Summary: 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 Differential Revision: D52999204
- Loading branch information
1 parent
5f75e9b
commit b726213
Showing
5 changed files
with
101 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
packages/react-native/ReactCommon/react/renderer/graphics/fromRawValueShared.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 { | ||
typedef SharedColor ( | ||
*parsePlatformColorFn)(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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters