Skip to content

Commit

Permalink
More consistent platform for out-of-tree platform extensions
Browse files Browse the repository at this point in the history
Summary:
This change consolidates the pattern for setting up out-of-tree platform options for core classes like ViewProps and ViewEventEmitter. A similar pattern was used for Touch.h. As we move towards documenting how to build an out-of-tree platform, it would be nice to specify a set of HostPlatformX classes that need to be implemented and made resolvable from specific header paths.

At this point, there is:
- HostPlatformViewProps
- HostPlatformViewEventEmitter
- HostPlatformTouch
- HostPlatformColor

The other benefit of this pattern is to DRY helper aliases like SharedViewEventEmitter and SharedViewProps.

## Changelog:
[General] [Added] - Use more consistent pattern for out-of-tree platform Fabric C++ class extensions

Differential Revision: D47917598

fbshipit-source-id: 0281a859d2758a0ad4a554016dfcb717108d3dc8
  • Loading branch information
rozele authored and facebook-github-bot committed Jul 31, 2023
1 parent 87c5963 commit 6092ce1
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* 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

#include <react/renderer/components/view/HostPlatformViewEventEmitter.h>

namespace facebook::react {
using ViewEventEmitter = HostPlatformViewEventEmitter;
using SharedViewEventEmitter = std::shared_ptr<const ViewEventEmitter>;
} // namespace facebook::react
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* 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

#include <react/renderer/components/view/HostPlatformViewProps.h>

namespace facebook::react {
using ViewProps = HostPlatformViewProps;
using SharedViewProps = std::shared_ptr<ViewProps const>;
} // namespace facebook::react
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@
#include <react/renderer/components/view/BaseViewEventEmitter.h>

namespace facebook::react {
using ViewEventEmitter = BaseViewEventEmitter;
using SharedViewEventEmitter = std::shared_ptr<const ViewEventEmitter>;
using HostPlatformViewEventEmitter = BaseViewEventEmitter;
} // namespace facebook::react
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

#include "ViewProps.h"
#include "HostPlatformViewProps.h"

#include <algorithm>

Expand All @@ -17,9 +17,9 @@

namespace facebook::react {

ViewProps::ViewProps(
HostPlatformViewProps::HostPlatformViewProps(
const PropsParserContext &context,
ViewProps const &sourceProps,
HostPlatformViewProps const &sourceProps,
RawProps const &rawProps,
bool shouldSetRawProps)
: BaseViewProps(context, sourceProps, rawProps, shouldSetRawProps),
Expand Down Expand Up @@ -89,7 +89,7 @@ ViewProps::ViewProps(
return; \
}

void ViewProps::setProp(
void HostPlatformViewProps::setProp(
const PropsParserContext &context,
RawPropsPropNameHash hash,
const char *propName,
Expand All @@ -99,7 +99,7 @@ void ViewProps::setProp(
// reuse the same values.
BaseViewProps::setProp(context, hash, propName, value);

static auto defaults = ViewProps{};
static auto defaults = HostPlatformViewProps{};

switch (hash) {
RAW_SET_PROP_SWITCH_CASE_BASIC(elevation);
Expand All @@ -112,12 +112,13 @@ void ViewProps::setProp(
}
}

bool ViewProps::getProbablyMoreHorizontalThanVertical_DEPRECATED() const {
bool HostPlatformViewProps::getProbablyMoreHorizontalThanVertical_DEPRECATED()
const {
return yogaStyle.flexDirection() == YGFlexDirectionRow;
}

#if RN_DEBUG_STRING_CONVERTIBLE
SharedDebugStringConvertibleList ViewProps::getDebugProps() const {
SharedDebugStringConvertibleList HostPlatformViewProps::getDebugProps() const {
return BaseViewProps::getDebugProps();
}
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,12 @@

namespace facebook::react {

class ViewProps;

using SharedViewProps = std::shared_ptr<ViewProps const>;

class ViewProps : public BaseViewProps {
class HostPlatformViewProps : public BaseViewProps {
public:
ViewProps() = default;
ViewProps(
HostPlatformViewProps() = default;
HostPlatformViewProps(
const PropsParserContext &context,
ViewProps const &sourceProps,
HostPlatformViewProps const &sourceProps,
RawProps const &rawProps,
bool shouldSetRawProps = true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@
#include <react/renderer/components/view/BaseViewEventEmitter.h>

namespace facebook::react {
using ViewEventEmitter = BaseViewEventEmitter;
using SharedViewEventEmitter = std::shared_ptr<const ViewEventEmitter>;
using HostPlatformViewEventEmitter = BaseViewEventEmitter;
} // namespace facebook::react
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@
#include <react/renderer/components/view/BaseViewProps.h>

namespace facebook::react {
using ViewProps = BaseViewProps;
using SharedViewProps = std::shared_ptr<ViewProps const>;
using HostPlatformViewProps = BaseViewProps;
} // namespace facebook::react

0 comments on commit 6092ce1

Please sign in to comment.