react-native/ReactCommon/fabric/uimanager/ShadowViewMutation.h
Valentin Shergin 5c83855c75 Fabric: Introducting ShadowView and ShadowViewMutation
Summary:
@public
We need some another object like ShadowNode (but not ShadowNode) to represent an instance of the component in the mutation instructions. This is
the main motivation for introducing ShadowView.

Why not use ShadowNode? ShadowNode is designed to represent a node in ShadowTree, not be a part of a mutation instruction.
 * ShadowNode exposes some APIs that should not be exposed to the mounting layer;
 * ShadowNode is an immutable data structure, so we cannot mutate it in some way which can be meaningful for mounting;
 * We should not add to ShadowNode any functionality which is needed only for mounting;
 * ShadowNode is a bit more heavy object to share that it needs to be; it's exposed (embedded into Mutation) as a `shared_ptr` which is not optimal from the performance perspective;
 * Retaining ShadowNode from mounting code can unnecessarily extend its lifetime which can negatively affect memory usage.

Reviewed By: mdvacca

Differential Revision: D9403562

fbshipit-source-id: 72ad81ed918157a62cd3d1a03261f14447649d0b
2018-09-03 23:04:20 -07:00

92 lines
1.9 KiB
C++

/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#pragma once
#include <vector>
#include <fabric/uimanager/ShadowView.h>
namespace facebook {
namespace react {
/*
* Describes a single native view tree mutation instruction which may contain
* pointers to an old shadow view, a new shadow view, a parent shadow view and
* final index of inserted or updated view.
* Use static methods to instantiate mutations of different types.
*/
struct ShadowViewMutation final {
#pragma mark - Designated Initializers
/*
* Creates and returns an `Create` mutation instruction.
*/
static ShadowViewMutation CreateMutation(
ShadowView shadowView
);
/*
* Creates and returns an `Delete` mutation instruction.
*/
static ShadowViewMutation DeleteMutation(
ShadowView shadowView
);
/*
* Creates and returns an `Insert` mutation instruction.
*/
static ShadowViewMutation InsertMutation(
ShadowView parentShadowView,
ShadowView childShadowView,
int index
);
/*
* Creates and returns a `Remove` mutation instruction.
*/
static ShadowViewMutation RemoveMutation(
ShadowView parentShadowView,
ShadowView childShadowView,
int index
);
/*
* Creates and returns an `Update` mutation instruction.
*/
static ShadowViewMutation UpdateMutation(
ShadowView parentShadowView,
ShadowView oldChildShadowView,
ShadowView newChildShadowView,
int index
);
#pragma mark - Type
enum Type {
Create,
Delete,
Insert,
Remove,
Update
};
#pragma mark - Fields
Type type = {Create};
ShadowView parentShadowView = {};
ShadowView oldChildShadowView = {};
ShadowView newChildShadowView = {};
int index = {};
};
using ShadowViewMutationList = std::vector<ShadowViewMutation>;
} // namespace react
} // namespace facebook