mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
7ac5d48341
Summary: On Android we have the notion of "virtual views", which are defined consistently but the logic is scattered and duplicated throughout the codebase. The logic exists to mark nodes that exist in the ShadowTree, but not the View tree. We want to CREATE, UPDATE, and DELETE them on the platform, but not INSERT or REMOVE them. They basically exist as EventEmitter objects. The only issue with this is (1) duplicated code, which opened the possibility for inconsistent definition (2) StubViewTree did not account for virtualized views, which caused assert crashes in debug mode for certain LayoutAnimations on Android. By moving the definition to ShadowViewMutation and accounting for it in StubViewTree, asserts are correct and consistent on all platforms. This was not caught until recently, because, until recently, no asserts actually ran on Android. Changelog: [Internal] Reviewed By: sammy-SC Differential Revision: D27001199 fbshipit-source-id: eb29085317037ba8a286d7813bdd57095ad4746f
138 lines
4.2 KiB
C++
138 lines
4.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 "ShadowViewMutation.h"
|
|
|
|
namespace facebook {
|
|
namespace react {
|
|
|
|
ShadowViewMutation ShadowViewMutation::CreateMutation(ShadowView shadowView) {
|
|
return {
|
|
/* .type = */ Create,
|
|
/* .parentShadowView = */ {},
|
|
/* .oldChildShadowView = */ {},
|
|
/* .newChildShadowView = */ shadowView,
|
|
/* .index = */ -1,
|
|
};
|
|
}
|
|
|
|
ShadowViewMutation ShadowViewMutation::DeleteMutation(ShadowView shadowView) {
|
|
return {
|
|
/* .type = */ Delete,
|
|
/* .parentShadowView = */ {},
|
|
/* .oldChildShadowView = */ shadowView,
|
|
/* .newChildShadowView = */ {},
|
|
/* .index = */ -1,
|
|
};
|
|
}
|
|
|
|
ShadowViewMutation ShadowViewMutation::InsertMutation(
|
|
ShadowView parentShadowView,
|
|
ShadowView childShadowView,
|
|
int index) {
|
|
return {
|
|
/* .type = */ Insert,
|
|
/* .parentShadowView = */ parentShadowView,
|
|
/* .oldChildShadowView = */ {},
|
|
/* .newChildShadowView = */ childShadowView,
|
|
/* .index = */ index,
|
|
};
|
|
}
|
|
|
|
ShadowViewMutation ShadowViewMutation::RemoveMutation(
|
|
ShadowView parentShadowView,
|
|
ShadowView childShadowView,
|
|
int index) {
|
|
return {
|
|
/* .type = */ Remove,
|
|
/* .parentShadowView = */ parentShadowView,
|
|
/* .oldChildShadowView = */ childShadowView,
|
|
/* .newChildShadowView = */ {},
|
|
/* .index = */ index,
|
|
};
|
|
}
|
|
|
|
ShadowViewMutation ShadowViewMutation::UpdateMutation(
|
|
ShadowView oldChildShadowView,
|
|
ShadowView newChildShadowView) {
|
|
return {
|
|
/* .type = */ Update,
|
|
/* .parentShadowView = */ {},
|
|
/* .oldChildShadowView = */ oldChildShadowView,
|
|
/* .newChildShadowView = */ newChildShadowView,
|
|
/* .index = */ -1,
|
|
};
|
|
}
|
|
|
|
bool ShadowViewMutation::mutatedViewIsVirtual() const {
|
|
bool viewIsVirtual = false;
|
|
|
|
#ifdef ANDROID
|
|
// Explanation: Even for non-virtual views,
|
|
// for "Insert" mutations, oldChildShadowView is always empty.
|
|
// for "Remove" mutations, newChildShadowView is always empty.
|
|
// Thus, to see if a view is virtual, we need to always check both the old and
|
|
// new View.
|
|
viewIsVirtual = newChildShadowView.layoutMetrics == EmptyLayoutMetrics &&
|
|
oldChildShadowView.layoutMetrics == EmptyLayoutMetrics;
|
|
#endif
|
|
|
|
return viewIsVirtual;
|
|
}
|
|
|
|
#if RN_DEBUG_STRING_CONVERTIBLE
|
|
|
|
std::string getDebugName(ShadowViewMutation const &mutation) {
|
|
switch (mutation.type) {
|
|
case ShadowViewMutation::Create:
|
|
return "Create";
|
|
case ShadowViewMutation::Delete:
|
|
return "Delete";
|
|
case ShadowViewMutation::Insert:
|
|
return "Insert";
|
|
case ShadowViewMutation::Remove:
|
|
return "Remove";
|
|
case ShadowViewMutation::Update:
|
|
return "Update";
|
|
}
|
|
}
|
|
|
|
std::vector<DebugStringConvertibleObject> getDebugProps(
|
|
ShadowViewMutation const &mutation,
|
|
DebugStringConvertibleOptions options) {
|
|
return {
|
|
mutation.oldChildShadowView.componentHandle
|
|
? DebugStringConvertibleObject{"oldChild",
|
|
getDebugDescription(
|
|
mutation.oldChildShadowView,
|
|
options)}
|
|
: DebugStringConvertibleObject{},
|
|
mutation.newChildShadowView.componentHandle
|
|
? DebugStringConvertibleObject{"newChild",
|
|
getDebugDescription(
|
|
mutation.newChildShadowView,
|
|
options)}
|
|
: DebugStringConvertibleObject{},
|
|
mutation.parentShadowView.componentHandle
|
|
? DebugStringConvertibleObject{"parent",
|
|
getDebugDescription(
|
|
mutation.parentShadowView,
|
|
options)}
|
|
: DebugStringConvertibleObject{},
|
|
mutation.index != -1
|
|
? DebugStringConvertibleObject{"index",
|
|
getDebugDescription(
|
|
mutation.index, options)}
|
|
: DebugStringConvertibleObject{},
|
|
};
|
|
}
|
|
|
|
#endif
|
|
|
|
} // namespace react
|
|
} // namespace facebook
|