From 4804e682388e40b82fb4a39fea256b3002a0aba6 Mon Sep 17 00:00:00 2001 From: Joshua Gross Date: Wed, 18 Aug 2021 13:22:00 -0700 Subject: [PATCH] Expose "unreserved" trait constants that can be mapped per-component Summary: Fabric core uses a lot of traits - I am reserving a few more for core usage, and also exposing a few "unreserved" traits. It is recommended that all custom components that do use traits rely on these constants instead of hard-coding any trait values. That way, in the unlikely event that these values change in the future, it will not break components. Changelog: [Internal] Reviewed By: cortinico, RSNara Differential Revision: D30401743 fbshipit-source-id: fb2e8f5cf33c94e31a0c25a89055acfc4eccf066 --- ReactCommon/react/renderer/core/ShadowNode.h | 4 ++++ ReactCommon/react/renderer/core/ShadowNodeTraits.h | 12 +++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/ReactCommon/react/renderer/core/ShadowNode.h b/ReactCommon/react/renderer/core/ShadowNode.h index 0735cbaa9ac..1ef71355f06 100644 --- a/ReactCommon/react/renderer/core/ShadowNode.h +++ b/ReactCommon/react/renderer/core/ShadowNode.h @@ -240,5 +240,9 @@ ShadowNodeReferenceT traitCast(ShadowNode const &shadowNode); template ShadowNodePointerT traitCast(ShadowNode const *shadowNode); +template +std::shared_ptr traitCast( + std::shared_ptr shadowNode); + } // namespace react } // namespace facebook diff --git a/ReactCommon/react/renderer/core/ShadowNodeTraits.h b/ReactCommon/react/renderer/core/ShadowNodeTraits.h index 5e55394454e..7c02f4bea94 100644 --- a/ReactCommon/react/renderer/core/ShadowNodeTraits.h +++ b/ReactCommon/react/renderer/core/ShadowNodeTraits.h @@ -21,7 +21,7 @@ class ShadowNodeTraits { public: /* * Underlying type for the traits. - * The first 18 bits are reserved for Core. + * The first 23 bits are reserved for Core. */ enum Trait : int32_t { None = 0, @@ -88,6 +88,16 @@ class ShadowNodeTraits { // Inherits 'TextShadowNode' Text = 1 << 17, + + // Reserved + ReservedTrait1 = 1 << 18, + ReservedTrait2 = 1 << 19, + ReservedTrait3 = 1 << 20, + ReservedTrait4 = 1 << 21, + ReservedTrait5 = 1 << 22, + + // Unserved - alias these for local usage + UnreservedTrait1 = 1 << 23 }; /*