react-native-reanimated 4.7.0 → 4.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/Common/cpp/reanimated/CSS/common/values/CSSNumber.cpp +5 -9
  2. package/Common/cpp/reanimated/CSS/common/values/CSSNumber.h +2 -6
  3. package/Common/cpp/reanimated/Fabric/ReanimatedCommitHook.cpp +34 -2
  4. package/Common/cpp/reanimated/Fabric/ReanimatedCommitHook.h +15 -1
  5. package/Common/cpp/reanimated/Fabric/ReanimatedMountHook.cpp +9 -0
  6. package/Common/cpp/reanimated/Fabric/ReanimatedMountHook.h +3 -0
  7. package/Common/cpp/reanimated/Fabric/updates/AnimatedPropsRegistry.cpp +135 -33
  8. package/Common/cpp/reanimated/Fabric/updates/AnimatedPropsRegistry.h +37 -3
  9. package/Common/cpp/reanimated/Fabric/updates/SynchronousWritesTracker.cpp +103 -0
  10. package/Common/cpp/reanimated/Fabric/updates/SynchronousWritesTracker.h +74 -0
  11. package/Common/cpp/reanimated/Fabric/updates/UpdatesRegistry.cpp +43 -0
  12. package/Common/cpp/reanimated/Fabric/updates/UpdatesRegistry.h +13 -0
  13. package/Common/cpp/reanimated/Fabric/updates/UpdatesRegistryManager.cpp +14 -1
  14. package/Common/cpp/reanimated/Fabric/updates/UpdatesRegistryManager.h +3 -0
  15. package/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy.cpp +318 -134
  16. package/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy.h +27 -6
  17. package/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxyCommon.cpp +32 -17
  18. package/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxyCommon.h +17 -1
  19. package/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy_Legacy.cpp +14 -13
  20. package/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy_Legacy.h +5 -2
  21. package/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsUtils.h +57 -9
  22. package/Common/cpp/reanimated/LayoutAnimations/PropsDiffer.h +2 -2
  23. package/Common/cpp/reanimated/LayoutAnimations/SharedTransitions.cpp +11 -11
  24. package/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxy.cpp +114 -11
  25. package/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxy.h +12 -2
  26. package/Common/cpp/reanimated/Tools/PlatformDepMethodsHolder.h +17 -1
  27. package/Common/cpp/reanimated/Tools/TextMetrics.h +22 -0
  28. package/android/src/main/cpp/reanimated/android/NativeProxy.cpp +32 -3
  29. package/android/src/main/cpp/reanimated/android/NativeProxy.h +3 -0
  30. package/android/src/main/java/com/swmansion/reanimated/NativeProxy.kt +108 -9
  31. package/android/src/main/java/com/swmansion/reanimated/NodesManager.kt +2 -4
  32. package/android/src/main/java/com/swmansion/reanimated/nativeProxy/EventHandler.kt +4 -3
  33. package/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensor.kt +1 -1
  34. package/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensorListener.kt +44 -33
  35. package/apple/reanimated/apple/REAReducedMotion.h +1 -3
  36. package/apple/reanimated/apple/REASynchronousPropsRewriter.h +18 -0
  37. package/apple/reanimated/apple/REASynchronousPropsRewriter.mm +37 -0
  38. package/apple/reanimated/apple/ReanimatedModule.mm +7 -0
  39. package/apple/reanimated/apple/keyboardObserver/REAKeyboardEventObserver.mm +20 -3
  40. package/apple/reanimated/apple/native/PlatformDepMethodsHolderImpl.mm +52 -1
  41. package/jest/resolver.js +4 -1
  42. package/lib/module/PropsRegistryGarbageCollector.js +43 -25
  43. package/lib/module/PropsRegistryGarbageCollector.js.map +1 -1
  44. package/lib/module/ReanimatedModule/NativeReanimated.js +2 -2
  45. package/lib/module/ReanimatedModule/NativeReanimated.js.map +1 -1
  46. package/lib/module/animation/timing.js +15 -2
  47. package/lib/module/animation/timing.js.map +1 -1
  48. package/lib/module/commonTypes.js.map +1 -1
  49. package/lib/module/createAnimatedComponent/AnimatedComponent.js +1 -1
  50. package/lib/module/createAnimatedComponent/AnimatedComponent.js.map +1 -1
  51. package/lib/module/createAnimatedComponent/AnimatedComponent.native.js +10 -34
  52. package/lib/module/createAnimatedComponent/AnimatedComponent.native.js.map +1 -1
  53. package/lib/module/platform-specific/jsVersion.js +1 -1
  54. package/lib/module/platformFunctions/setNativeProps.native.js +2 -1
  55. package/lib/module/platformFunctions/setNativeProps.native.js.map +1 -1
  56. package/lib/module/updateProps/updateProps.native.js +5 -4
  57. package/lib/module/updateProps/updateProps.native.js.map +1 -1
  58. package/lib/typescript/PropsRegistryGarbageCollector.d.ts +2 -2
  59. package/lib/typescript/PropsRegistryGarbageCollector.d.ts.map +1 -1
  60. package/lib/typescript/ReanimatedModule/reanimatedModuleProxy.d.ts +1 -1
  61. package/lib/typescript/ReanimatedModule/reanimatedModuleProxy.d.ts.map +1 -1
  62. package/lib/typescript/animation/timing.d.ts.map +1 -1
  63. package/lib/typescript/commonTypes.d.ts +3 -1
  64. package/lib/typescript/commonTypes.d.ts.map +1 -1
  65. package/lib/typescript/createAnimatedComponent/AnimatedComponent.d.ts +1 -1
  66. package/lib/typescript/createAnimatedComponent/AnimatedComponent.d.ts.map +1 -1
  67. package/lib/typescript/createAnimatedComponent/AnimatedComponent.native.d.ts +1 -1
  68. package/lib/typescript/createAnimatedComponent/AnimatedComponent.native.d.ts.map +1 -1
  69. package/lib/typescript/createAnimatedComponent/commonTypes.d.ts +1 -1
  70. package/lib/typescript/createAnimatedComponent/commonTypes.d.ts.map +1 -1
  71. package/lib/typescript/platform-specific/jsVersion.d.ts +1 -1
  72. package/lib/typescript/updateProps/updateProps.native.d.ts.map +1 -1
  73. package/package.json +9 -7
  74. package/src/PropsRegistryGarbageCollector.ts +46 -25
  75. package/src/ReanimatedModule/NativeReanimated.ts +2 -2
  76. package/src/ReanimatedModule/reanimatedModuleProxy.ts +1 -1
  77. package/src/animation/timing.ts +20 -2
  78. package/src/commonTypes.ts +3 -1
  79. package/src/createAnimatedComponent/AnimatedComponent.native.tsx +5 -30
  80. package/src/createAnimatedComponent/AnimatedComponent.tsx +1 -1
  81. package/src/createAnimatedComponent/commonTypes.ts +1 -1
  82. package/src/platform-specific/jsVersion.ts +1 -1
  83. package/src/platformFunctions/setNativeProps.native.ts +3 -1
  84. package/src/privateGlobals.d.ts +1 -0
  85. package/src/updateProps/updateProps.native.ts +10 -3
@@ -59,6 +59,39 @@ std::vector<AncestorOrigin> ancestorOrigins(
59
59
  }
60
60
  return chain;
61
61
  }
62
+
63
+ void collectSubtreeTags(const std::shared_ptr<LightNode> &node, std::unordered_set<Tag> &tags) {
64
+ tags.insert(node->current.tag);
65
+ for (const auto &child : node->children) {
66
+ collectSubtreeTags(child, tags);
67
+ }
68
+ }
69
+
70
+ // Every exiting ancestor that the removals leave without children.
71
+ void collectDroppedAncestors(const std::shared_ptr<LightNode> &node, std::unordered_set<Tag> &removals) {
72
+ for (auto ancestor = node->parent.lock(); ancestor && ancestor->isExiting() && ancestor->state != ANIMATING;
73
+ ancestor = ancestor->parent.lock()) {
74
+ const auto tag = ancestor->current.tag;
75
+ const auto keepsAChild = std::ranges::any_of(
76
+ ancestor->children, [&removals](const auto &child) { return !removals.contains(child->current.tag); });
77
+ if (removals.contains(tag) || keepsAChild) {
78
+ return;
79
+ }
80
+ removals.insert(tag);
81
+ }
82
+ }
83
+
84
+ // The subtrees of the roots and the ancestors that they drop.
85
+ std::unordered_set<Tag> collectRemovals(const std::vector<std::shared_ptr<LightNode>> &roots) {
86
+ std::unordered_set<Tag> removals;
87
+ for (const auto &root : roots) {
88
+ collectSubtreeTags(root, removals);
89
+ }
90
+ for (const auto &root : roots) {
91
+ collectDroppedAncestors(root, removals);
92
+ }
93
+ return removals;
94
+ }
62
95
  } // namespace
63
96
 
64
97
  std::shared_ptr<LayoutAnimationsProxyRegistry> createLayoutAnimationsProxyDefaultRegistry(
@@ -102,6 +135,20 @@ void LayoutAnimationsProxy::warnIfSnapshotIsStale(const ShadowView &snapshot, co
102
135
  }
103
136
  }
104
137
 
138
+ // A layout animation sends its frames to the platform as Updates from its current view.
139
+ const ShadowView &LayoutAnimationsProxy::mountedView(const std::shared_ptr<LightNode> &node) const {
140
+ const auto tag = node->current.tag;
141
+ if (const auto animationIt = layoutAnimations_.find(tag); animationIt != layoutAnimations_.end()) {
142
+ return animationIt->second.currentView;
143
+ }
144
+ if (const auto completedAnimationIt = completedAnimations_.find(tag);
145
+ completedAnimationIt != completedAnimations_.end()) {
146
+ return completedAnimationIt->second.animation.currentView;
147
+ }
148
+ resolveLightNodeProps(node);
149
+ return node->current;
150
+ }
151
+
105
152
  std::optional<ShadowView> LayoutAnimationsProxy::reparentLayoutAnimation(
106
153
  const Tag tag,
107
154
  const Tag parentTag,
@@ -157,7 +204,7 @@ std::optional<MountingTransaction> LayoutAnimationsProxy::pullTransaction(
157
204
  auto rootChildCount = static_cast<int>(lightNodes_[surfaceId_]->children.size());
158
205
  const bool flushStructuralMutations = shouldFlushStructuralMutations();
159
206
 
160
- reconcileContradictedRemovals(mutations, filteredMutations);
207
+ reconcileContradictedRemovals(mutations, transaction, propsParserContext);
161
208
 
162
209
  if constexpr (!StaticFeatureFlags::getFlag("ENABLE_SHARED_ELEMENT_TRANSITIONS")) {
163
210
  if (!mutations.empty()) {
@@ -188,7 +235,9 @@ std::optional<MountingTransaction> LayoutAnimationsProxy::pullTransaction(
188
235
  // shared element, the issue should be gone with the new stack
189
236
  // implementation
190
237
  if (auto screen = findParentRNSScreen(afterTopScreen)) {
191
- forceScreenSnapshot_(screen->current.tag);
238
+ if (forceScreenSnapshot_(screen->current.tag)) {
239
+ snapshottedScreens_.insert(screen->current.tag);
240
+ }
192
241
  }
193
242
  #endif
194
243
  }
@@ -215,14 +264,15 @@ std::optional<MountingTransaction> LayoutAnimationsProxy::pullTransaction(
215
264
  filteredMutations.insert(
216
265
  filteredMutations.end(), transaction.teardownMutations.begin(), transaction.teardownMutations.end());
217
266
 
267
+ collectDueRemovals(transaction);
218
268
  if (flushStructuralMutations) {
219
- flushCompletedRemovals(filteredMutations);
269
+ tearDown(transaction.dueRemovals, filteredMutations);
220
270
  }
221
271
 
222
272
  configLock.unlock();
223
273
  flushLayoutAnimationOperations(lock);
224
274
 
225
- addOngoingAnimations(filteredMutations);
275
+ addOngoingAnimations(transaction);
226
276
 
227
277
  cleanupAnimations(transaction, propsParserContext, flushStructuralMutations);
228
278
 
@@ -238,6 +288,10 @@ std::optional<MountingTransaction> LayoutAnimationsProxy::pullTransaction(
238
288
  keepTransitioningViewsHidden(filteredMutations, propsParserContext);
239
289
  }
240
290
 
291
+ react_native_assert(!deletesCreatedTag(filteredMutations) && "Transaction deletes a view that it creates");
292
+ #ifdef ANDROID
293
+ holdFramesUntilBatchIsQueued(filteredMutations);
294
+ #endif
241
295
  return MountingTransaction{surfaceId, transactionNumber, std::move(filteredMutations), telemetry};
242
296
  }
243
297
 
@@ -256,6 +310,7 @@ void LayoutAnimationsProxy::unmapLightNode(const std::shared_ptr<LightNode> &nod
256
310
  return;
257
311
  }
258
312
  lightNodes_.erase(it);
313
+ snapshottedScreens_.erase(node->current.tag);
259
314
  if (node == topScreen_) {
260
315
  topScreen_ = nullptr;
261
316
  }
@@ -268,51 +323,79 @@ void LayoutAnimationsProxy::unmapLightNode(const std::shared_ptr<LightNode> &nod
268
323
  }
269
324
  }
270
325
 
271
- // If React re-creates or re-inserts a tag whose exiting removal we are still
272
- // withholding, it has contradicted that withheld removal. Flush it now instead
273
- // of letting the stale node linger: updateLightTree would overwrite its
274
- // lightNodes_ entry (the "LightNode already exists" assert is compiled out in
275
- // release), orphaning the still-mounted exiting view, and the eventual
276
- // removal flush would then remove the wrong, live view and crash the
277
- // mounting layer.
278
- //
279
- // This must run before updateLightTree (so the tag is re-registered cleanly)
280
- // and before addOngoingAnimations (which would otherwise emit an Update for a
281
- // tag we are about to Delete this frame).
326
+ // React re-creating a tag that the light tree still holds keeps its mounted view: the Create becomes an Update of it
327
+ // and the Delete is dropped, because Android mounts the Deletes of a transaction after its Creates. A live node
328
+ // is deleted in the same transaction, for example when React Native's LayoutAnimation flushes a Remove and Delete
329
+ // that it deferred.
282
330
  void LayoutAnimationsProxy::reconcileContradictedRemovals(
283
- const ShadowViewMutationList &mutations,
284
- ShadowViewMutationList &filteredMutations) const {
331
+ ShadowViewMutationList &mutations,
332
+ TransactionMeta &transaction,
333
+ [[maybe_unused]] const PropsParserContext &propsParserContext) const {
334
+ auto &filteredMutations = transaction.filteredMutations;
335
+ auto &recreatedTags = transaction.recreatedTags;
336
+ std::unordered_set<Tag> deletedTags;
285
337
  for (const auto &mutation : mutations) {
286
- if (mutation.type != ShadowViewMutation::Type::Create && mutation.type != ShadowViewMutation::Type::Insert) {
338
+ if (mutation.type == ShadowViewMutation::Type::Delete) {
339
+ deletedTags.insert(mutation.oldChildShadowView.tag);
340
+ }
341
+ }
342
+ std::vector<std::shared_ptr<LightNode>> withheldNodes;
343
+ for (auto &mutation : mutations) {
344
+ if (mutation.type != ShadowViewMutation::Type::Create) {
287
345
  continue;
288
346
  }
289
347
  const auto tag = mutation.newChildShadowView.tag;
290
348
  const auto it = lightNodes_.find(tag);
291
- if (it == lightNodes_.end() || it->second->state == UNDEFINED) {
292
- continue;
293
- }
294
- const auto node = it->second;
295
- completedAnimations_.erase(tag);
296
- updateMap_.erase(tag);
297
- unmapLightNode(node);
298
- if (node->state == DELETED) {
299
- // already unmounted — only the stale map entry had to go
349
+ if (it == lightNodes_.end() || (it->second->state == LIVE && !deletedTags.contains(tag))) {
300
350
  continue;
301
351
  }
352
+ const auto &node = it->second;
302
353
  const auto parent = node->parent.lock();
303
354
  react_native_assert(parent && "Parent node is nullptr");
304
- if (!parent) {
305
- continue;
355
+ recreatedTags.insert(tag);
356
+ const auto &mounted = mountedView(node);
357
+ auto recreated = mutation.newChildShadowView;
358
+ #ifdef ANDROID
359
+ recreated = resetPropsMissingFrom(recreated, mounted, propsParserContext);
360
+ #endif
361
+ auto update = ShadowViewMutation::UpdateMutation(mounted, recreated, parent->current.tag);
362
+ if (node->state == LIVE) {
363
+ mutation = std::move(update);
364
+ } else {
365
+ filteredMutations.push_back(std::move(update));
366
+ withheldNodes.push_back(node);
306
367
  }
307
- const auto index = parent->removeChild(node);
308
- react_native_assert(index != -1 && "Exiting node not found");
309
- if (index == -1) {
310
- continue;
368
+ }
369
+ tearDown(collectRemovals(withheldNodes), filteredMutations);
370
+ const auto deletesRecreatedTag = [&recreatedTags](const ShadowViewMutation &mutation) {
371
+ return mutation.type == ShadowViewMutation::Delete && recreatedTags.contains(mutation.oldChildShadowView.tag);
372
+ };
373
+ std::erase_if(mutations, deletesRecreatedTag);
374
+ std::erase_if(filteredMutations, deletesRecreatedTag);
375
+ }
376
+
377
+ #ifdef ANDROID
378
+ // Android applies the raw props of an Update as they are, so a prop that the mounted view has and the view leaves
379
+ // out is set to null, which resets it.
380
+ ShadowView LayoutAnimationsProxy::resetPropsMissingFrom(
381
+ const ShadowView &view,
382
+ const ShadowView &mounted,
383
+ const PropsParserContext &propsParserContext) const {
384
+ auto rawProps = view.props->rawProps;
385
+ for (const auto &[name, _] : mounted.props->rawProps.items()) {
386
+ if (rawProps.count(name) == 0) {
387
+ rawProps[name] = nullptr;
311
388
  }
312
- endAnimationsRecursively(node, index, filteredMutations);
313
- maybeDropAncestors(parent, filteredMutations);
314
389
  }
390
+ if (rawProps.size() == view.props->rawProps.size()) {
391
+ return view;
392
+ }
393
+ auto newView = view;
394
+ newView.props = componentDescriptorRegistry_->at(view.componentHandle)
395
+ .cloneProps(propsParserContext, view.props, RawProps(std::move(rawProps)));
396
+ return newView;
315
397
  }
398
+ #endif
316
399
 
317
400
  bool LayoutAnimationsProxy::shouldOverridePullTransaction() const {
318
401
  // we need to listen to every possible mutation to keep the light tree updated
@@ -328,9 +411,9 @@ void LayoutAnimationsProxy::updateLightTree(
328
411
  ReanimatedSystraceSection s("updateLightTree");
329
412
  auto &filteredMutations = transaction.filteredMutations;
330
413
  std::unordered_set<Tag> inserted, moved, deleted;
331
- std::unordered_map<Tag, IndexCursors> indexCursors;
332
414
  std::unordered_map<Tag, ShadowView> updatedViews;
333
415
  std::unordered_map<Tag, std::vector<AncestorOrigin>> oldChains;
416
+ std::unordered_set<Tag> removedSubtreeRoots;
334
417
  for (auto it = mutations.rbegin(); it != mutations.rend(); it++) {
335
418
  const auto &mutation = *it;
336
419
  switch (mutation.type) {
@@ -403,37 +486,50 @@ void LayoutAnimationsProxy::updateLightTree(
403
486
  }
404
487
  lightNodes_[mutation.newChildShadowView.tag] = node;
405
488
  staleSynchronousProps_.forget(mutation.newChildShadowView.tag);
406
- filteredMutations.push_back(mutation);
489
+ if (!transaction.recreatedTags.contains(mutation.newChildShadowView.tag)) {
490
+ filteredMutations.push_back(mutation);
491
+ }
407
492
  break;
408
493
  }
409
494
  case ShadowViewMutation::Delete: {
410
- const auto it = lightNodes_.find(mutation.oldChildShadowView.tag);
411
- react_native_assert(it != lightNodes_.end() && "Delete mutation for an unknown node");
412
- const auto state = it->second->state;
413
- // View flattening emits a child's Delete after its parent's Remove, which may have already torn the child
414
- // down.
415
- if (state == UNDEFINED || state == DEAD || state == DELETED) {
495
+ const auto tag = mutation.oldChildShadowView.tag;
496
+ const auto it = lightNodes_.find(tag);
497
+ react_native_assert(
498
+ (it == lightNodes_.end() || it->second->isExiting()) &&
499
+ "Delete mutation for a view that React did not remove");
500
+ // The differ removes everything that moves out of a view before its Delete, and inserts into the parent
501
+ // of the view only after it.
502
+ if (removedSubtreeRoots.erase(tag)) {
503
+ react_native_assert(it != lightNodes_.end() && "Delete mutation for an unknown node");
416
504
  const auto node = it->second;
417
- unmapLightNode(node);
505
+ const auto parent = node->parent.lock();
506
+ react_native_assert(parent && "Parent node is nullptr");
507
+ handleSubtreeRemoval(node, parent, transaction);
418
508
  }
419
- staleSynchronousProps_.forget(mutation.oldChildShadowView.tag);
509
+ staleSynchronousProps_.forget(tag);
420
510
  break;
421
511
  }
422
512
  case ShadowViewMutation::Insert: {
423
513
  transferConfigFromNativeID(mutation.newChildShadowView.props->nativeId, mutation.newChildShadowView.tag);
424
514
  auto &node = lightNodes_[mutation.newChildShadowView.tag];
515
+ react_native_assert(node->state == LIVE && "React inserts a view whose removal is withheld");
425
516
  auto &parent = lightNodes_[mutation.parentTag];
426
- const auto hostIndex = parent->toHostIndexForInsert(mutation.index, indexCursors[mutation.parentTag]);
517
+ auto &cursors = transaction.indexCursors[mutation.parentTag];
518
+ const auto hostIndex = parent->toHostIndexForInsert(mutation.index, cursors);
427
519
  parent->children.insert(parent->children.begin() + hostIndex, node);
520
+ cursors.remove = {};
428
521
  node->parent = parent;
429
522
  const auto tag = mutation.newChildShadowView.tag;
430
523
  bool hasSharedTransition = false;
431
524
  if constexpr (StaticFeatureFlags::getFlag("ENABLE_SHARED_ELEMENT_TRANSITIONS")) {
432
525
  auto sharedTransitionLock = std::unique_lock<std::mutex>(sharedTransitionManager_->mutex_);
433
- hasSharedTransition = sharedTransitionManager_->tagToName_.contains(tag);
526
+ hasSharedTransition = mutation.newChildShadowView.traits.check(ShadowNodeTraits::Trait::ViewKind) &&
527
+ sharedTransitionManager_->tagToName_.contains(tag);
434
528
  }
435
529
  const auto layoutConfig = layoutAnimationsManager_->getLayoutAnimationConfig(tag, LAYOUT);
436
- const auto enteringConfig = layoutAnimationsManager_->getLayoutAnimationConfig(tag, ENTERING);
530
+ const auto enteringConfig = isViewKind(mutation.newChildShadowView)
531
+ ? layoutAnimationsManager_->getLayoutAnimationConfig(tag, ENTERING)
532
+ : nullptr;
437
533
  if (moved.contains(tag)) {
438
534
  const auto offset = reparentOffset(oldChains.at(tag), ancestorOrigins(parent, {}));
439
535
  node->previous.layoutMetrics.frame.origin += offset;
@@ -449,8 +545,13 @@ void LayoutAnimationsProxy::updateLightTree(
449
545
  filteredMutations.push_back(
450
546
  ShadowViewMutation::InsertMutation(mutation.parentTag, node->previous, hostIndex));
451
547
  } else {
452
- filteredMutations.push_back(
453
- ShadowViewMutation::InsertMutation(mutation.parentTag, mutation.newChildShadowView, hostIndex));
548
+ auto view = mutation.newChildShadowView;
549
+ const auto updatedViewIt = updatedViews.find(tag);
550
+ const bool propsChanged = updatedViewIt != updatedViews.end() && updatedViewIt->second.props != view.props;
551
+ if (!propsChanged) {
552
+ view.props = propsOfMountedView(view);
553
+ }
554
+ filteredMutations.push_back(ShadowViewMutation::InsertMutation(mutation.parentTag, view, hostIndex));
454
555
  }
455
556
  } else if (enteringConfig) {
456
557
  transaction.entering.push_back({node, enteringConfig});
@@ -476,7 +577,10 @@ void LayoutAnimationsProxy::updateLightTree(
476
577
  const auto tag = node->current.tag;
477
578
  const auto parentTag = mutation.parentTag;
478
579
  const auto &parent = lightNodes_[parentTag];
479
- const auto hostIndex = parent->toHostIndexForRemove(mutation.index, indexCursors[parentTag]);
580
+ react_native_assert(parent && "Remove mutation from an unknown parent");
581
+ auto &cursors = transaction.indexCursors[parentTag];
582
+ const auto hostIndex = parent->toHostIndexForRemove(mutation.index, cursors);
583
+ cursors.insert = {};
480
584
  react_native_assert(
481
585
  hostIndex < static_cast<int>(parent->children.size()) &&
482
586
  parent->children[hostIndex]->current.tag == mutation.oldChildShadowView.tag &&
@@ -490,8 +594,11 @@ void LayoutAnimationsProxy::updateLightTree(
490
594
  filteredMutations.push_back(
491
595
  ShadowViewMutation::RemoveMutation(parentTag, mutation.oldChildShadowView, hostIndex));
492
596
  parent->children.erase(parent->children.begin() + hostIndex);
493
- } else if (!deleted.contains(parentTag)) {
494
- handleSubtreeRemoval(node, parent, hostIndex, transaction);
597
+ } else {
598
+ node->setExitingState(DECISION_PENDING);
599
+ if (!deleted.contains(parentTag)) {
600
+ removedSubtreeRoots.insert(tag);
601
+ }
495
602
  }
496
603
  break;
497
604
  }
@@ -501,6 +608,7 @@ void LayoutAnimationsProxy::updateLightTree(
501
608
  }
502
609
  }
503
610
  }
611
+ react_native_assert(removedSubtreeRoots.empty() && "React removed a view without deleting it");
504
612
  }
505
613
 
506
614
  void LayoutAnimationsProxy::applyInitialMutationsToLightTree(const ShadowViewMutationList &mutations) const {
@@ -656,14 +764,16 @@ void LayoutAnimationsProxy::initializeLightTree(const ShadowTreeRevision &baseRe
656
764
 
657
765
  const auto lock = std::unique_lock<std::recursive_mutex>(mutex);
658
766
  react_native_assert(!isLightTreeInitialized() && "Light tree is already initialized");
767
+ const auto root = std::make_shared<LightNode>();
659
768
  if (baseRevision.rootShadowNode) {
660
769
  const auto &size = baseRevision.rootShadowNode->getLayoutMetrics().frame.size;
661
770
  window_ = {size.width, size.height};
771
+ root->current = ShadowView(*baseRevision.rootShadowNode);
772
+ } else {
773
+ root->current.componentName = "RootView";
774
+ root->current.tag = surfaceId_;
775
+ root->current.props = std::make_shared<BaseViewProps>();
662
776
  }
663
- const auto root = std::make_shared<LightNode>();
664
- root->current.componentName = "RootView";
665
- root->current.tag = surfaceId_;
666
- root->current.props = std::make_shared<BaseViewProps>();
667
777
  lightNodes_[surfaceId_] = root;
668
778
  applyInitialMutationsToLightTree(initialMutations);
669
779
  for (const auto &[revisionNumber, mutations] : pendingTransactions_) {
@@ -703,74 +813,101 @@ std::optional<SurfaceId> LayoutAnimationsProxy::endLayoutAnimation(int tag, bool
703
813
  react_native_assert(false && "LightNode not found");
704
814
  return surfaceId_;
705
815
  }
706
- nodeIt->second->setExitingState(DEAD);
816
+ nodeIt->second->setExitingState(COMPLETED);
707
817
 
708
818
  return surfaceId_;
709
819
  }
710
820
 
711
821
  // A subtree that animates keeps its place in the host tree, so nothing is emitted for its root.
712
- // A subtree that does not animate emits its Remove in stream order. Its teardown mounts at the
713
- // end of the transaction, so native code that reads a view on unmount still sees its children.
822
+ // A subtree that does not animate is removed at its current host index after its descendants, like React
823
+ // removes it. On iOS a subtree that holds a screen React Native Screens snapshots is removed before its
824
+ // descendants instead, and their teardown mounts at the end of the transaction.
714
825
  void LayoutAnimationsProxy::handleSubtreeRemoval(
715
826
  const std::shared_ptr<LightNode> &node,
716
827
  const std::shared_ptr<LightNode> &parent,
717
- const int hostIndex,
718
828
  TransactionMeta &transaction) const {
719
829
  ReanimatedSystraceSection s("handleSubtreeRemoval");
830
+ const bool defersTeardown = holdsSnapshottedScreen(node);
720
831
  const StartAnimationsRecursivelyConfig config = {
721
832
  .shouldRemoveSubviewsWithoutAnimations = true,
722
833
  .shouldAnimate = !transaction.surfaceDropped,
723
834
  .isScreenPop = false,
835
+ .defersTeardown = defersTeardown,
724
836
  };
725
837
  if (startAnimationsRecursively(node, transaction, config)) {
726
838
  return;
727
839
  }
728
- react_native_assert(!node->isExiting() && "A subtree that does not animate must stay UNDEFINED");
840
+ react_native_assert(node->state == DECISION_PENDING && "A subtree that does not animate stays DECISION_PENDING");
841
+ const auto hostIndex = parent->removeChild(node);
842
+ react_native_assert(hostIndex != -1 && "Removed node not found in its parent");
843
+ transaction.indexCursors.erase(parent->current.tag);
844
+ node->setExitingState(TORN_DOWN);
845
+ unmapLightNode(node);
729
846
  cancelLayoutAnimation(node->current.tag);
730
847
  if constexpr (StaticFeatureFlags::getFlag("ENABLE_SHARED_ELEMENT_TRANSITIONS")) {
731
848
  hiddenViewTags_.erase(node->current.tag);
732
849
  }
733
850
  transaction.filteredMutations.push_back(
734
851
  ShadowViewMutation::RemoveMutation(parent->current.tag, node->current, hostIndex));
735
- transaction.teardownMutations.push_back(ShadowViewMutation::DeleteMutation(node->current));
736
- parent->children.erase(parent->children.begin() + hostIndex);
852
+ (defersTeardown ? transaction.teardownMutations : transaction.filteredMutations)
853
+ .push_back(ShadowViewMutation::DeleteMutation(node->current));
737
854
  }
738
855
 
739
- void LayoutAnimationsProxy::flushCompletedRemovals(ShadowViewMutationList &filteredMutations) const {
740
- ReanimatedSystraceSection s("flushCompletedRemovals");
856
+ // React Native Screens snapshots a screen in snapshottedScreens_ after pending updates when the screen is removed,
857
+ // so its content must still be mounted then.
858
+ bool LayoutAnimationsProxy::holdsSnapshottedScreen([[maybe_unused]] const std::shared_ptr<LightNode> &node) const {
859
+ #ifdef __APPLE__
860
+ if constexpr (StaticFeatureFlags::getFlag("ENABLE_SHARED_ELEMENT_TRANSITIONS")) {
861
+ return std::ranges::any_of(snapshottedScreens_, [&](const Tag tag) {
862
+ const auto it = lightNodes_.find(tag);
863
+ return it != lightNodes_.end() && isInSubtree(it->second, node);
864
+ });
865
+ }
866
+ #endif
867
+ return false;
868
+ }
741
869
 
742
- std::vector<Tag> completedRemovalTags;
743
- completedRemovalTags.reserve(completedAnimations_.size());
870
+ // A UI-thread pull on Android must not update the views that the next flushing pull removes, because
871
+ // Android can mount that JS-thread pull first.
872
+ void LayoutAnimationsProxy::collectDueRemovals(TransactionMeta &transaction) const {
873
+ std::vector<std::shared_ptr<LightNode>> finishedExits;
744
874
  for (const auto &[tag, completedAnimation] : completedAnimations_) {
745
- if (hasPendingLayoutAnimation(tag) || !completedAnimation.shouldRemove) {
875
+ const auto nodeIt = lightNodes_.find(tag);
876
+ if (!completedAnimation.shouldRemove || hasPendingLayoutAnimation(tag) || nodeIt == lightNodes_.end() ||
877
+ nodeIt->second->state != COMPLETED) {
746
878
  continue;
747
879
  }
748
- completedRemovalTags.push_back(tag);
880
+ finishedExits.push_back(nodeIt->second);
749
881
  }
882
+ transaction.dueRemovals = collectRemovals(finishedExits);
883
+ }
750
884
 
751
- for (const auto tag : completedRemovalTags) {
752
- const auto completedAnimationIt = completedAnimations_.find(tag);
753
- if (completedAnimationIt == completedAnimations_.end() || hasPendingLayoutAnimation(tag) ||
754
- !completedAnimationIt->second.shouldRemove) {
755
- continue;
756
- }
757
- const auto nodeIt = lightNodes_.find(tag);
758
- if (nodeIt == lightNodes_.end() || nodeIt->second->state != DEAD) {
759
- continue;
760
- }
761
- const auto node = nodeIt->second;
762
- auto parent = node->parent.lock();
885
+ void LayoutAnimationsProxy::tearDown(const std::unordered_set<Tag> &removals, ShadowViewMutationList &mutations) const {
886
+ ReanimatedSystraceSection s("tearDown");
887
+ std::vector<std::shared_ptr<LightNode>> roots;
888
+ for (const auto tag : removals) {
889
+ const auto &node = lightNodes_.at(tag);
890
+ const auto parent = node->parent.lock();
763
891
  react_native_assert(parent && "Parent node is nullptr");
764
- auto index = parent->removeChild(node);
765
- react_native_assert(index != -1 && "Dead node not found");
766
-
767
- endAnimationsRecursively(node, index, filteredMutations);
768
- maybeDropAncestors(parent, filteredMutations);
892
+ if (!removals.contains(parent->current.tag)) {
893
+ roots.push_back(node);
894
+ }
895
+ }
896
+ [[maybe_unused]] const auto mutationCount = mutations.size();
897
+ for (const auto &root : roots) {
898
+ const auto index = root->parent.lock()->removeChild(root);
899
+ react_native_assert(index != -1 && "Removed node not found in its parent");
900
+ endAnimationsRecursively(root, index, mutations);
769
901
  }
902
+ react_native_assert(
903
+ mutations.size() - mutationCount == 2 * removals.size() &&
904
+ std::ranges::none_of(removals, [this](const Tag tag) { return lightNodes_.contains(tag); }) &&
905
+ "The teardown must remove exactly the removals");
770
906
  }
771
907
 
772
- void LayoutAnimationsProxy::addOngoingAnimations(ShadowViewMutationList &mutations) const {
908
+ void LayoutAnimationsProxy::addOngoingAnimations(TransactionMeta &transaction) const {
773
909
  ReanimatedSystraceSection s1("addOngoingAnimations");
910
+ auto &mutations = transaction.filteredMutations;
774
911
  #ifdef ANDROID
775
912
  std::optional<std::unique_ptr<int[]>> maybeCorrectedTags;
776
913
 
@@ -804,6 +941,9 @@ void LayoutAnimationsProxy::addOngoingAnimations(ShadowViewMutationList &mutatio
804
941
  // https://github.com/software-mansion/react-native-reanimated/issues/7493
805
942
  continue;
806
943
  }
944
+ if (transaction.dueRemovals.contains(tag) || unqueuedBatchTags_.contains(tag)) {
945
+ continue;
946
+ }
807
947
  #endif
808
948
 
809
949
  auto layoutAnimationIt = layoutAnimations_.find(tag);
@@ -824,11 +964,16 @@ void LayoutAnimationsProxy::addOngoingAnimations(ShadowViewMutationList &mutatio
824
964
  mutations.push_back(
825
965
  ShadowViewMutation::UpdateMutation(layoutAnimation.currentView, newView, layoutAnimation.parentTag));
826
966
  layoutAnimation.currentView = newView;
827
- if (layoutAnimation.opacity && static_cast<const ViewProps &>(*newView.props).opacity == *layoutAnimation.opacity) {
967
+ if (layoutAnimation.opacity &&
968
+ (updateValues.animatesOpacity || getViewProps(newView).opacity == *layoutAnimation.opacity)) {
828
969
  layoutAnimation.opacity.reset();
829
970
  }
830
971
  }
972
+ #ifdef ANDROID
973
+ std::erase_if(updateMap_, [this](const auto &update) { return !unqueuedBatchTags_.contains(update.first); });
974
+ #else
831
975
  updateMap_.clear();
976
+ #endif
832
977
  }
833
978
 
834
979
  void LayoutAnimationsProxy::endAnimationsRecursively(
@@ -837,7 +982,7 @@ void LayoutAnimationsProxy::endAnimationsRecursively(
837
982
  ShadowViewMutationList &mutations) const {
838
983
  const auto tag = node->current.tag;
839
984
  cancelLayoutAnimation(tag);
840
- node->setExitingState(DELETED);
985
+ node->setExitingState(TORN_DOWN);
841
986
  unmapLightNode(node);
842
987
  // iterate from the end, so that children
843
988
  // with higher indices appear first in the mutations list
@@ -845,7 +990,7 @@ void LayoutAnimationsProxy::endAnimationsRecursively(
845
990
  const int childrenSize = static_cast<int>(node->children.size());
846
991
  for (int i = childrenSize - 1; i >= 0; i--) {
847
992
  auto &subNode = node->children[i];
848
- if (subNode->state != DELETED) {
993
+ if (subNode->state != TORN_DOWN) {
849
994
  endAnimationsRecursively(subNode, i, mutations);
850
995
  }
851
996
  }
@@ -860,35 +1005,14 @@ void LayoutAnimationsProxy::endAnimationsRecursively(
860
1005
  mutations.push_back(ShadowViewMutation::DeleteMutation(node->current));
861
1006
  }
862
1007
 
863
- void LayoutAnimationsProxy::maybeDropAncestors(
864
- const std::shared_ptr<LightNode> &node,
865
- ShadowViewMutationList &cleanupMutations) const {
866
- if (node->children.size() != 0 || node->state == ANIMATING || node->state == UNDEFINED) {
867
- return;
868
- }
869
-
870
- auto parent = node->parent.lock();
871
- react_native_assert(parent && "Parent node is nullptr");
872
- auto index = parent->removeChild(node);
873
- react_native_assert(index != -1 && "Child node not found");
874
-
875
- node->setExitingState(DELETED);
876
- unmapLightNode(node);
877
- cancelLayoutAnimation(node->current.tag);
878
- if constexpr (StaticFeatureFlags::getFlag("ENABLE_SHARED_ELEMENT_TRANSITIONS")) {
879
- hiddenViewTags_.erase(node->current.tag);
880
- }
881
- cleanupMutations.push_back(ShadowViewMutation::RemoveMutation(parent->current.tag, node->current, index));
882
- cleanupMutations.push_back(ShadowViewMutation::DeleteMutation(node->current));
883
- maybeDropAncestors(parent, cleanupMutations);
884
- }
885
-
886
1008
  bool LayoutAnimationsProxy::startAnimationsRecursively(
887
1009
  const std::shared_ptr<LightNode> &node,
888
1010
  TransactionMeta &transaction,
889
1011
  StartAnimationsRecursivelyConfig config) const {
890
- auto &mutations = transaction.teardownMutations;
891
- auto &[shouldRemoveSubviewsWithoutAnimations, shouldAnimate, isScreenPop] = config;
1012
+ react_native_assert(node->state == DECISION_PENDING && "Subtree removal of a view that React does not delete");
1013
+ transaction.indexCursors.erase(node->current.tag);
1014
+ auto &[shouldRemoveSubviewsWithoutAnimations, shouldAnimate, isScreenPop, defersTeardown] = config;
1015
+ auto &mutations = defersTeardown ? transaction.teardownMutations : transaction.filteredMutations;
892
1016
  if (isRNSScreenOrStack(node)) {
893
1017
  isScreenPop = true;
894
1018
  }
@@ -909,8 +1033,9 @@ bool LayoutAnimationsProxy::startAnimationsRecursively(
909
1033
  for (auto it = node->children.rbegin(); it != node->children.rend(); it++) {
910
1034
  index--;
911
1035
  auto &subNode = *it;
912
- if (subNode->state != UNDEFINED) {
913
- if (shouldAnimate && subNode->state != DEAD) {
1036
+ react_native_assert(subNode->isExiting() && "Subtree removal of a view that React does not delete");
1037
+ if (subNode->state != DECISION_PENDING) {
1038
+ if (shouldAnimate && subNode->state != COMPLETED) {
914
1039
  hasAnimatedChildren = true;
915
1040
  } else {
916
1041
  endAnimationsRecursively(subNode, index, mutations);
@@ -925,13 +1050,11 @@ bool LayoutAnimationsProxy::startAnimationsRecursively(
925
1050
  }
926
1051
  mutations.push_back(ShadowViewMutation::RemoveMutation(node->current.tag, subNode->current, index));
927
1052
  toBeRemoved.push_back(subNode);
928
- subNode->setExitingState(DELETED);
1053
+ subNode->setExitingState(TORN_DOWN);
1054
+ unmapLightNode(subNode);
929
1055
  mutations.push_back(ShadowViewMutation::DeleteMutation(subNode->current));
930
1056
  } else {
931
1057
  subNode->setExitingState(WAITING);
932
- // register withheld subtree members, so that reconcileContradictedRemovals
933
- // can find them when React re-creates their tags
934
- lightNodes_[subNode->current.tag] = subNode;
935
1058
  }
936
1059
  }
937
1060
 
@@ -943,7 +1066,6 @@ bool LayoutAnimationsProxy::startAnimationsRecursively(
943
1066
 
944
1067
  if (hasExitAnimation) {
945
1068
  node->setExitingState(ANIMATING);
946
- lightNodes_[node->current.tag] = node;
947
1069
  transaction.exiting.push_back({node, exitConfig});
948
1070
  } else {
949
1071
  if (!shouldAnimate) {
@@ -951,7 +1073,6 @@ bool LayoutAnimationsProxy::startAnimationsRecursively(
951
1073
  }
952
1074
  if (hasAnimatedChildren) {
953
1075
  node->setExitingState(WAITING);
954
- lightNodes_[node->current.tag] = node;
955
1076
  }
956
1077
  }
957
1078
 
@@ -967,11 +1088,13 @@ void LayoutAnimationsProxy::clearSurfaceState() const {
967
1088
  LayoutAnimationsProxyCommon::clearSurfaceState();
968
1089
  if constexpr (StaticFeatureFlags::getFlag("ENABLE_SHARED_ELEMENT_TRANSITIONS")) {
969
1090
  sharedContainers_.clear();
1091
+ snapshottedScreens_.clear();
970
1092
  transition_.reset();
971
1093
  uncommittedScreenPop_.reset();
972
1094
  }
973
1095
  #ifdef ANDROID
974
1096
  cleanupPullScheduled_ = false;
1097
+ unqueuedBatchTags_.clear();
975
1098
  #endif
976
1099
  }
977
1100
 
@@ -981,6 +1104,7 @@ void LayoutAnimationsProxy::clearSurfaceState() const {
981
1104
  ShadowView LayoutAnimationsProxy::cloneViewWithoutOpacity(
982
1105
  const ShadowView &shadowView,
983
1106
  const PropsParserContext &propsParserContext) const {
1107
+ react_native_assert(isViewKind(shadowView) && "Only ViewKind views have ViewProps");
984
1108
  auto newView = shadowView;
985
1109
  folly::dynamic rawProps = folly::dynamic::object("opacity", 0);
986
1110
  #ifdef ANDROID
@@ -996,11 +1120,16 @@ ShadowView LayoutAnimationsProxy::cloneViewWithoutOpacity(
996
1120
 
997
1121
  // Android's push model applies JS-thread transactions asynchronously on the UI
998
1122
  // thread. A UI-thread pull can overtake them, so completed animations must not
999
- // add structural cleanup mutations there. This gate can go away with Android's
1000
- // pull model.
1123
+ // add structural cleanup mutations there.
1124
+ //
1125
+ // Under the pull model there is nothing left to overtake, because every
1126
+ // transaction is pulled from the UI thread's frame callback. Keeping the thread
1127
+ // check on its own there would mean this never returns true, so no exiting view
1128
+ // would ever have its removal flushed, and every one of them would stay mounted
1129
+ // for the lifetime of the surface.
1001
1130
  bool LayoutAnimationsProxy::shouldFlushStructuralMutations() const {
1002
1131
  #ifdef ANDROID
1003
- return !worklets::isOnUIThread(uiScheduler_);
1132
+ return isMountingCoordinatorPullModelEnabled() || !worklets::isOnUIThread(uiScheduler_);
1004
1133
  #else
1005
1134
  return true;
1006
1135
  #endif
@@ -1011,7 +1140,15 @@ void LayoutAnimationsProxy::cleanupAnimations(
1011
1140
  const PropsParserContext &propsParserContext,
1012
1141
  const bool flushStructuralMutations) const {
1013
1142
  ReanimatedSystraceSection s("cleanupAnimations");
1014
- std::unordered_set<Tag> preservedContainerTags;
1143
+ std::unordered_set<Tag> preservedTags;
1144
+ #ifdef ANDROID
1145
+ if (!flushStructuralMutations) {
1146
+ preservedTags = transaction.dueRemovals;
1147
+ }
1148
+ for (const auto &[tag, _] : unqueuedBatchTags_) {
1149
+ preservedTags.insert(tag);
1150
+ }
1151
+ #endif
1015
1152
  if constexpr (StaticFeatureFlags::getFlag("ENABLE_SHARED_ELEMENT_TRANSITIONS")) {
1016
1153
  for (const auto &[tag, _] : completedAnimations_) {
1017
1154
  if (hasPendingLayoutAnimation(tag)) {
@@ -1022,7 +1159,7 @@ void LayoutAnimationsProxy::cleanupAnimations(
1022
1159
  continue;
1023
1160
  }
1024
1161
  if (!flushStructuralMutations) {
1025
- preservedContainerTags.insert(tag);
1162
+ preservedTags.insert(tag);
1026
1163
  continue;
1027
1164
  }
1028
1165
  if (containerIt->second.restoreAfterNode) {
@@ -1033,7 +1170,7 @@ void LayoutAnimationsProxy::cleanupAnimations(
1033
1170
 
1034
1171
  cleanupSharedTransitions(transaction, propsParserContext);
1035
1172
  }
1036
- cleanupCompletedAnimations(transaction.filteredMutations, propsParserContext, true, preservedContainerTags);
1173
+ cleanupCompletedAnimations(transaction.filteredMutations, propsParserContext, true, preservedTags);
1037
1174
  }
1038
1175
 
1039
1176
  #ifdef ANDROID
@@ -1052,6 +1189,54 @@ void LayoutAnimationsProxy::maybeScheduleCleanupPull(const bool flushedStructura
1052
1189
  scheduleCleanupPull();
1053
1190
  }
1054
1191
  }
1192
+
1193
+ // The push model queues the batch after the pull returns, in the same JS task. A frame that the UI thread pulls
1194
+ // in between mounts before the batch, so the frames of its views wait for the next JS task.
1195
+ // https://github.com/facebook/react-native/blob/v0.88.0-rc.3/packages/react-native/ReactCommon/react/renderer/runtimescheduler/RuntimeScheduler_Modern.cpp#L315-L346
1196
+ void LayoutAnimationsProxy::holdFramesUntilBatchIsQueued(const ShadowViewMutationList &mutations) const {
1197
+ if (mutations.empty() || isMountingCoordinatorPullModelEnabled() || worklets::isOnUIThread(uiScheduler_)) {
1198
+ return;
1199
+ }
1200
+ std::vector<Tag> tags;
1201
+ for (const auto &mutation : mutations) {
1202
+ const auto isRemoval = mutation.type == ShadowViewMutation::Remove || mutation.type == ShadowViewMutation::Delete;
1203
+ const auto tag = (isRemoval ? mutation.oldChildShadowView : mutation.newChildShadowView).tag;
1204
+ const auto hasRecord =
1205
+ layoutAnimations_.contains(tag) || completedAnimations_.contains(tag) || hasPendingLayoutAnimation(tag);
1206
+ if (hasRecord) {
1207
+ tags.push_back(tag);
1208
+ unqueuedBatchTags_[tag]++;
1209
+ }
1210
+ }
1211
+ if (tags.empty()) {
1212
+ return;
1213
+ }
1214
+ jsInvoker_->invokeAsync([this, weakThis = weak_from_this(), tags = std::move(tags)](jsi::Runtime &) {
1215
+ if (const auto strongThis = weakThis.lock()) {
1216
+ releaseFramesOfQueuedBatch(tags);
1217
+ }
1218
+ });
1219
+ }
1220
+
1221
+ void LayoutAnimationsProxy::releaseFramesOfQueuedBatch(const std::vector<Tag> &tags) const {
1222
+ const auto lock = std::unique_lock<std::recursive_mutex>(mutex);
1223
+ bool hasHeldFrame = false;
1224
+ for (const auto tag : tags) {
1225
+ const auto it = unqueuedBatchTags_.find(tag);
1226
+ if (it == unqueuedBatchTags_.end()) {
1227
+ continue;
1228
+ }
1229
+ if (--it->second == 0) {
1230
+ unqueuedBatchTags_.erase(it);
1231
+ }
1232
+ const auto completedIt = completedAnimations_.find(tag);
1233
+ const auto waitsForCleanup = completedIt != completedAnimations_.end() && !completedIt->second.shouldRemove;
1234
+ hasHeldFrame = hasHeldFrame || updateMap_.contains(tag) || waitsForCleanup;
1235
+ }
1236
+ if (hasHeldFrame) {
1237
+ schedulePullOnNextFrame();
1238
+ }
1239
+ }
1055
1240
  #endif
1056
1241
 
1057
1242
  // MARK: Start Animation
@@ -1061,15 +1246,14 @@ void LayoutAnimationsProxy::startEnteringAnimation(
1061
1246
  const std::shared_ptr<Serializable> &config) const {
1062
1247
  resolveLightNodeProps(node);
1063
1248
  const auto &newChildShadowView = node->current;
1064
- const auto &props = newChildShadowView.props;
1065
- auto &viewProps = static_cast<const ViewProps &>(*props);
1066
- const auto opacity = viewProps.opacity;
1249
+ const auto opacity = getViewProps(newChildShadowView).opacity;
1067
1250
  const auto &parent = node->parent.lock();
1068
1251
  react_native_assert(parent && "Parent node is nullptr");
1252
+ const PropsParserContext propsParserContext{surfaceId_, *contextContainer_};
1069
1253
  enqueueLayoutAnimation(ManagedLayoutAnimationStart{
1070
1254
  .tag = newChildShadowView.tag,
1071
1255
  .type = LayoutAnimationType::ENTERING,
1072
- .before = newChildShadowView,
1256
+ .before = cloneViewWithoutOpacity(newChildShadowView, propsParserContext),
1073
1257
  .after = newChildShadowView,
1074
1258
  .parentTag = parent->current.tag,
1075
1259
  .opacity = opacity,