mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
dd05ec3801
Summary: 1. When testing major changes to the differ, it can be useful to have more verbose logging. 2. On Android, since asserts don't fire yet, I log which asserts are failing. Should have no impact on any builds unless you manually set the macro here, and it will have no impact on production builds regardless. Changelog: [Internal] Reviewed By: shergin Differential Revision: D23257859 fbshipit-source-id: 94a8e74ece8023064de0f2203db6074975f8f1f0
63 lines
2.0 KiB
C++
63 lines
2.0 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 "stubs.h"
|
|
|
|
#include <react/renderer/core/LayoutableShadowNode.h>
|
|
#include <react/renderer/core/ShadowNodeFragment.h>
|
|
#include <react/renderer/mounting/Differentiator.h>
|
|
|
|
namespace facebook {
|
|
namespace react {
|
|
|
|
/*
|
|
* Generates `create` and `insert` instructions recursively traversing a shadow
|
|
* tree.
|
|
* This is a trivial implementation of diffing algorithm that can only "diff"
|
|
* an empty tree with some other one.
|
|
*/
|
|
static void calculateShadowViewMutationsForNewTree(
|
|
ShadowViewMutation::List &mutations,
|
|
ShadowView const &parentShadowView,
|
|
ShadowViewNodePair::List const &newChildPairs) {
|
|
for (auto index = 0; index < newChildPairs.size(); index++) {
|
|
auto const &newChildPair = newChildPairs[index];
|
|
|
|
mutations.push_back(
|
|
ShadowViewMutation::CreateMutation(newChildPair.shadowView));
|
|
mutations.push_back(ShadowViewMutation::InsertMutation(
|
|
parentShadowView, newChildPair.shadowView, index));
|
|
|
|
auto const newGrandChildPairs =
|
|
sliceChildShadowNodeViewPairs(*newChildPair.shadowNode);
|
|
|
|
calculateShadowViewMutationsForNewTree(
|
|
mutations, newChildPair.shadowView, newGrandChildPairs);
|
|
}
|
|
}
|
|
|
|
StubViewTree stubViewTreeFromShadowNode(ShadowNode const &rootShadowNode) {
|
|
auto mutations = ShadowViewMutation::List{};
|
|
mutations.reserve(256);
|
|
|
|
calculateShadowViewMutationsForNewTree(
|
|
mutations,
|
|
ShadowView(rootShadowNode),
|
|
sliceChildShadowNodeViewPairs(rootShadowNode));
|
|
|
|
auto emptyRootShadowNode = rootShadowNode.clone(
|
|
ShadowNodeFragment{ShadowNodeFragment::propsPlaceholder(),
|
|
ShadowNode::emptySharedShadowNodeSharedList()});
|
|
|
|
auto stubViewTree = StubViewTree(ShadowView(*emptyRootShadowNode));
|
|
stubViewTree.mutate(mutations, true);
|
|
return stubViewTree;
|
|
}
|
|
|
|
} // namespace react
|
|
} // namespace facebook
|