Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void AnimatedPropsRegistry::update(
}
}

std::pair<std::unordered_set<const ShadowNodeFamily*>&, SnapshotMap&>
std::pair<std::unordered_set<ShadowNodeFamily::Shared>&, SnapshotMap&>
AnimatedPropsRegistry::getMap(SurfaceId surfaceId) {
auto lock = std::lock_guard(mutex_);
auto& [pendingMap, map, pendingFamilies, families] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ struct PropsSnapshot {

struct SurfaceContext {
std::unordered_map<Tag, std::unique_ptr<PropsSnapshot>> pendingMap, map;
std::unordered_set<const ShadowNodeFamily *> pendingFamilies, families;
std::unordered_set<ShadowNodeFamily::Shared> pendingFamilies, families;
};

struct SurfaceUpdates {
std::unordered_set<const ShadowNodeFamily *> families;
std::unordered_set<ShadowNodeFamily::Shared> families;
std::unordered_map<Tag, AnimatedProps> propsMap;
bool hasLayoutUpdates{false};
};
Expand All @@ -39,7 +39,7 @@ class AnimatedPropsRegistry {
public:
void update(const std::unordered_map<SurfaceId, SurfaceUpdates> &surfaceUpdates);
void clear(SurfaceId surfaceId);
std::pair<std::unordered_set<const ShadowNodeFamily *> &, SnapshotMap &> getMap(SurfaceId surfaceId);
std::pair<std::unordered_set<ShadowNodeFamily::Shared> &, SnapshotMap &> getMap(SurfaceId surfaceId);

private:
std::unordered_map<SurfaceId, SurfaceContext> surfaceContexts_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void AnimationBackend::onAnimationFrame(AnimationTimestamp timestamp) {
auto& [families, updates, hasLayoutUpdates] =
surfaceUpdates[family->getSurfaceId()];
hasLayoutUpdates |= mutation.hasLayoutUpdates;
families.insert(family.get());
families.insert(family);
updates[mutation.tag] = std::move(mutation.props);
}
}
Expand Down Expand Up @@ -145,7 +145,8 @@ void AnimationBackend::commitUpdates(
const ShadowNode& shadowNode,
const ShadowNodeFragment& fragment) {
auto newProps = ShadowNodeFragment::propsPlaceholder();
if (surfaceFamilies.contains(&shadowNode.getFamily())) {
if (surfaceFamilies.contains(
shadowNode.getFamilyShared())) {
auto& animatedProps = updates.at(shadowNode.getTag());
newProps = cloneProps(animatedProps, shadowNode);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ RootShadowNode::Unshared AnimationBackendCommitHook::shadowTreeWillCommit(
const ShadowNodeFragment& fragment) {
auto newProps = ShadowNodeFragment::propsPlaceholder();
std::shared_ptr<BaseViewProps> viewProps = nullptr;
if (surfaceFamilies.contains(&shadowNode.getFamily()) &&
if (surfaceFamilies.contains(shadowNode.getFamilyShared()) &&
updates.contains(shadowNode.getTag())) {
auto& snapshot = updates.at(shadowNode.getTag());
if (!snapshot->propNames.empty() || snapshot->rawProps) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,17 +413,16 @@ namespace {

std::shared_ptr<ShadowNode> cloneMultipleRecursive(
const ShadowNode& shadowNode,
const std::unordered_map<const ShadowNodeFamily*, int>& childrenCount,
const std::unordered_map<Tag, int>& childrenCount,
const std::function<std::shared_ptr<
ShadowNode>(const ShadowNode&, const ShadowNodeFragment&)>& callback) {
const auto* family = &shadowNode.getFamily();
auto& children = shadowNode.getChildren();
std::shared_ptr<std::vector<std::shared_ptr<const ShadowNode>>> newChildren;
auto count = childrenCount.at(family);
auto count = childrenCount.at(shadowNode.getTag());

for (size_t i = 0; count > 0 && i < children.size(); i++) {
const auto childFamily = &children[i]->getFamily();
if (childrenCount.contains(childFamily)) {
const auto childTag = children[i]->getTag();
if (childrenCount.contains(childTag)) {
count--;
if (!newChildren) {
newChildren =
Expand All @@ -441,37 +440,38 @@ std::shared_ptr<ShadowNode> cloneMultipleRecursive(
} // namespace

std::shared_ptr<ShadowNode> ShadowNode::cloneMultiple(
const std::unordered_set<const ShadowNodeFamily*>& familiesToUpdate,
const std::unordered_set<ShadowNodeFamily::Shared>& familiesToUpdate,
const std::function<std::shared_ptr<ShadowNode>(
const ShadowNode& oldShadowNode,
const ShadowNodeFragment& fragment)>& callback) const {
std::unordered_map<const ShadowNodeFamily*, int> childrenCount;
std::unordered_map<Tag, int> childrenCount;

for (const auto& family : familiesToUpdate) {
if (childrenCount.contains(family)) {
if (childrenCount.contains(family->getTag())) {
continue;
}

childrenCount[family] = 0;
childrenCount[family->getTag()] = 0;

auto ancestor = family->parent_.lock();
while ((ancestor != nullptr) && ancestor != family_) {
auto ancestorIt = childrenCount.find(ancestor.get());
auto ancestorTag = ancestor->getTag();
auto ancestorIt = childrenCount.find(ancestorTag);
if (ancestorIt != childrenCount.end()) {
ancestorIt->second++;
break;
}
childrenCount[ancestor.get()] = 1;
childrenCount[ancestorTag] = 1;

ancestor = ancestor->parent_.lock();
}

if (ancestor == family_) {
childrenCount[ancestor.get()]++;
childrenCount[ancestor->getTag()]++;
}
}

if (!childrenCount.contains(&this->getFamily())) {
if (!childrenCount.contains(getTag())) {
return nullptr;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class ShadowNode : public Sealable, public DebugStringConvertible, public jsi::N
* Returns `nullptr` if the operation cannot be performed successfully.
*/
std::shared_ptr<ShadowNode> cloneMultiple(
const std::unordered_set<const ShadowNodeFamily *> &familiesToUpdate,
const std::unordered_set<ShadowNodeFamily::Shared> &familiesToUpdate,
const std::function<
std::shared_ptr<ShadowNode>(const ShadowNode &oldShadowNode, const ShadowNodeFragment &fragment)> &callback)
const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ TEST_F(ShadowNodeTest, handleRuntimeReferenceTransferOnClone) {
TEST_F(ShadowNodeTest, cloneMultiple) {
auto newProps = std::make_shared<const TestProps>();
auto newRoot = nodeA_->cloneMultiple(
{&nodeA_->getFamily(), &nodeAB_->getFamily()},
{nodeA_->getFamilyShared(), nodeAB_->getFamilyShared()},
[&](const ShadowNode& oldShadowNode, const ShadowNodeFragment& fragment) {
return oldShadowNode.clone({
.props = newProps,
Expand Down Expand Up @@ -346,7 +346,7 @@ TEST_F(ShadowNodeTest, cloneMultiple) {
TEST_F(ShadowNodeTest, cloneMultipleWithSingleFamily) {
auto newProps = std::make_shared<const TestProps>();
auto newRoot = nodeA_->cloneMultiple(
{&nodeAB_->getFamily()},
{nodeAB_->getFamilyShared()},
[&](const ShadowNode& oldShadowNode, const ShadowNodeFragment& fragment) {
return oldShadowNode.clone({
.props = newProps,
Expand Down Expand Up @@ -379,7 +379,7 @@ TEST_F(ShadowNodeTest, cloneMultipleReturnsNullptrWhenFamilyHasNoPathToRoot) {
auto newProps = std::make_shared<const TestProps>();
// nodeZ_ is not part of nodeA_'s tree
auto result = nodeA_->cloneMultiple(
{&nodeZ_->getFamily()},
{nodeZ_->getFamilyShared()},
[&](const ShadowNode& oldShadowNode, const ShadowNodeFragment& fragment) {
return oldShadowNode.clone({
.props = newProps,
Expand All @@ -396,7 +396,7 @@ TEST_F(ShadowNodeTest, cloneMultipleWithMixOfValidAndInvalidFamilies) {
auto newProps = std::make_shared<const TestProps>();
// nodeAB_ is in the tree, nodeZ_ is not
auto result = nodeA_->cloneMultiple(
{&nodeAB_->getFamily(), &nodeZ_->getFamily()},
{nodeAB_->getFamilyShared(), nodeZ_->getFamilyShared()},
[&](const ShadowNode& oldShadowNode, const ShadowNodeFragment& fragment) {
return oldShadowNode.clone({
.props = newProps,
Expand Down
Loading