Skip to content

Commit

Permalink
Abstract underlying Color implementation
Browse files Browse the repository at this point in the history
Summary:
On other platforms (e.g., react-native-windows), it's possible that platform colors may not be efficiently represented as int32_t values. In the case of react-native-windows, Color can either be an ARGB value or a list of fallback strings for platform colors.

This change should decouple how platforms represent color values, allowing them to manage how they are used at the point they are used.

## Changelog:
[General] [Added] - Support customization of underlying Color representation in out-of-tree platforms

Differential Revision: D47873465

fbshipit-source-id: 8715b3061f4280e118fb6e39971d604137003d07
  • Loading branch information
rozele authored and facebook-github-bot committed Jul 28, 2023
1 parent 4721561 commit 205ae72
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@
#include <limits>

#include <react/renderer/graphics/ColorComponents.h>
#include <react/renderer/graphics/HostPlatformColor.h>

namespace facebook::react {

using Color = int32_t;

/*
* On Android, a color can be represented as 32 bits integer, so there is no
* need to instantiate complex color objects and then pass them as shared
* pointers. Hense instead of using shared_ptr, we use a simple wrapper class
* which provides a pointer-like interface.
* which provides a pointer-like interface. On other platforms, colors may be
* represented by more complex objects that cannot be represented as 32-bits
* integers, so we hide the implementation detail in HostPlatformColor.h.
*/
class SharedColor {
public:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* 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.
*/

#pragma once

namespace facebook::react {

using Color = int32_t;

} // namespace facebook::react
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* 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.
*/

#pragma once

namespace facebook::react {

using Color = int32_t;

} // namespace facebook::react
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* 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.
*/

#pragma once

namespace facebook::react {

using Color = int32_t;

} // namespace facebook::react

0 comments on commit 205ae72

Please sign in to comment.