From 6092ce152a3ddff22373cad25dc88eb921c3e809 Mon Sep 17 00:00:00 2001 From: Eric Rozell Date: Mon, 31 Jul 2023 07:58:34 -0700 Subject: [PATCH] More consistent platform for out-of-tree platform extensions 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 --- .../renderer/components/view/ViewEventEmitter.h | 15 +++++++++++++++ .../react/renderer/components/view/ViewProps.h | 15 +++++++++++++++ ...ntEmitter.h => HostPlatformViewEventEmitter.h} | 3 +-- .../{ViewProps.cpp => HostPlatformViewProps.cpp} | 15 ++++++++------- .../view/{ViewProps.h => HostPlatformViewProps.h} | 12 ++++-------- ...ntEmitter.h => HostPlatformViewEventEmitter.h} | 3 +-- .../view/{ViewProps.h => HostPlatformViewProps.h} | 3 +-- 7 files changed, 45 insertions(+), 21 deletions(-) create mode 100644 packages/react-native/ReactCommon/react/renderer/components/view/ViewEventEmitter.h create mode 100644 packages/react-native/ReactCommon/react/renderer/components/view/ViewProps.h rename packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/{ViewEventEmitter.h => HostPlatformViewEventEmitter.h} (73%) rename packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/{ViewProps.cpp => HostPlatformViewProps.cpp} (92%) rename packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/{ViewProps.h => HostPlatformViewProps.h} (88%) rename packages/react-native/ReactCommon/react/renderer/components/view/platform/cxx/react/renderer/components/view/{ViewEventEmitter.h => HostPlatformViewEventEmitter.h} (73%) rename packages/react-native/ReactCommon/react/renderer/components/view/platform/cxx/react/renderer/components/view/{ViewProps.h => HostPlatformViewProps.h} (78%) diff --git a/packages/react-native/ReactCommon/react/renderer/components/view/ViewEventEmitter.h b/packages/react-native/ReactCommon/react/renderer/components/view/ViewEventEmitter.h new file mode 100644 index 00000000000000..2ad0d4e4190505 --- /dev/null +++ b/packages/react-native/ReactCommon/react/renderer/components/view/ViewEventEmitter.h @@ -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 + +namespace facebook::react { +using ViewEventEmitter = HostPlatformViewEventEmitter; +using SharedViewEventEmitter = std::shared_ptr; +} // namespace facebook::react diff --git a/packages/react-native/ReactCommon/react/renderer/components/view/ViewProps.h b/packages/react-native/ReactCommon/react/renderer/components/view/ViewProps.h new file mode 100644 index 00000000000000..f1d3bb0c286bf7 --- /dev/null +++ b/packages/react-native/ReactCommon/react/renderer/components/view/ViewProps.h @@ -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 + +namespace facebook::react { +using ViewProps = HostPlatformViewProps; +using SharedViewProps = std::shared_ptr; +} // namespace facebook::react diff --git a/packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/ViewEventEmitter.h b/packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/HostPlatformViewEventEmitter.h similarity index 73% rename from packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/ViewEventEmitter.h rename to packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/HostPlatformViewEventEmitter.h index 23140c98b561ba..24c9a19a7f4dfc 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/ViewEventEmitter.h +++ b/packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/HostPlatformViewEventEmitter.h @@ -10,6 +10,5 @@ #include namespace facebook::react { -using ViewEventEmitter = BaseViewEventEmitter; -using SharedViewEventEmitter = std::shared_ptr; +using HostPlatformViewEventEmitter = BaseViewEventEmitter; } // namespace facebook::react diff --git a/packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/ViewProps.cpp b/packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/HostPlatformViewProps.cpp similarity index 92% rename from packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/ViewProps.cpp rename to packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/HostPlatformViewProps.cpp index 20f2d5feea3b31..85f74f20a2c45b 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/ViewProps.cpp +++ b/packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/HostPlatformViewProps.cpp @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -#include "ViewProps.h" +#include "HostPlatformViewProps.h" #include @@ -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), @@ -89,7 +89,7 @@ ViewProps::ViewProps( return; \ } -void ViewProps::setProp( +void HostPlatformViewProps::setProp( const PropsParserContext &context, RawPropsPropNameHash hash, const char *propName, @@ -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); @@ -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 diff --git a/packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/ViewProps.h b/packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/HostPlatformViewProps.h similarity index 88% rename from packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/ViewProps.h rename to packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/HostPlatformViewProps.h index 5ebda517aeae40..dd08ff16edf84a 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/ViewProps.h +++ b/packages/react-native/ReactCommon/react/renderer/components/view/platform/android/react/renderer/components/view/HostPlatformViewProps.h @@ -20,16 +20,12 @@ namespace facebook::react { -class ViewProps; - -using SharedViewProps = std::shared_ptr; - -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); diff --git a/packages/react-native/ReactCommon/react/renderer/components/view/platform/cxx/react/renderer/components/view/ViewEventEmitter.h b/packages/react-native/ReactCommon/react/renderer/components/view/platform/cxx/react/renderer/components/view/HostPlatformViewEventEmitter.h similarity index 73% rename from packages/react-native/ReactCommon/react/renderer/components/view/platform/cxx/react/renderer/components/view/ViewEventEmitter.h rename to packages/react-native/ReactCommon/react/renderer/components/view/platform/cxx/react/renderer/components/view/HostPlatformViewEventEmitter.h index 23140c98b561ba..24c9a19a7f4dfc 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/view/platform/cxx/react/renderer/components/view/ViewEventEmitter.h +++ b/packages/react-native/ReactCommon/react/renderer/components/view/platform/cxx/react/renderer/components/view/HostPlatformViewEventEmitter.h @@ -10,6 +10,5 @@ #include namespace facebook::react { -using ViewEventEmitter = BaseViewEventEmitter; -using SharedViewEventEmitter = std::shared_ptr; +using HostPlatformViewEventEmitter = BaseViewEventEmitter; } // namespace facebook::react diff --git a/packages/react-native/ReactCommon/react/renderer/components/view/platform/cxx/react/renderer/components/view/ViewProps.h b/packages/react-native/ReactCommon/react/renderer/components/view/platform/cxx/react/renderer/components/view/HostPlatformViewProps.h similarity index 78% rename from packages/react-native/ReactCommon/react/renderer/components/view/platform/cxx/react/renderer/components/view/ViewProps.h rename to packages/react-native/ReactCommon/react/renderer/components/view/platform/cxx/react/renderer/components/view/HostPlatformViewProps.h index 6e2d465236bcdb..527985d2990214 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/view/platform/cxx/react/renderer/components/view/ViewProps.h +++ b/packages/react-native/ReactCommon/react/renderer/components/view/platform/cxx/react/renderer/components/view/HostPlatformViewProps.h @@ -10,6 +10,5 @@ #include namespace facebook::react { -using ViewProps = BaseViewProps; -using SharedViewProps = std::shared_ptr; +using HostPlatformViewProps = BaseViewProps; } // namespace facebook::react