Files
react-native/ReactCommon/react/renderer/core/ShadowNodeTraits.h
T
Andrew Coates 050922a17e Remove usages of RTTI in places used by react-native-windows (#31694)
Summary:
Adding runtime type information adds greatly to the binary size, so react-native-windows builds without it.  But some parts of the fabric code currently uses dynamic_cast, which means to use fabric we have to build with RTTI turned on.  This PR removes the usages of dynamic_cast that are hit in release builds, which should allow react-native-windows to turn off RTTI in release builds.

Required for:  https://github.com/microsoft/react-native-windows/issues/7981

One thing to note, the comment in ShadowNodeTraits indicates that core was reserving the first 16 bits.  I'm adding two more.  Is that ok?  Should core be reserving more for future use?

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://github.com/facebook/react-native/wiki/Changelog
-->

[Internal] [Fixed] - Remove uses of dynamic_cast in release builds

Pull Request resolved: https://github.com/facebook/react-native/pull/31694

Test Plan:
Verified that I can build react-native-windows with Fabric in release, without RTTI.
Boot / clicked around in RNW RNTester

Reviewed By: sammy-SC

Differential Revision: D29040383

Pulled By: JoshuaGross

fbshipit-source-id: e49286e59c4ba54faf0b4de5e244dfa1f7c3f193
2021-06-11 11:52:30 -07:00

114 lines
3.2 KiB
C++

/*
* 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 <cstdint>
namespace facebook {
namespace react {
/*
* A set of predefined traits associated with a particular `ShadowNode` class
* and an instance of that class. Used for efficient checking for interface
* conformance for and storing important flags.
*/
class ShadowNodeTraits {
public:
/*
* Underlying type for the traits.
* The first 18 bits are reserved for Core.
*/
enum Trait : int32_t {
None = 0,
// Note:
// Not all traits are used yet (but all will be used in the near future).
// Inherits `LayoutableShadowNode`.
LayoutableKind = 1 << 0,
// Inherits `YogaLayoutableShadowNode`.
YogaLayoutableKind = 1 << 1,
// Inherits `ConcreteViewShadowNode<>` template.
ViewKind = 1 << 2,
// Inherits `BaseTextShadowNode`.
TextKind = 1 << 3,
// Used when calculating relative layout in
// LayoutableShadowNode::getRelativeLayoutMetrics. This trait marks node as
// root, so when calculating relative layout, the calculation will not
// traverse beyond this node. See T61257516 for details.
RootNodeKind = 1 << 4,
// `ViewShadowNode` (exact!) class.
View = 1 << 5,
// The node is hidden.
// Nodes with this trait (and all their descendants) will not produce views.
Hidden = 1 << 6,
// Indicates that the `YogaLayoutableShadowNode` must set `isDirty` flag for
// Yoga node when a `ShadowNode` is being cloned. `ShadowNode`s that modify
// Yoga styles in the constructor (or later) *after* the `ShadowNode`
// is cloned must set this trait.
// Any Yoga node (not only Leaf ones) can have this trait.
DirtyYogaNode = 1 << 9,
// Inherits `YogaLayoutableShadowNode` and enforces that the `YGNode` is a
// leaf.
LeafYogaNode = 1 << 10,
// Inherits `YogaLayoutableShadowNode` and has a custom measure function.
// Only Leaf nodes can have this trait.
MeasurableYogaNode = 1 << 11,
// Indicates that the `ShadowNode` must form a stacking context.
// A Stacking Context forms a level of a `ShadowView` hierarchy (in contrast
// with a level of a `ShadowNode` hierarchy).
// See W3C standard for more details: https://www.w3.org/TR/CSS2/zindex.html
FormsStackingContext = 1 << 13,
// Indicates that the node must form a `ShadowView`.
FormsView = 1 << 14,
// Internal to `ShadowNode`; do not use it outside.
// Indicates that `children` list is shared between nodes and need
// to be cloned before the first mutation.
ChildrenAreShared = 1 << 15,
// Inherits 'RawTextShadowNode'
RawText = 1 << 16,
// Inherits 'TextShadowNode'
Text = 1 << 17,
};
/*
* Sets, unsets, and checks individual traits.
*/
inline void set(Trait trait) {
traits_ = ShadowNodeTraits::Trait(traits_ | trait);
}
inline void unset(Trait trait) {
traits_ = ShadowNodeTraits::Trait(traits_ & ~trait);
}
inline bool check(Trait traits) const {
return ShadowNodeTraits::Trait(traits_ & traits) == traits;
}
private:
Trait traits_{Trait::None};
};
} // namespace react
} // namespace facebook