Use react_native_assert in LayoutAnimations
Summary: Use react_native_assert in LayoutAnimations to enable asserts to fire on Android. Changelog: [Internal] Reviewed By: mdvacca Differential Revision: D26517096 fbshipit-source-id: f000c4848f29c8779170625d357f547f2e9e6365
This commit is contained in:
Родитель
d93b7c3369
Коммит
5be2843c1c
|
@ -59,6 +59,7 @@ rn_xplat_cxx_library(
|
|||
"//xplat/jsi:JSIDynamic",
|
||||
"//xplat/jsi:jsi",
|
||||
react_native_xplat_target("react/config:config"),
|
||||
react_native_xplat_target("react/debug:debug"),
|
||||
react_native_xplat_target("react/renderer/componentregistry:componentregistry"),
|
||||
react_native_xplat_target("react/renderer/components/view:view"),
|
||||
react_native_xplat_target("react/renderer/core:core"),
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
#include <algorithm>
|
||||
#include <chrono>
|
||||
|
||||
#include <react/debug/react_native_assert.h>
|
||||
|
||||
#include <react/renderer/componentregistry/ComponentDescriptorFactory.h>
|
||||
#include <react/renderer/components/root/RootShadowNode.h>
|
||||
#include <react/renderer/components/view/ViewProps.h>
|
||||
|
@ -27,16 +29,6 @@
|
|||
|
||||
#include <glog/logging.h>
|
||||
|
||||
#ifdef VERBOSE_LAYOUT_ANIMATION_ASSERTS
|
||||
#define LA_ASSERT(cond) \
|
||||
if (!(cond)) { \
|
||||
LOG(ERROR) << "ASSERT FAILURE: " << #cond; \
|
||||
} \
|
||||
assert(cond);
|
||||
#else
|
||||
#define LA_ASSERT(cond) assert(cond);
|
||||
#endif
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
|
@ -410,7 +402,7 @@ void LayoutAnimationKeyFrameManager::
|
|||
bool skipLastAnimation,
|
||||
bool lastAnimationOnly) const {
|
||||
bool isRemoveMutation = mutation.type == ShadowViewMutation::Type::Remove;
|
||||
LA_ASSERT(
|
||||
react_native_assert(
|
||||
isRemoveMutation || mutation.type == ShadowViewMutation::Type::Insert);
|
||||
|
||||
// TODO: turn all of this into a lambda and share code?
|
||||
|
@ -525,7 +517,7 @@ void LayoutAnimationKeyFrameManager::adjustDelayedMutationIndicesForMutation(
|
|||
bool skipLastAnimation) const {
|
||||
bool isRemoveMutation = mutation.type == ShadowViewMutation::Type::Remove;
|
||||
bool isInsertMutation = mutation.type == ShadowViewMutation::Type::Insert;
|
||||
LA_ASSERT(isRemoveMutation || isInsertMutation);
|
||||
react_native_assert(isRemoveMutation || isInsertMutation);
|
||||
|
||||
if (mutatedViewIsVirtual(mutation)) {
|
||||
PrintMutationInstruction(
|
||||
|
@ -878,7 +870,7 @@ LayoutAnimationKeyFrameManager::pullTransaction(
|
|||
mutation.type == ShadowViewMutation::Type::Update
|
||||
? mutation.oldChildShadowView
|
||||
: mutation.newChildShadowView);
|
||||
LA_ASSERT(baselineShadowView.tag > 0);
|
||||
react_native_assert(baselineShadowView.tag > 0);
|
||||
bool haveComponentDescriptor =
|
||||
hasComponentDescriptorForShadowView(baselineShadowView);
|
||||
|
||||
|
@ -967,11 +959,12 @@ LayoutAnimationKeyFrameManager::pullTransaction(
|
|||
// If there's already an animation queued up, followed by this
|
||||
// Insert, it *must* be an Update mutation animation. Other
|
||||
// sequences should not be possible.
|
||||
LA_ASSERT(keyframe.type == AnimationConfigurationType::Update);
|
||||
react_native_assert(
|
||||
keyframe.type == AnimationConfigurationType::Update);
|
||||
|
||||
// The mutation is an "insert", so it must have a
|
||||
// "newChildShadowView"
|
||||
LA_ASSERT(mutation.newChildShadowView.tag > 0);
|
||||
react_native_assert(mutation.newChildShadowView.tag > 0);
|
||||
|
||||
// Those asserts don't run in prod. If there's some edge-case
|
||||
// that we haven't caught yet, we'd crash in debug; make sure we
|
||||
|
@ -993,14 +986,14 @@ LayoutAnimationKeyFrameManager::pullTransaction(
|
|||
mutation.type == ShadowViewMutation::Type::Insert
|
||||
? mutation.newChildShadowView
|
||||
: mutation.oldChildShadowView);
|
||||
LA_ASSERT(viewStart.tag > 0);
|
||||
react_native_assert(viewStart.tag > 0);
|
||||
ShadowView viewFinal = ShadowView(
|
||||
mutation.type == ShadowViewMutation::Type::Update
|
||||
? mutation.newChildShadowView
|
||||
: viewStart);
|
||||
LA_ASSERT(viewFinal.tag > 0);
|
||||
react_native_assert(viewFinal.tag > 0);
|
||||
ShadowView parent = mutation.parentShadowView;
|
||||
LA_ASSERT(
|
||||
react_native_assert(
|
||||
parent.tag > 0 ||
|
||||
mutation.type == ShadowViewMutation::Type::Update ||
|
||||
mutation.type == ShadowViewMutation::Type::Delete);
|
||||
|
@ -1024,7 +1017,7 @@ LayoutAnimationKeyFrameManager::pullTransaction(
|
|||
const_cast<ViewProps *>(viewProps)->opacity = 0;
|
||||
}
|
||||
|
||||
LA_ASSERT(props != nullptr);
|
||||
react_native_assert(props != nullptr);
|
||||
if (props != nullptr) {
|
||||
viewStart.props = props;
|
||||
}
|
||||
|
@ -1050,7 +1043,7 @@ LayoutAnimationKeyFrameManager::pullTransaction(
|
|||
Transform::Scale(isScaleX ? 0 : 1, isScaleY ? 0 : 1, 1);
|
||||
}
|
||||
|
||||
LA_ASSERT(props != nullptr);
|
||||
react_native_assert(props != nullptr);
|
||||
if (props != nullptr) {
|
||||
viewStart.props = props;
|
||||
}
|
||||
|
@ -1082,7 +1075,7 @@ LayoutAnimationKeyFrameManager::pullTransaction(
|
|||
const_cast<ViewProps *>(viewProps)->opacity = 0;
|
||||
}
|
||||
|
||||
LA_ASSERT(props != nullptr);
|
||||
react_native_assert(props != nullptr);
|
||||
if (props != nullptr) {
|
||||
viewFinal.props = props;
|
||||
}
|
||||
|
@ -1108,7 +1101,7 @@ LayoutAnimationKeyFrameManager::pullTransaction(
|
|||
Transform::Scale(isScaleX ? 0 : 1, isScaleY ? 0 : 1, 1);
|
||||
}
|
||||
|
||||
LA_ASSERT(props != nullptr);
|
||||
react_native_assert(props != nullptr);
|
||||
if (props != nullptr) {
|
||||
viewFinal.props = props;
|
||||
}
|
||||
|
@ -1140,7 +1133,8 @@ LayoutAnimationKeyFrameManager::pullTransaction(
|
|||
// (either this is a "move", or there's a corresponding "Delete"
|
||||
// that is animated). We configure it as a Noop animation so it is
|
||||
// executed when all the other animations are completed.
|
||||
LA_ASSERT(mutation.type == ShadowViewMutation::Type::Remove);
|
||||
react_native_assert(
|
||||
mutation.type == ShadowViewMutation::Type::Remove);
|
||||
|
||||
Tag removeTag = mutation.oldChildShadowView.tag;
|
||||
auto correspondingInsertIt = std::find_if(
|
||||
|
@ -1182,7 +1176,7 @@ LayoutAnimationKeyFrameManager::pullTransaction(
|
|||
// already made in the current animation, and start the animation
|
||||
// from this point.
|
||||
keyFrame.viewStart = conflictingKeyFrame.viewPrev;
|
||||
LA_ASSERT(keyFrame.viewStart.tag > 0);
|
||||
react_native_assert(keyFrame.viewStart.tag > 0);
|
||||
keyFrame.initialProgress = 0;
|
||||
|
||||
// We're guaranteed that a tag only has one animation associated
|
||||
|
@ -1193,9 +1187,9 @@ LayoutAnimationKeyFrameManager::pullTransaction(
|
|||
}
|
||||
}
|
||||
|
||||
LA_ASSERT(keyFrame.viewStart.tag > 0);
|
||||
LA_ASSERT(keyFrame.viewEnd.tag > 0);
|
||||
LA_ASSERT(keyFrame.viewPrev.tag > 0);
|
||||
react_native_assert(keyFrame.viewStart.tag > 0);
|
||||
react_native_assert(keyFrame.viewEnd.tag > 0);
|
||||
react_native_assert(keyFrame.viewPrev.tag > 0);
|
||||
keyFramesToAnimate.push_back(keyFrame);
|
||||
}
|
||||
|
||||
|
@ -1284,8 +1278,8 @@ LayoutAnimationKeyFrameManager::pullTransaction(
|
|||
PrintMutationInstruction(
|
||||
"Queueing up final mutation instruction - update:",
|
||||
mutationInstruction);
|
||||
LA_ASSERT(mutationInstruction.oldChildShadowView.tag > 0);
|
||||
LA_ASSERT(
|
||||
react_native_assert(mutationInstruction.oldChildShadowView.tag > 0);
|
||||
react_native_assert(
|
||||
mutationInstruction.newChildShadowView.tag > 0 ||
|
||||
mutationInstruction.type == ShadowViewMutation::Delete ||
|
||||
mutationInstruction.type == ShadowViewMutation::Remove);
|
||||
|
@ -1307,8 +1301,10 @@ LayoutAnimationKeyFrameManager::pullTransaction(
|
|||
auto generatedPenultimateMutation =
|
||||
ShadowViewMutation::UpdateMutation(
|
||||
keyFrame.viewPrev, mutatedShadowView);
|
||||
LA_ASSERT(generatedPenultimateMutation.oldChildShadowView.tag > 0);
|
||||
LA_ASSERT(generatedPenultimateMutation.newChildShadowView.tag > 0);
|
||||
react_native_assert(
|
||||
generatedPenultimateMutation.oldChildShadowView.tag > 0);
|
||||
react_native_assert(
|
||||
generatedPenultimateMutation.newChildShadowView.tag > 0);
|
||||
PrintMutationInstruction(
|
||||
"Queueing up penultimate mutation instruction - synthetic",
|
||||
generatedPenultimateMutation);
|
||||
|
@ -1316,8 +1312,8 @@ LayoutAnimationKeyFrameManager::pullTransaction(
|
|||
|
||||
auto generatedMutation = ShadowViewMutation::UpdateMutation(
|
||||
mutatedShadowView, keyFrame.viewEnd);
|
||||
LA_ASSERT(generatedMutation.oldChildShadowView.tag > 0);
|
||||
LA_ASSERT(generatedMutation.newChildShadowView.tag > 0);
|
||||
react_native_assert(generatedMutation.oldChildShadowView.tag > 0);
|
||||
react_native_assert(generatedMutation.newChildShadowView.tag > 0);
|
||||
PrintMutationInstruction(
|
||||
"Queueing up final mutation instruction - synthetic",
|
||||
generatedMutation);
|
||||
|
@ -1490,8 +1486,10 @@ LayoutAnimationKeyFrameManager::pullTransaction(
|
|||
auto generatedPenultimateMutation =
|
||||
ShadowViewMutation::UpdateMutation(
|
||||
keyFrame.viewPrev, mutatedShadowView);
|
||||
LA_ASSERT(generatedPenultimateMutation.oldChildShadowView.tag > 0);
|
||||
LA_ASSERT(generatedPenultimateMutation.newChildShadowView.tag > 0);
|
||||
react_native_assert(
|
||||
generatedPenultimateMutation.oldChildShadowView.tag > 0);
|
||||
react_native_assert(
|
||||
generatedPenultimateMutation.newChildShadowView.tag > 0);
|
||||
PrintMutationInstruction(
|
||||
"No Animation: Queueing up penultimate mutation instruction - synthetic",
|
||||
generatedPenultimateMutation);
|
||||
|
@ -1500,8 +1498,8 @@ LayoutAnimationKeyFrameManager::pullTransaction(
|
|||
|
||||
auto generatedMutation = ShadowViewMutation::UpdateMutation(
|
||||
mutatedShadowView, keyFrame.viewEnd);
|
||||
LA_ASSERT(generatedMutation.oldChildShadowView.tag > 0);
|
||||
LA_ASSERT(generatedMutation.newChildShadowView.tag > 0);
|
||||
react_native_assert(generatedMutation.oldChildShadowView.tag > 0);
|
||||
react_native_assert(generatedMutation.newChildShadowView.tag > 0);
|
||||
PrintMutationInstruction(
|
||||
"No Animation: Queueing up final mutation instruction - synthetic",
|
||||
generatedMutation);
|
||||
|
@ -1673,10 +1671,10 @@ ShadowView LayoutAnimationKeyFrameManager::createInterpolatedShadowView(
|
|||
double progress,
|
||||
ShadowView startingView,
|
||||
ShadowView finalView) const {
|
||||
LA_ASSERT(startingView.tag > 0);
|
||||
LA_ASSERT(finalView.tag > 0);
|
||||
react_native_assert(startingView.tag > 0);
|
||||
react_native_assert(finalView.tag > 0);
|
||||
if (!hasComponentDescriptorForShadowView(startingView)) {
|
||||
LA_ASSERT(false);
|
||||
react_native_assert(false);
|
||||
return finalView;
|
||||
}
|
||||
ComponentDescriptor const &componentDescriptor =
|
||||
|
@ -1690,10 +1688,10 @@ ShadowView LayoutAnimationKeyFrameManager::createInterpolatedShadowView(
|
|||
// will, so make sure we always keep the mounting layer consistent with the
|
||||
// "final" state.
|
||||
auto mutatedShadowView = ShadowView(finalView);
|
||||
LA_ASSERT(mutatedShadowView.tag > 0);
|
||||
react_native_assert(mutatedShadowView.tag > 0);
|
||||
|
||||
LA_ASSERT(startingView.props != nullptr);
|
||||
LA_ASSERT(finalView.props != nullptr);
|
||||
react_native_assert(startingView.props != nullptr);
|
||||
react_native_assert(finalView.props != nullptr);
|
||||
if (startingView.props == nullptr || finalView.props == nullptr) {
|
||||
return finalView;
|
||||
}
|
||||
|
@ -1701,7 +1699,7 @@ ShadowView LayoutAnimationKeyFrameManager::createInterpolatedShadowView(
|
|||
// Animate opacity or scale/transform
|
||||
mutatedShadowView.props = componentDescriptor.interpolateProps(
|
||||
progress, startingView.props, finalView.props);
|
||||
LA_ASSERT(mutatedShadowView.props != nullptr);
|
||||
react_native_assert(mutatedShadowView.props != nullptr);
|
||||
|
||||
// Interpolate LayoutMetrics
|
||||
LayoutMetrics const &finalLayoutMetrics = finalView.layoutMetrics;
|
||||
|
|
Загрузка…
Ссылка в новой задаче