mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
97a4598bab
Summary: This diff adds more enforcement for consistency of `ShadowNodeMutation`s, including: * `Props` object for newly created or updated view must not be nullptr; * `oldShadowView` must describe the previous state of the view for `Update` instruction; * `ignoreDuplicateCreates` option was removed. I suspect some of the crashes we see in Fabric are caused by a violation of one of these constraints. If one of these fails in debug builds, we will get an early signal. Changelog: [Internal] Reviewed By: JoshuaGross Differential Revision: D24880821 fbshipit-source-id: 8c8a3d8e205ce34f6e0335e8a2b0cf676930c284
78 lines
2.2 KiB
C++
78 lines
2.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.
|
|
*/
|
|
|
|
#include "StubView.h"
|
|
|
|
namespace facebook {
|
|
namespace react {
|
|
|
|
StubView::operator ShadowView() const {
|
|
auto shadowView = ShadowView{};
|
|
shadowView.componentName = componentName;
|
|
shadowView.componentHandle = componentHandle;
|
|
shadowView.tag = tag;
|
|
shadowView.props = props;
|
|
shadowView.eventEmitter = eventEmitter;
|
|
shadowView.layoutMetrics = layoutMetrics;
|
|
shadowView.state = state;
|
|
return shadowView;
|
|
}
|
|
|
|
void StubView::update(ShadowView const &shadowView) {
|
|
componentName = shadowView.componentName;
|
|
componentHandle = shadowView.componentHandle;
|
|
tag = shadowView.tag;
|
|
props = shadowView.props;
|
|
eventEmitter = shadowView.eventEmitter;
|
|
layoutMetrics = shadowView.layoutMetrics;
|
|
state = shadowView.state;
|
|
}
|
|
|
|
bool operator==(StubView const &lhs, StubView const &rhs) {
|
|
return std::tie(lhs.props, lhs.layoutMetrics) ==
|
|
std::tie(rhs.props, rhs.layoutMetrics);
|
|
}
|
|
|
|
bool operator!=(StubView const &lhs, StubView const &rhs) {
|
|
return !(lhs == rhs);
|
|
}
|
|
|
|
#if RN_DEBUG_STRING_CONVERTIBLE
|
|
|
|
std::string getDebugName(StubView const &stubView) {
|
|
return std::string{"Stub"} +
|
|
std::string{stubView.componentHandle ? stubView.componentName
|
|
: "[invalid]"};
|
|
}
|
|
|
|
std::vector<DebugStringConvertibleObject> getDebugProps(
|
|
StubView const &stubView,
|
|
DebugStringConvertibleOptions options) {
|
|
return {
|
|
{"tag", getDebugDescription(stubView.tag, options)},
|
|
{"props", getDebugDescription(stubView.props, options)},
|
|
{"eventEmitter", getDebugDescription(stubView.eventEmitter, options)},
|
|
{"layoutMetrics", getDebugDescription(stubView.layoutMetrics, options)},
|
|
{"state", getDebugDescription(stubView.state, options)},
|
|
};
|
|
}
|
|
|
|
std::vector<StubView> getDebugChildren(
|
|
StubView const &stubView,
|
|
DebugStringConvertibleOptions options) {
|
|
std::vector<StubView> result;
|
|
for (auto const &child : stubView.children) {
|
|
result.push_back(*child);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
#endif
|
|
|
|
} // namespace react
|
|
} // namespace facebook
|