Skip to content

Commit

Permalink
Fabric: Unification of ShadowView's default constructor
Browse files Browse the repository at this point in the history
Summary:
The previous version of a set of default values of `ShadowView`'s fields has a bug:
```
  ComponentName componentName = "";
```

Initalizing `char const *` with a string literal in .h file makes the default constructor of the object produces different values across binary units (because a pointer to empty string can be defined differently). Now it's just a null pointer.

Reviewed By: sammy-SC

Differential Revision: D15911452

fbshipit-source-id: 16bcfb5f78ea802c0833135c486e3fbb8b7acaa6
  • Loading branch information
shergin authored and facebook-github-bot committed Jun 24, 2019
1 parent bca4e4c commit 27b6729
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions ReactCommon/fabric/mounting/ShadowView.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,28 @@ namespace react {
*/
struct ShadowView final {
ShadowView() = default;
ShadowView(const ShadowView &shadowView) = default;
ShadowView(ShadowView const &shadowView) = default;
ShadowView(ShadowView &&shadowView) noexcept = default;

~ShadowView(){};

/*
* Constructs a `ShadowView` from given `ShadowNode`.
*/
explicit ShadowView(const ShadowNode &shadowNode);
explicit ShadowView(ShadowNode const &shadowNode);

ShadowView &operator=(const ShadowView &other) = default;
ShadowView &operator=(ShadowView const &other) = default;
ShadowView &operator=(ShadowView &&other) = default;

bool operator==(const ShadowView &rhs) const;
bool operator!=(const ShadowView &rhs) const;

ComponentName componentName = "";
ComponentHandle componentHandle = 0;
Tag tag = -1; // Tag does not change during the lifetime of a shadow view.
SharedProps props = {};
SharedEventEmitter eventEmitter = {};
LayoutMetrics layoutMetrics = EmptyLayoutMetrics;
SharedLocalData localData = {};
State::Shared state = {};
bool operator==(ShadowView const &rhs) const;
bool operator!=(ShadowView const &rhs) const;

ComponentName componentName{};
ComponentHandle componentHandle{};
Tag tag{};
Props::Shared props{};
EventEmitter::Shared eventEmitter{};
LayoutMetrics layoutMetrics{EmptyLayoutMetrics};
LocalData::Shared localData{};
State::Shared state{};
};

#if RN_DEBUG_STRING_CONVERTIBLE
Expand Down

0 comments on commit 27b6729

Please sign in to comment.