Skip to content

Commit

Permalink
Move ShadowNodePair to Differentiator (#46590)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #46590

This API should not be part of the ShadowView header, since the class is only used by Differentiator. The ShadowView header should contain public API's that the mounting layer can consume.

Changelog: [Internal]

Reviewed By: sammy-SC

Differential Revision: D63148522

fbshipit-source-id: 0545777fd311424ccd2d66de8b47b5591e8175f7
  • Loading branch information
javache authored and facebook-github-bot committed Sep 23, 2024
1 parent 300db67 commit a6fcad7
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ enum class NoBreadcrumb {};

namespace facebook::react {

enum class ReparentMode { Flatten, Unflatten };

bool ShadowViewNodePair::operator==(const ShadowViewNodePair& rhs) const {
return this->shadowNode == rhs.shadowNode;
}

bool ShadowViewNodePair::operator!=(const ShadowViewNodePair& rhs) const {
return !(*this == rhs);
}

/*
* Extremely simple and naive implementation of a map.
* The map is simple but it's optimized for particular constraints that we have
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,48 @@

namespace facebook::react {

enum class ReparentMode { Flatten, Unflatten };
/*
* Describes pair of a `ShadowView` and a `ShadowNode`.
* This is not exposed to the mounting layer.
*/
struct ShadowViewNodePair final {
using NonOwningList = std::vector<ShadowViewNodePair*>;

ShadowView shadowView;
const ShadowNode* shadowNode;

/**
* The ShadowNode does not form a stacking context, and the native views
* corresponding to its children may be parented to an ancestor.
*/
bool flattened{false};

/**
* Whether this ShadowNode should create a corresponding native view.
*/
bool isConcreteView{true};
Point contextOrigin{0, 0};

size_t mountIndex{0};

/**
* This is nullptr unless `inOtherTree` is set to true.
* We rely on this only for marginal cases. TODO: could we
* rely on this more heavily to simplify the diffing algorithm
* overall?
*/
mutable const ShadowViewNodePair* otherTreePair{nullptr};

/*
* The stored pointer to `ShadowNode` represents an identity of the pair.
*/
bool operator==(const ShadowViewNodePair& rhs) const;
bool operator!=(const ShadowViewNodePair& rhs) const;

bool inOtherTree() const {
return this->otherTreePair != nullptr;
}
};

/**
* During differ, we need to keep some `ShadowViewNodePair`s in memory.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,4 @@ std::vector<DebugStringConvertibleObject> getDebugProps(

#endif

bool ShadowViewNodePair::operator==(const ShadowViewNodePair& rhs) const {
return this->shadowNode == rhs.shadowNode;
}

bool ShadowViewNodePair::operator!=(const ShadowViewNodePair& rhs) const {
return !(*this == rhs);
}

} // namespace facebook::react
Original file line number Diff line number Diff line change
Expand Up @@ -57,50 +57,6 @@ std::vector<DebugStringConvertibleObject> getDebugProps(

#endif

/*
* Describes pair of a `ShadowView` and a `ShadowNode`.
* This is not exposed to the mounting layer.
*
*/
struct ShadowViewNodePair final {
using NonOwningList = std::vector<ShadowViewNodePair*>;

ShadowView shadowView;
const ShadowNode* shadowNode;

/**
* The ShadowNode does not form a stacking context, and the native views
* corresponding to its children may be parented to an ancestor.
*/
bool flattened{false};

/**
* Whether this ShadowNode should create a corresponding native view.
*/
bool isConcreteView{true};
Point contextOrigin{0, 0};

size_t mountIndex{0};

/**
* This is nullptr unless `inOtherTree` is set to true.
* We rely on this only for marginal cases. TODO: could we
* rely on this more heavily to simplify the diffing algorithm
* overall?
*/
mutable const ShadowViewNodePair* otherTreePair{nullptr};

/*
* The stored pointer to `ShadowNode` represents an identity of the pair.
*/
bool operator==(const ShadowViewNodePair& rhs) const;
bool operator!=(const ShadowViewNodePair& rhs) const;

bool inOtherTree() const {
return this->otherTreePair != nullptr;
}
};

} // namespace facebook::react

namespace std {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ static void calculateShadowViewMutationsForNewTree(
ShadowViewMutation::List& mutations,
ViewNodePairScope& scope,
const ShadowView& parentShadowView,
std::vector<ShadowViewNodePair*> newChildPairs) {
ShadowViewNodePair::NonOwningList newChildPairs) {
// Sorting pairs based on `orderIndex` if needed.
reorderInPlaceIfNeeded(newChildPairs);

Expand Down

0 comments on commit a6fcad7

Please sign in to comment.