-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement PlatformColor in Fabric Android
Summary: This diff implements PlatformColor in Fabric Android changelog: [internal] internal Reviewed By: JoshuaGross Differential Revision: D29841461 fbshipit-source-id: 63a523626b021c634bc399e749b639b55730391a
- Loading branch information
1 parent
8066bc9
commit cdce14f
Showing
8 changed files
with
169 additions
and
16 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
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
69 changes: 69 additions & 0 deletions
69
...on/react/renderer/graphics/platform/android/react/renderer/graphics/PlatformColorParser.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,69 @@ | ||
/* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <fbjni/fbjni.h> | ||
#include <react/jni/ReadableNativeMap.h> | ||
#include <react/renderer/core/PropsParserContext.h> | ||
#include <react/renderer/core/RawProps.h> | ||
#include <react/renderer/graphics/ColorComponents.h> | ||
|
||
using namespace facebook::jni; | ||
|
||
namespace facebook { | ||
namespace react { | ||
|
||
inline ColorComponents parsePlatformColor( | ||
const PropsParserContext &context, | ||
const RawValue &value) { | ||
ColorComponents colorComponents = {0, 0, 0, 0}; | ||
|
||
if (value.hasType<better::map<std::string, std::vector<std::string>>>()) { | ||
auto map = (better::map<std::string, std::vector<std::string>>)value; | ||
auto resourcePaths = map["resource_paths"]; | ||
auto dynamicResourcePaths = folly::dynamic::array(); | ||
for (const auto &resourcePath : resourcePaths) { | ||
dynamicResourcePaths.push_back(resourcePath); | ||
} | ||
folly::dynamic dynamicPlatformColor = folly::dynamic::object(); | ||
dynamicPlatformColor["resource_paths"] = dynamicResourcePaths; | ||
|
||
auto fabricUIManager = | ||
context.contextContainer.at<jni::global_ref<jobject>>( | ||
"FabricUIManager"); | ||
|
||
static auto getColorFromJava = | ||
facebook::jni::findClassStatic( | ||
"com/facebook/react/fabric/FabricUIManager") | ||
->getMethod<jint(jint, ReadableMap::javaobject)>("getColor"); | ||
|
||
local_ref<ReadableNativeMap::javaobject> dynamicPlatformColorRNM = | ||
ReadableNativeMap::newObjectCxxArgs(dynamicPlatformColor); | ||
local_ref<ReadableMap::javaobject> dynamicPlatformColorRM = | ||
make_local(reinterpret_cast<ReadableMap::javaobject>( | ||
dynamicPlatformColorRNM.get())); | ||
|
||
auto color = getColorFromJava( | ||
fabricUIManager, context.surfaceId, dynamicPlatformColorRM.get()); | ||
|
||
dynamicPlatformColorRM.reset(); | ||
dynamicPlatformColorRNM.reset(); | ||
|
||
auto argb = (int64_t)color; | ||
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; | ||
} | ||
|
||
return colorComponents; | ||
} | ||
|
||
} // namespace react | ||
} // namespace facebook |
29 changes: 29 additions & 0 deletions
29
...Common/react/renderer/graphics/platform/cxx/react/renderer/graphics/PlatformColorParser.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,29 @@ | ||
/* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <react/renderer/core/PropsParserContext.h> | ||
#include <react/renderer/core/RawProps.h> | ||
#include <react/renderer/graphics/ColorComponents.h> | ||
|
||
namespace facebook { | ||
namespace react { | ||
|
||
inline ColorComponents parsePlatformColor( | ||
const PropsParserContext &context, | ||
const RawValue &value) { | ||
float alpha = 0; | ||
float red = 0; | ||
float green = 0; | ||
float blue = 0; | ||
|
||
return {red, green, blue, alpha}; | ||
} | ||
|
||
} // namespace react | ||
} // namespace facebook |
30 changes: 30 additions & 0 deletions
30
ReactCommon/react/renderer/graphics/platform/ios/PlatformColorParser.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,30 @@ | ||
/* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <react/renderer/core/PropsParserContext.h> | ||
#include <react/renderer/core/RawProps.h> | ||
#include <react/renderer/graphics/ColorComponents.h> | ||
|
||
namespace facebook { | ||
namespace react { | ||
|
||
inline ColorComponents parsePlatformColor( | ||
const PropsParserContext &context, | ||
const RawValue &value) { | ||
// TODO T87791134: implement parsing of PlatformColor for iOS | ||
float alpha = 0; | ||
float red = 0; | ||
float green = 0; | ||
float blue = 0; | ||
|
||
return {red, green, blue, alpha}; | ||
} | ||
|
||
} // namespace react | ||
} // namespace facebook |
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