@react-native-ohos/react-native-reanimated 3.18.2-rc.2 → 4.0.0-rc.1

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 (282) hide show
  1. package/compatibility.json +161 -0
  2. package/harmony/reanimated/BuildProfile.ets +16 -16
  3. package/harmony/reanimated/build-profile.json5 +18 -11
  4. package/harmony/reanimated/oh-package.json5 +12 -11
  5. package/harmony/reanimated/src/main/cpp/CMakeLists.txt +31 -40
  6. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/AnimatedSensor/AnimatedSensorModule.cpp +81 -86
  7. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/AnimatedSensor/AnimatedSensorModule.h +46 -47
  8. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/InterpolatorRegistry.cpp +390 -0
  9. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/InterpolatorRegistry.h +16 -0
  10. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/definitions.h +30 -0
  11. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/filters/FilterOp.cpp +46 -0
  12. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/filters/FilterOp.h +23 -0
  13. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/transforms/Quaternion.cpp +53 -0
  14. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/transforms/Quaternion.h +21 -0
  15. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/transforms/TransformMatrix.cpp +166 -0
  16. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/transforms/TransformMatrix.h +71 -0
  17. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/transforms/TransformMatrix2D.cpp +368 -0
  18. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/transforms/TransformMatrix2D.h +53 -0
  19. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/transforms/TransformMatrix3D.cpp +594 -0
  20. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/transforms/TransformMatrix3D.h +67 -0
  21. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/transforms/TransformOp.cpp +52 -0
  22. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/transforms/TransformOp.h +26 -0
  23. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/transforms/vectors.cpp +156 -0
  24. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/transforms/vectors.h +76 -0
  25. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/values/CSSAngle.cpp +93 -0
  26. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/values/CSSAngle.h +33 -0
  27. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/values/CSSBoolean.cpp +48 -0
  28. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/values/CSSBoolean.h +31 -0
  29. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/values/CSSColor.cpp +135 -0
  30. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/values/CSSColor.h +61 -0
  31. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/values/CSSDiscreteArray.cpp +100 -0
  32. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/values/CSSDiscreteArray.h +44 -0
  33. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/values/CSSKeyword.cpp +81 -0
  34. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/values/CSSKeyword.h +53 -0
  35. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/values/CSSLength.cpp +122 -0
  36. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/values/CSSLength.h +38 -0
  37. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/values/CSSNumber.cpp +82 -0
  38. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/values/CSSNumber.h +63 -0
  39. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/values/CSSValue.h +118 -0
  40. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/values/CSSValueVariant.cpp +174 -0
  41. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/values/CSSValueVariant.h +111 -0
  42. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/values/complex/CSSBoxShadow.cpp +196 -0
  43. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/values/complex/CSSBoxShadow.h +66 -0
  44. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/values/complex/CSSDropShadow.cpp +134 -0
  45. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/values/complex/CSSDropShadow.h +44 -0
  46. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/configs/CSSAnimationConfig.cpp +174 -0
  47. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/configs/CSSAnimationConfig.h +49 -0
  48. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/configs/CSSKeyframesConfig.cpp +45 -0
  49. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/configs/CSSKeyframesConfig.h +26 -0
  50. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/configs/CSSTransitionConfig.cpp +90 -0
  51. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/configs/CSSTransitionConfig.h +43 -0
  52. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/configs/common.cpp +17 -0
  53. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/configs/common.h +13 -0
  54. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/core/CSSAnimation.cpp +127 -0
  55. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/core/CSSAnimation.h +51 -0
  56. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/core/CSSTransition.cpp +145 -0
  57. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/core/CSSTransition.h +47 -0
  58. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/easing/EasingFunctions.cpp +69 -0
  59. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/easing/EasingFunctions.h +22 -0
  60. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/easing/cubicBezier.cpp +66 -0
  61. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/easing/cubicBezier.h +15 -0
  62. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/easing/linear.cpp +28 -0
  63. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/easing/linear.h +15 -0
  64. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/easing/steps.cpp +13 -0
  65. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/easing/steps.h +12 -0
  66. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/InterpolatorFactory.cpp +157 -0
  67. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/InterpolatorFactory.h +189 -0
  68. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/PropertyInterpolator.cpp +76 -0
  69. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/PropertyInterpolator.h +66 -0
  70. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/configs.h +20 -0
  71. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/filters/FilterOperation.cpp +136 -0
  72. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/filters/FilterOperation.h +40 -0
  73. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/filters/FilterOperationInterpolator.cpp +38 -0
  74. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/filters/FilterOperationInterpolator.h +24 -0
  75. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/filters/FilterStyleInterpolator.cpp +58 -0
  76. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/filters/FilterStyleInterpolator.h +24 -0
  77. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/filters/operations/blur.h +14 -0
  78. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/filters/operations/brightness.h +14 -0
  79. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/filters/operations/contrast.h +14 -0
  80. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/filters/operations/dropShadow.h +17 -0
  81. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/filters/operations/grayscale.h +14 -0
  82. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/filters/operations/hueRotate.h +14 -0
  83. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/filters/operations/invert.h +14 -0
  84. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/filters/operations/opacity.h +14 -0
  85. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/filters/operations/saturate.h +14 -0
  86. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/filters/operations/sepia.h +14 -0
  87. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/groups/ArrayPropertiesInterpolator.cpp +95 -0
  88. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/groups/ArrayPropertiesInterpolator.h +36 -0
  89. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/groups/GroupPropertiesInterpolator.cpp +41 -0
  90. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/groups/GroupPropertiesInterpolator.h +32 -0
  91. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/groups/RecordPropertiesInterpolator.cpp +99 -0
  92. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/groups/RecordPropertiesInterpolator.h +37 -0
  93. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/operations/OperationsStyleInterpolator.cpp +308 -0
  94. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/operations/OperationsStyleInterpolator.h +100 -0
  95. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/operations/StyleOperation.cpp +19 -0
  96. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/operations/StyleOperation.h +94 -0
  97. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/operations/StyleOperationInterpolator.cpp +18 -0
  98. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/operations/StyleOperationInterpolator.h +43 -0
  99. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/styles/AnimationStyleInterpolator.h +26 -0
  100. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/styles/TransitionStyleInterpolator.cpp +103 -0
  101. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/styles/TransitionStyleInterpolator.h +42 -0
  102. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/transforms/TransformOperation.cpp +224 -0
  103. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/transforms/TransformOperation.h +52 -0
  104. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/transforms/TransformOperationInterpolator.cpp +218 -0
  105. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/transforms/TransformOperationInterpolator.h +89 -0
  106. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/transforms/TransformsStyleInterpolator.cpp +149 -0
  107. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/transforms/TransformsStyleInterpolator.h +33 -0
  108. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/transforms/operations/matrix.cpp +208 -0
  109. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/transforms/operations/matrix.h +56 -0
  110. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/transforms/operations/perspective.cpp +42 -0
  111. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/transforms/operations/perspective.h +20 -0
  112. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/transforms/operations/rotate.cpp +41 -0
  113. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/transforms/operations/rotate.h +39 -0
  114. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/transforms/operations/scale.cpp +28 -0
  115. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/transforms/operations/scale.h +25 -0
  116. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/transforms/operations/skew.cpp +14 -0
  117. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/transforms/operations/skew.h +20 -0
  118. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/transforms/operations/translate.cpp +39 -0
  119. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/transforms/operations/translate.h +25 -0
  120. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/values/ResolvableValueInterpolator.cpp +47 -0
  121. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/values/ResolvableValueInterpolator.h +43 -0
  122. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/values/SimpleValueInterpolator.cpp +70 -0
  123. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/values/SimpleValueInterpolator.h +40 -0
  124. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/values/ValueInterpolator.cpp +146 -0
  125. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/values/ValueInterpolator.h +71 -0
  126. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/misc/ViewStylesRepository.cpp +155 -0
  127. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/misc/ViewStylesRepository.h +53 -0
  128. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/progress/AnimationProgressProvider.cpp +170 -0
  129. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/progress/AnimationProgressProvider.h +67 -0
  130. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/progress/KeyframeProgressProvider.h +12 -0
  131. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/progress/RawProgressProvider.cpp +41 -0
  132. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/progress/RawProgressProvider.h +31 -0
  133. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/progress/TransitionProgressProvider.cpp +193 -0
  134. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/progress/TransitionProgressProvider.h +77 -0
  135. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/registries/CSSAnimationsRegistry.cpp +340 -0
  136. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/registries/CSSAnimationsRegistry.h +80 -0
  137. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/registries/CSSKeyframesRegistry.cpp +45 -0
  138. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/registries/CSSKeyframesRegistry.h +29 -0
  139. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/registries/CSSTransitionsRegistry.cpp +167 -0
  140. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/registries/CSSTransitionsRegistry.h +51 -0
  141. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/registries/StaticPropsRegistry.cpp +61 -0
  142. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/registries/StaticPropsRegistry.h +33 -0
  143. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/svg/values/SVGBrush.cpp +80 -0
  144. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/svg/values/SVGBrush.h +39 -0
  145. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/svg/values/SVGLength.cpp +93 -0
  146. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/svg/values/SVGLength.h +36 -0
  147. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/svg/values/SVGStrokeDashArray.cpp +110 -0
  148. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/svg/values/SVGStrokeDashArray.h +33 -0
  149. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/utils/DelayedItemsManager.cpp +75 -0
  150. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/utils/DelayedItemsManager.h +45 -0
  151. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/utils/algorithms.cpp +12 -0
  152. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/utils/algorithms.h +10 -0
  153. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/utils/interpolators.cpp +36 -0
  154. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/utils/interpolators.h +23 -0
  155. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/utils/props.cpp +149 -0
  156. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/utils/props.h +32 -0
  157. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ReanimatedCommitHook.cpp +113 -101
  158. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ReanimatedCommitHook.h +49 -51
  159. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ReanimatedCommitShadowNode.h +46 -49
  160. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ReanimatedMountHook.cpp +56 -96
  161. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ReanimatedMountHook.h +37 -33
  162. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ShadowTreeCloner.cpp +104 -95
  163. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ShadowTreeCloner.h +22 -29
  164. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/updates/AnimatedPropsRegistry.cpp +72 -0
  165. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/updates/AnimatedPropsRegistry.h +25 -0
  166. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/updates/UpdatesRegistry.cpp +160 -0
  167. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/updates/UpdatesRegistry.h +71 -0
  168. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/updates/UpdatesRegistryManager.cpp +161 -0
  169. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/updates/UpdatesRegistryManager.h +65 -0
  170. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationType.h +11 -9
  171. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsManager.cpp +137 -232
  172. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsManager.h +82 -90
  173. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxyCommon.cpp +79 -0
  174. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxyCommon.h +81 -0
  175. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy_Experimental.cpp +864 -0
  176. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy_Experimental.h +214 -0
  177. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/{LayoutAnimationsProxy.cpp → LayoutAnimationsProxy_Legacy.cpp} +897 -870
  178. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy_Legacy.h +220 -0
  179. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsUtils.cpp +31 -91
  180. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsUtils.h +146 -176
  181. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/PropsDiffer.cpp +456 -0
  182. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/PropsDiffer.h +102 -0
  183. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/SharedTransitions.cpp +544 -0
  184. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/NativeModules/PropValueProcessor.cpp +119 -0
  185. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/NativeModules/PropValueProcessor.h +39 -0
  186. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxy.cpp +1376 -971
  187. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxy.h +228 -252
  188. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxySpec.cpp +183 -231
  189. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxySpec.h +93 -109
  190. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/RuntimeDecorators/RNRuntimeDecorator.cpp +54 -56
  191. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/RuntimeDecorators/RNRuntimeDecorator.h +28 -20
  192. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/RuntimeDecorators/UIRuntimeDecorator.cpp +58 -70
  193. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/RuntimeDecorators/UIRuntimeDecorator.h +31 -35
  194. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/FeatureFlags.cpp +18 -0
  195. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/FeatureFlags.h +44 -0
  196. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/PlatformDepMethodsHolder.h +67 -98
  197. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/ReanimatedSystraceSection.h +114 -135
  198. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/ReanimatedVersion.cpp +46 -0
  199. package/harmony/reanimated/src/main/cpp/Common/cpp/{worklets → reanimated}/Tools/ReanimatedVersion.h +18 -19
  200. package/harmony/reanimated/src/main/cpp/ReanimatedModule.cpp +60 -85
  201. package/harmony/reanimated/src/main/cpp/ReanimatedNodesManager.cpp +1 -0
  202. package/harmony/reanimated/src/main/cpp/ReanimatedPackage.cpp +0 -3
  203. package/harmony/reanimated/src/main/cpp/ReanimatedSensor.cpp +266 -0
  204. package/harmony/reanimated/src/main/cpp/ReanimatedSensor.h +36 -0
  205. package/harmony/reanimated/src/main/cpp/ReanimatedSensorContainer.cpp +36 -0
  206. package/harmony/reanimated/src/main/cpp/ReanimatedSensorContainer.h +23 -0
  207. package/harmony/reanimated/src/main/cpp/ReanimatedUIScheduler.h +3 -3
  208. package/harmony/reanimated/src/main/ets/ReanimatedModule.ts +5 -1
  209. package/harmony/reanimated/src/main/ets/ReanimatedPackage.ts +1 -4
  210. package/harmony/reanimated/src/main/module.json5 +12 -12
  211. package/harmony/reanimated/src/main/resources/base/element/color.json +7 -7
  212. package/harmony/reanimated/src/main/resources/base/element/string.json +15 -15
  213. package/harmony/reanimated/src/main/resources/base/profile/main_pages.json +5 -5
  214. package/harmony/reanimated/src/main/resources/en_US/element/string.json +15 -15
  215. package/harmony/reanimated/src/main/resources/zh_CN/element/string.json +15 -15
  216. package/harmony/reanimated/ts.ts +6 -6
  217. package/harmony/reanimated.har +0 -0
  218. package/package.json +68 -50
  219. package/scripts/deploy.js +191 -0
  220. package/scripts/set-reanimated-version.js +37 -0
  221. package/scripts/update-version.js +119 -0
  222. package/scripts/validate-react-native-version.js +46 -0
  223. package/scripts/validate-worklets-build.js +17 -0
  224. package/scripts/validate-worklets-version.js +79 -0
  225. package/scripts/worklets-version.json +4 -0
  226. package/LICENSE +0 -21
  227. package/README.OpenSource +0 -11
  228. package/README.md +0 -10
  229. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/PropsRegistry.cpp +0 -68
  230. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/PropsRegistry.h +0 -68
  231. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy.h +0 -147
  232. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/CollectionUtils.h +0 -14
  233. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/FeaturesConfig.cpp +0 -5
  234. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/FeaturesConfig.h +0 -19
  235. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.cpp +0 -47
  236. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.h +0 -59
  237. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/NativeModules/WorkletsModuleProxySpec.cpp +0 -27
  238. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/NativeModules/WorkletsModuleProxySpec.h +0 -25
  239. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Registries/EventHandlerRegistry.cpp +0 -94
  240. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Registries/EventHandlerRegistry.h +0 -49
  241. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Registries/WorkletRuntimeRegistry.cpp +0 -8
  242. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Registries/WorkletRuntimeRegistry.h +0 -39
  243. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/SharedItems/Shareables.cpp +0 -326
  244. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/SharedItems/Shareables.h +0 -345
  245. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/AsyncQueue.cpp +0 -52
  246. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/AsyncQueue.h +0 -35
  247. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/Defs.h +0 -10
  248. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/JSISerializer.cpp +0 -342
  249. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/JSISerializer.h +0 -47
  250. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/JSLogger.cpp +0 -16
  251. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/JSLogger.h +0 -20
  252. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/JSScheduler.cpp +0 -20
  253. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/JSScheduler.h +0 -29
  254. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/PlatformLogger.h +0 -16
  255. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/ReanimatedJSIUtils.cpp +0 -26
  256. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/ReanimatedJSIUtils.h +0 -199
  257. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/ReanimatedVersion.cpp +0 -95
  258. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/SingleInstanceChecker.h +0 -72
  259. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/ThreadSafeQueue.h +0 -49
  260. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/UIScheduler.cpp +0 -20
  261. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/UIScheduler.h +0 -22
  262. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/WorkletEventHandler.cpp +0 -29
  263. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/Tools/WorkletEventHandler.h +0 -41
  264. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/RNRuntimeWorkletDecorator.cpp +0 -16
  265. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/RNRuntimeWorkletDecorator.h +0 -19
  266. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/ReanimatedHermesRuntime.cpp +0 -112
  267. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/ReanimatedHermesRuntime.h +0 -127
  268. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/ReanimatedRuntime.cpp +0 -53
  269. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/ReanimatedRuntime.h +0 -22
  270. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/RuntimeInitialization.md +0 -191
  271. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.cpp +0 -173
  272. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.h +0 -90
  273. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeCollector.h +0 -36
  274. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.cpp +0 -189
  275. package/harmony/reanimated/src/main/cpp/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.h +0 -22
  276. package/harmony/reanimated/src/main/cpp/ReanimatedLogger.cpp +0 -33
  277. package/harmony/reanimated/src/main/cpp/WorkletsModule.cpp +0 -61
  278. package/harmony/reanimated/src/main/cpp/WorkletsModule.h +0 -22
  279. package/harmony/reanimated/src/main/cpp/patches/AnimatedSensor/AnimatedSensorModule.cpp +0 -89
  280. package/harmony/reanimated/src/main/cpp/patches/Fabric/ShadowTreeCloner.cpp +0 -95
  281. package/harmony/reanimated/src/main/cpp/patches/NativeModules/ReanimatedModuleProxy.cpp +0 -964
  282. package/harmony/reanimated/src/main/ets/WorkletsModule.ts +0 -15
@@ -1,870 +1,897 @@
1
- #ifdef RCT_NEW_ARCH_ENABLED
2
-
3
- #include <reanimated/LayoutAnimations/LayoutAnimationsProxy.h>
4
- #include <reanimated/NativeModules/ReanimatedModuleProxy.h>
5
-
6
- #include <react/renderer/animations/utils.h>
7
- #include <react/renderer/mounting/ShadowViewMutation.h>
8
-
9
- #include <set>
10
- #include <utility>
11
-
12
- namespace reanimated {
13
-
14
- // We never modify the Shadow Tree, we just send some additional
15
- // mutations to the mounting layer.
16
- // When animations finish, the Host Tree will represent the most recent Shadow
17
- // Tree
18
- // On android this code will be sometimes executed on the JS thread.
19
- // That's why we have to schedule some of animation manager function on the UI
20
- // thread
21
- std::optional<MountingTransaction> LayoutAnimationsProxy::pullTransaction(
22
- SurfaceId surfaceId,
23
- MountingTransaction::Number transactionNumber,
24
- const TransactionTelemetry &telemetry,
25
- ShadowViewMutationList mutations) const {
26
- #ifdef LAYOUT_ANIMATIONS_LOGS
27
- LOG(INFO) << std::endl;
28
- LOG(INFO) << "pullTransaction " << std::this_thread::get_id() << " "
29
- << surfaceId << std::endl;
30
- #endif
31
- auto lock = std::unique_lock<std::recursive_mutex>(mutex);
32
- PropsParserContext propsParserContext{surfaceId, *contextContainer_};
33
- ShadowViewMutationList filteredMutations;
34
-
35
- std::vector<std::shared_ptr<MutationNode>> roots;
36
- std::unordered_map<Tag, ShadowView> movedViews;
37
-
38
- parseRemoveMutations(movedViews, mutations, roots);
39
-
40
- handleRemovals(filteredMutations, roots);
41
-
42
- handleUpdatesAndEnterings(
43
- filteredMutations, movedViews, mutations, propsParserContext, surfaceId);
44
-
45
- addOngoingAnimations(surfaceId, filteredMutations);
46
-
47
- return MountingTransaction{
48
- surfaceId, transactionNumber, std::move(filteredMutations), telemetry};
49
- }
50
-
51
- std::optional<SurfaceId> LayoutAnimationsProxy::progressLayoutAnimation(
52
- int tag,
53
- const jsi::Object &newStyle) {
54
- #ifdef LAYOUT_ANIMATIONS_LOGS
55
- LOG(INFO) << "progress layout animation for tag " << tag << std::endl;
56
- #endif
57
- auto lock = std::unique_lock<std::recursive_mutex>(mutex);
58
- auto layoutAnimationIt = layoutAnimations_.find(tag);
59
-
60
- if (layoutAnimationIt == layoutAnimations_.end()) {
61
- return {};
62
- }
63
-
64
- auto &layoutAnimation = layoutAnimationIt->second;
65
-
66
- maybeRestoreOpacity(layoutAnimation, newStyle);
67
-
68
- auto rawProps =
69
- std::make_shared<RawProps>(uiRuntime_, jsi::Value(uiRuntime_, newStyle));
70
-
71
- PropsParserContext propsParserContext{
72
- layoutAnimation.finalView->surfaceId, *contextContainer_};
73
- #ifdef ANDROID
74
- rawProps = std::make_shared<RawProps>(folly::dynamic::merge(
75
- layoutAnimation.finalView->props->rawProps, (folly::dynamic)*rawProps));
76
- #endif
77
- auto newProps =
78
- getComponentDescriptorForShadowView(*layoutAnimation.finalView)
79
- .cloneProps(
80
- propsParserContext,
81
- layoutAnimation.finalView->props,
82
- std::move(*rawProps));
83
- auto &updateMap =
84
- surfaceManager.getUpdateMap(layoutAnimation.finalView->surfaceId);
85
- updateMap.insert_or_assign(
86
- tag, UpdateValues{newProps, Frame(uiRuntime_, newStyle)});
87
-
88
- return layoutAnimation.finalView->surfaceId;
89
- }
90
-
91
- std::optional<SurfaceId> LayoutAnimationsProxy::endLayoutAnimation(
92
- int tag,
93
- bool shouldRemove) {
94
- #ifdef LAYOUT_ANIMATIONS_LOGS
95
- LOG(INFO) << "end layout animation for " << tag << " - should remove "
96
- << shouldRemove << std::endl;
97
- #endif
98
- auto lock = std::unique_lock<std::recursive_mutex>(mutex);
99
- auto layoutAnimationIt = layoutAnimations_.find(tag);
100
-
101
- if (layoutAnimationIt == layoutAnimations_.end()) {
102
- return {};
103
- }
104
-
105
- auto &layoutAnimation = layoutAnimationIt->second;
106
-
107
- // multiple layout animations can be triggered for a view
108
- // one after the other, so we need to keep count of how many
109
- // were actually triggered, so that we don't cleanup necessary
110
- // structures too early
111
- if (layoutAnimation.count > 1) {
112
- layoutAnimation.count--;
113
- return {};
114
- }
115
-
116
- auto surfaceId = layoutAnimation.finalView->surfaceId;
117
- auto &updateMap = surfaceManager.getUpdateMap(surfaceId);
118
- layoutAnimations_.erase(tag);
119
- updateMap.erase(tag);
120
-
121
- if (!shouldRemove || !nodeForTag_.contains(tag)) {
122
- return {};
123
- }
124
-
125
- auto node = nodeForTag_[tag];
126
- auto mutationNode = std::static_pointer_cast<MutationNode>(node);
127
- mutationNode->state = DEAD;
128
- deadNodes.insert(mutationNode);
129
-
130
- return surfaceId;
131
- }
132
-
133
- /**
134
- Organizes removed views into a tree structure, allowing for convenient
135
- traversals and index maintenance
136
- */
137
- void LayoutAnimationsProxy::parseRemoveMutations(
138
- std::unordered_map<Tag, ShadowView> &movedViews,
139
- ShadowViewMutationList &mutations,
140
- std::vector<std::shared_ptr<MutationNode>> &roots) const {
141
- std::set<Tag> deletedViews;
142
- std::unordered_map<Tag, std::vector<std::shared_ptr<MutationNode>>>
143
- childrenForTag, unflattenedChildrenForTag;
144
-
145
- std::vector<std::shared_ptr<MutationNode>> mutationNodes;
146
-
147
- // iterate from the end, so that parents appear before children
148
- for (auto it = mutations.rbegin(); it != mutations.rend(); it++) {
149
- auto &mutation = *it;
150
- if (mutation.type == ShadowViewMutation::Delete) {
151
- deletedViews.insert(mutation.oldChildShadowView.tag);
152
- }
153
- if (mutation.type == ShadowViewMutation::Remove) {
154
- updateIndexForMutation(mutation);
155
- auto tag = mutation.oldChildShadowView.tag;
156
- #if REACT_NATIVE_MINOR_VERSION >= 78
157
- auto parentTag = mutation.parentTag;
158
- #else
159
- auto parentTag = mutation.parentShadowView.tag;
160
- #endif // REACT_NATIVE_MINOR_VERSION >= 78
161
- auto unflattenedParentTag = parentTag; // temporary
162
-
163
- std::shared_ptr<MutationNode> mutationNode;
164
- std::shared_ptr<Node> node = nodeForTag_[tag],
165
- parent = nodeForTag_[parentTag],
166
- unflattenedParent =
167
- nodeForTag_[unflattenedParentTag];
168
-
169
- if (!node) {
170
- mutationNode = std::make_shared<MutationNode>(mutation);
171
- } else {
172
- mutationNode =
173
- std::make_shared<MutationNode>(mutation, std::move(*node));
174
- for (auto &subNode : mutationNode->children) {
175
- subNode->parent = mutationNode;
176
- }
177
- for (auto &subNode : mutationNode->unflattenedChildren) {
178
- subNode->unflattenedParent = mutationNode;
179
- }
180
- }
181
- if (!deletedViews.contains(mutation.oldChildShadowView.tag)) {
182
- mutationNode->state = MOVED;
183
- movedViews.insert_or_assign(
184
- mutation.oldChildShadowView.tag, mutation.oldChildShadowView);
185
- }
186
- nodeForTag_[tag] = mutationNode;
187
-
188
- if (!parent) {
189
- parent = std::make_shared<Node>(parentTag);
190
- nodeForTag_[parentTag] = parent;
191
- }
192
-
193
- if (!unflattenedParent) {
194
- if (parentTag == unflattenedParentTag) {
195
- unflattenedParent = parent;
196
- } else {
197
- unflattenedParent = std::make_shared<Node>(unflattenedParentTag);
198
- nodeForTag_[unflattenedParentTag] = unflattenedParent;
199
- }
200
- }
201
-
202
- mutationNodes.push_back(mutationNode);
203
-
204
- childrenForTag[parentTag].push_back(mutationNode);
205
- unflattenedChildrenForTag[unflattenedParentTag].push_back(mutationNode);
206
- mutationNode->parent = parent;
207
- mutationNode->unflattenedParent = unflattenedParent;
208
- }
209
- if (mutation.type == ShadowViewMutation::Update &&
210
- movedViews.contains(mutation.newChildShadowView.tag)) {
211
- auto node = nodeForTag_[mutation.newChildShadowView.tag];
212
- auto mutationNode = std::static_pointer_cast<MutationNode>(node);
213
- mutationNode->mutation.oldChildShadowView = mutation.oldChildShadowView;
214
- movedViews[mutation.newChildShadowView.tag] = mutation.oldChildShadowView;
215
- }
216
- }
217
-
218
- for (auto &[parentTag, children] : childrenForTag) {
219
- auto &parent = nodeForTag_[parentTag];
220
- parent->insertChildren(children);
221
- for (auto &child : children) {
222
- child->parent = parent;
223
- }
224
- }
225
- for (auto &[unflattenedParentTag, children] : unflattenedChildrenForTag) {
226
- auto &unflattenedParent = nodeForTag_[unflattenedParentTag];
227
- unflattenedParent->insertUnflattenedChildren(children);
228
- for (auto &child : children) {
229
- child->unflattenedParent = unflattenedParent;
230
- }
231
- }
232
-
233
- for (auto &mutationNode : mutationNodes) {
234
- if (!mutationNode->unflattenedParent->isMutationMode()) {
235
- roots.push_back(mutationNode);
236
- }
237
- }
238
- }
239
-
240
- void LayoutAnimationsProxy::handleRemovals(
241
- ShadowViewMutationList &filteredMutations,
242
- std::vector<std::shared_ptr<MutationNode>> &roots) const {
243
- // iterate from the end, so that children
244
- // with higher indices appear first in the mutations list
245
- for (auto it = roots.rbegin(); it != roots.rend(); it++) {
246
- auto &node = *it;
247
- if (!startAnimationsRecursively(
248
- node, true, true, false, filteredMutations)) {
249
- filteredMutations.push_back(node->mutation);
250
- node->unflattenedParent->removeChildFromUnflattenedTree(node); //???
251
- if (node->state != MOVED) {
252
- maybeCancelAnimation(node->tag);
253
- filteredMutations.push_back(ShadowViewMutation::DeleteMutation(
254
- node->mutation.oldChildShadowView));
255
- nodeForTag_.erase(node->tag);
256
- #ifdef LAYOUT_ANIMATIONS_LOGS
257
- LOG(INFO) << "delete " << node->tag << std::endl;
258
- #endif
259
- }
260
- }
261
- }
262
-
263
- for (auto node : deadNodes) {
264
- if (node->state != DELETED) {
265
- endAnimationsRecursively(node, filteredMutations);
266
- maybeDropAncestors(node->unflattenedParent, node, filteredMutations);
267
- }
268
- }
269
- deadNodes.clear();
270
- }
271
-
272
- void LayoutAnimationsProxy::handleUpdatesAndEnterings(
273
- ShadowViewMutationList &filteredMutations,
274
- const std::unordered_map<Tag, ShadowView> &movedViews,
275
- ShadowViewMutationList &mutations,
276
- const PropsParserContext &propsParserContext,
277
- SurfaceId surfaceId) const {
278
- std::unordered_map<Tag, ShadowView> oldShadowViewsForReparentings;
279
- for (auto &mutation : mutations) {
280
- maybeUpdateWindowDimensions(mutation, surfaceId);
281
-
282
- Tag tag = mutation.type == ShadowViewMutation::Type::Create ||
283
- mutation.type == ShadowViewMutation::Type::Insert
284
- ? mutation.newChildShadowView.tag
285
- : mutation.oldChildShadowView.tag;
286
-
287
- switch (mutation.type) {
288
- case ShadowViewMutation::Type::Create: {
289
- filteredMutations.push_back(mutation);
290
- break;
291
- }
292
- case ShadowViewMutation::Type::Insert: {
293
- updateIndexForMutation(mutation);
294
-
295
- #if REACT_NATIVE_MINOR_VERSION >= 78
296
- const auto parentTag = mutation.parentTag;
297
- const auto mutationParent = parentTag;
298
- #else
299
- const auto parentTag = mutation.parentShadowView.tag;
300
- const auto mutationParent = mutation.parentShadowView;
301
- #endif // REACT_NATIVE_MINOR_VERSION >= 78
302
- if (nodeForTag_.contains(parentTag)) {
303
- nodeForTag_[parentTag]->applyMutationToIndices(mutation);
304
- }
305
-
306
- if (movedViews.contains(tag)) {
307
- auto layoutAnimationIt = layoutAnimations_.find(tag);
308
- if (layoutAnimationIt == layoutAnimations_.end()) {
309
- if (oldShadowViewsForReparentings.contains(tag)) {
310
- filteredMutations.push_back(ShadowViewMutation::InsertMutation(
311
- mutationParent,
312
- oldShadowViewsForReparentings[tag],
313
- mutation.index));
314
- } else {
315
- filteredMutations.push_back(mutation);
316
- }
317
- continue;
318
- }
319
-
320
- auto oldView = *layoutAnimationIt->second.currentView;
321
- filteredMutations.push_back(ShadowViewMutation::InsertMutation(
322
- mutationParent, oldView, mutation.index));
323
- continue;
324
- }
325
-
326
- transferConfigFromNativeID(
327
- mutation.newChildShadowView.props->nativeId,
328
- mutation.newChildShadowView.tag);
329
- if (!layoutAnimationsManager_->hasLayoutAnimation(tag, ENTERING)) {
330
- filteredMutations.push_back(mutation);
331
- continue;
332
- }
333
-
334
- startEnteringAnimation(tag, mutation);
335
- filteredMutations.push_back(mutation);
336
-
337
- // temporarily set opacity to 0 to prevent flickering on android
338
- std::shared_ptr<ShadowView> newView =
339
- cloneViewWithoutOpacity(mutation, propsParserContext);
340
-
341
- filteredMutations.push_back(ShadowViewMutation::UpdateMutation(
342
- mutation.newChildShadowView, *newView, mutationParent));
343
- break;
344
- }
345
-
346
- case ShadowViewMutation::Type::Update: {
347
- auto shouldAnimate = hasLayoutChanged(mutation);
348
- if (!layoutAnimationsManager_->hasLayoutAnimation(tag, LAYOUT) ||
349
- (!shouldAnimate && !layoutAnimations_.contains(tag))) {
350
- // We should cancel any ongoing animation here to ensure that the
351
- // proper final state is reached for this view However, due to how
352
- // RNSScreens handle adding headers (a second commit is triggered to
353
- // offset all the elements by the header height) this would lead to
354
- // all entering animations being cancelled when a screen with a header
355
- // is pushed onto a stack
356
- // TODO: find a better solution for this problem
357
- filteredMutations.push_back(mutation);
358
- continue;
359
- } else if (!shouldAnimate) {
360
- updateOngoingAnimationTarget(tag, mutation);
361
- continue;
362
- }
363
-
364
- // store the oldChildShadowView, so that we can use this ShadowView when
365
- // the view is inserted
366
- oldShadowViewsForReparentings[tag] = mutation.oldChildShadowView;
367
- startLayoutAnimation(tag, mutation);
368
- break;
369
- }
370
-
371
- case ShadowViewMutation::Type::Remove:
372
- case ShadowViewMutation::Type::Delete: {
373
- break;
374
- }
375
-
376
- default:
377
- filteredMutations.push_back(mutation);
378
- }
379
- }
380
- }
381
-
382
- void LayoutAnimationsProxy::addOngoingAnimations(
383
- SurfaceId surfaceId,
384
- ShadowViewMutationList &mutations) const {
385
- auto &updateMap = surfaceManager.getUpdateMap(surfaceId);
386
- for (auto &[tag, updateValues] : updateMap) {
387
- auto layoutAnimationIt = layoutAnimations_.find(tag);
388
-
389
- if (layoutAnimationIt == layoutAnimations_.end()) {
390
- continue;
391
- }
392
-
393
- auto &layoutAnimation = layoutAnimationIt->second;
394
-
395
- auto newView = std::make_shared<ShadowView>(*layoutAnimation.finalView);
396
- newView->props = updateValues.newProps;
397
- updateLayoutMetrics(newView->layoutMetrics, updateValues.frame);
398
-
399
- mutations.push_back(ShadowViewMutation::UpdateMutation(
400
- *layoutAnimation.currentView,
401
- *newView,
402
- #if REACT_NATIVE_MINOR_VERSION >= 78
403
- layoutAnimation.parentTag
404
- #else
405
- *layoutAnimation.parentView
406
- #endif // REACT_NATIVE_MINOR_VERSION >= 78
407
- ));
408
- layoutAnimation.currentView = newView;
409
- }
410
- updateMap.clear();
411
- }
412
-
413
- void LayoutAnimationsProxy::endAnimationsRecursively(
414
- std::shared_ptr<MutationNode> node,
415
- ShadowViewMutationList &mutations) const {
416
- maybeCancelAnimation(node->tag);
417
- node->state = DELETED;
418
- // iterate from the end, so that children
419
- // with higher indices appear first in the mutations list
420
- for (auto it = node->unflattenedChildren.rbegin();
421
- it != node->unflattenedChildren.rend();
422
- it++) {
423
- auto &subNode = *it;
424
- if (subNode->state != DELETED) {
425
- endAnimationsRecursively(subNode, mutations);
426
- }
427
- }
428
- mutations.push_back(node->mutation);
429
- nodeForTag_.erase(node->tag);
430
- #ifdef LAYOUT_ANIMATIONS_LOGS
431
- LOG(INFO) << "delete " << node->tag << std::endl;
432
- #endif
433
- mutations.push_back(
434
- ShadowViewMutation::DeleteMutation(node->mutation.oldChildShadowView));
435
- }
436
-
437
- void LayoutAnimationsProxy::maybeDropAncestors(
438
- std::shared_ptr<Node> parent,
439
- std::shared_ptr<MutationNode> child,
440
- ShadowViewMutationList &cleanupMutations) const {
441
- parent->removeChildFromUnflattenedTree(child);
442
- if (!parent->isMutationMode()) {
443
- return;
444
- }
445
-
446
- auto node = std::static_pointer_cast<MutationNode>(parent);
447
-
448
- if (node->children.size() == 0 && node->state != ANIMATING) {
449
- nodeForTag_.erase(node->tag);
450
- cleanupMutations.push_back(node->mutation);
451
- maybeCancelAnimation(node->tag);
452
- #ifdef LAYOUT_ANIMATIONS_LOGS
453
- LOG(INFO) << "delete " << node->tag << std::endl;
454
- #endif
455
- cleanupMutations.push_back(
456
- ShadowViewMutation::DeleteMutation(node->mutation.oldChildShadowView));
457
- maybeDropAncestors(node->unflattenedParent, node, cleanupMutations);
458
- }
459
- }
460
-
461
- const ComponentDescriptor &
462
- LayoutAnimationsProxy::getComponentDescriptorForShadowView(
463
- const ShadowView &shadowView) const {
464
- return componentDescriptorRegistry_->at(shadowView.componentHandle);
465
- }
466
-
467
- bool LayoutAnimationsProxy::startAnimationsRecursively(
468
- std::shared_ptr<MutationNode> node,
469
- bool shouldRemoveSubviewsWithoutAnimations,
470
- bool shouldAnimate,
471
- bool isScreenPop,
472
- ShadowViewMutationList &mutations) const {
473
- if (isRNSScreen(node)) {
474
- isScreenPop = true;
475
- }
476
-
477
- shouldAnimate = !isScreenPop &&
478
- layoutAnimationsManager_->shouldAnimateExiting(node->tag, shouldAnimate);
479
-
480
- bool hasExitAnimation = shouldAnimate &&
481
- layoutAnimationsManager_->hasLayoutAnimation(
482
- node->tag, LayoutAnimationType::EXITING);
483
- bool hasAnimatedChildren = false;
484
-
485
- shouldRemoveSubviewsWithoutAnimations =
486
- shouldRemoveSubviewsWithoutAnimations && !hasExitAnimation;
487
- std::vector<std::shared_ptr<MutationNode>> toBeRemoved;
488
-
489
- // iterate from the end, so that children
490
- // with higher indices appear first in the mutations list
491
- for (auto it = node->unflattenedChildren.rbegin();
492
- it != node->unflattenedChildren.rend();
493
- it++) {
494
- auto &subNode = *it;
495
- #ifdef LAYOUT_ANIMATIONS_LOGS
496
- LOG(INFO) << "child " << subNode->tag << " "
497
- << " " << shouldAnimate << " "
498
- << shouldRemoveSubviewsWithoutAnimations << std::endl;
499
- #endif
500
- if (subNode->state != UNDEFINED && subNode->state != MOVED) {
501
- if (shouldAnimate && subNode->state != DEAD) {
502
- hasAnimatedChildren = true;
503
- } else {
504
- endAnimationsRecursively(subNode, mutations);
505
- toBeRemoved.push_back(subNode);
506
- }
507
- } else if (startAnimationsRecursively(
508
- subNode,
509
- shouldRemoveSubviewsWithoutAnimations,
510
- shouldAnimate,
511
- isScreenPop,
512
- mutations)) {
513
- #ifdef LAYOUT_ANIMATIONS_LOGS
514
- LOG(INFO) << "child " << subNode->tag
515
- << " start animations returned true " << std::endl;
516
- #endif
517
- hasAnimatedChildren = true;
518
- } else if (subNode->state == MOVED) {
519
- mutations.push_back(subNode->mutation);
520
- toBeRemoved.push_back(subNode);
521
- } else if (shouldRemoveSubviewsWithoutAnimations) {
522
- maybeCancelAnimation(subNode->tag);
523
- mutations.push_back(subNode->mutation);
524
- toBeRemoved.push_back(subNode);
525
- subNode->state = DELETED;
526
- nodeForTag_.erase(subNode->tag);
527
- #ifdef LAYOUT_ANIMATIONS_LOGS
528
- LOG(INFO) << "delete " << subNode->tag << std::endl;
529
- #endif
530
- mutations.push_back(ShadowViewMutation::DeleteMutation(
531
- subNode->mutation.oldChildShadowView));
532
- } else {
533
- subNode->state = WAITING;
534
- }
535
- }
536
-
537
- for (auto &subNode : toBeRemoved) {
538
- node->removeChildFromUnflattenedTree(subNode);
539
- }
540
-
541
- if (node->state == MOVED) {
542
- auto replacement = std::make_shared<Node>(*node);
543
- for (auto subNode : node->children) {
544
- subNode->parent = replacement;
545
- }
546
- for (auto subNode : node->unflattenedChildren) {
547
- subNode->unflattenedParent = replacement;
548
- }
549
- nodeForTag_[replacement->tag] = replacement;
550
- return false;
551
- }
552
-
553
- bool wantAnimateExit = hasExitAnimation || hasAnimatedChildren;
554
-
555
- if (hasExitAnimation) {
556
- node->state = ANIMATING;
557
- startExitingAnimation(node->tag, node->mutation);
558
- } else {
559
- layoutAnimationsManager_->clearLayoutAnimationConfig(node->tag);
560
- }
561
-
562
- return wantAnimateExit;
563
- }
564
-
565
- void LayoutAnimationsProxy::updateIndexForMutation(
566
- ShadowViewMutation &mutation) const {
567
- if (mutation.index == -1) {
568
- return;
569
- }
570
-
571
- #if REACT_NATIVE_MINOR_VERSION >= 78
572
- const auto parentTag = mutation.parentTag;
573
- #else
574
- const auto parentTag = mutation.parentShadowView.tag;
575
- #endif // REACT_NATIVE_MINOR_VERSION >= 78
576
-
577
- if (!nodeForTag_.contains(parentTag)) {
578
- return;
579
- }
580
-
581
- auto parent = nodeForTag_[parentTag];
582
- int size = 0, prevIndex = -1, offset = 0;
583
-
584
- for (auto &subNode : parent->children) {
585
- size += subNode->mutation.index - prevIndex - 1;
586
- if (mutation.index < size) {
587
- break;
588
- }
589
- offset++;
590
- prevIndex = subNode->mutation.index;
591
- }
592
- #ifdef LAYOUT_ANIMATIONS_LOGS
593
- int tag = mutation.type == ShadowViewMutation::Insert
594
- ? mutation.newChildShadowView.tag
595
- : mutation.oldChildShadowView.tag;
596
- LOG(INFO) << "update index for " << tag << " in " << parentTag << ": "
597
- << mutation.index << " -> " << mutation.index + offset << std::endl;
598
- #endif
599
- mutation.index += offset;
600
- }
601
-
602
- bool LayoutAnimationsProxy::shouldOverridePullTransaction() const {
603
- return true;
604
- }
605
-
606
- void LayoutAnimationsProxy::createLayoutAnimation(
607
- const ShadowViewMutation &mutation,
608
- ShadowView &oldView,
609
- const SurfaceId &surfaceId,
610
- const int tag) const {
611
- int count = 1;
612
- auto layoutAnimationIt = layoutAnimations_.find(tag);
613
-
614
- if (layoutAnimationIt != layoutAnimations_.end()) {
615
- auto &layoutAnimation = layoutAnimationIt->second;
616
- oldView = *layoutAnimation.currentView;
617
- count = layoutAnimation.count + 1;
618
- }
619
-
620
- auto finalView = std::make_shared<ShadowView>(
621
- mutation.type == ShadowViewMutation::Remove
622
- ? mutation.oldChildShadowView
623
- : mutation.newChildShadowView);
624
- auto currentView = std::make_shared<ShadowView>(oldView);
625
-
626
- #if REACT_NATIVE_MINOR_VERSION >= 78
627
- layoutAnimations_.insert_or_assign(
628
- tag,
629
- LayoutAnimation{finalView, currentView, mutation.parentTag, {}, count});
630
- #else
631
- auto parentView = std::make_shared<ShadowView>(mutation.parentShadowView);
632
- layoutAnimations_.insert_or_assign(
633
- tag, LayoutAnimation{finalView, currentView, parentView, {}, count});
634
- #endif // REACT_NATIVE_MINOR_VERSION >= 78
635
- }
636
-
637
- void LayoutAnimationsProxy::startEnteringAnimation(
638
- const int tag,
639
- ShadowViewMutation &mutation) const {
640
- #ifdef LAYOUT_ANIMATIONS_LOGS
641
- LOG(INFO) << "start entering animation for tag " << tag << std::endl;
642
- #endif
643
- auto finalView = std::make_shared<ShadowView>(mutation.newChildShadowView);
644
- auto current = std::make_shared<ShadowView>(mutation.newChildShadowView);
645
- #if REACT_NATIVE_MINOR_VERSION < 78
646
- auto parent = std::make_shared<ShadowView>(mutation.parentShadowView);
647
- #endif
648
-
649
- auto &viewProps =
650
- static_cast<const ViewProps &>(*mutation.newChildShadowView.props);
651
- auto opacity = viewProps.opacity;
652
-
653
- uiScheduler_->scheduleOnUI([weakThis = weak_from_this(),
654
- finalView,
655
- current,
656
- #if REACT_NATIVE_MINOR_VERSION < 78
657
- parent,
658
- #endif // RE
659
- mutation,
660
- opacity,
661
- tag]() {
662
- auto strongThis = weakThis.lock();
663
- if (!strongThis) {
664
- return;
665
- }
666
-
667
- Rect window{};
668
- {
669
- auto &mutex = strongThis->mutex;
670
- auto lock = std::unique_lock<std::recursive_mutex>(mutex);
671
- strongThis->layoutAnimations_.insert_or_assign(
672
- tag, LayoutAnimation {
673
- finalView, current,
674
- #if REACT_NATIVE_MINOR_VERSION >= 78
675
- mutation.parentTag,
676
- #else
677
- parent,
678
- #endif // REACT_NATIVE_MINOR_VERSION >= 78
679
- opacity
680
- });
681
- window = strongThis->surfaceManager.getWindow(
682
- mutation.newChildShadowView.surfaceId);
683
- }
684
-
685
- Snapshot values(mutation.newChildShadowView, window);
686
- auto &uiRuntime = strongThis->uiRuntime_;
687
- jsi::Object yogaValues(uiRuntime);
688
- yogaValues.setProperty(uiRuntime, "targetOriginX", values.x);
689
- yogaValues.setProperty(uiRuntime, "targetGlobalOriginX", values.x);
690
- yogaValues.setProperty(uiRuntime, "targetOriginY", values.y);
691
- yogaValues.setProperty(uiRuntime, "targetGlobalOriginY", values.y);
692
- yogaValues.setProperty(uiRuntime, "targetWidth", values.width);
693
- yogaValues.setProperty(uiRuntime, "targetHeight", values.height);
694
- yogaValues.setProperty(uiRuntime, "windowWidth", values.windowWidth);
695
- yogaValues.setProperty(uiRuntime, "windowHeight", values.windowHeight);
696
- strongThis->layoutAnimationsManager_->startLayoutAnimation(
697
- uiRuntime, tag, LayoutAnimationType::ENTERING, yogaValues);
698
- });
699
- }
700
-
701
- void LayoutAnimationsProxy::startExitingAnimation(
702
- const int tag,
703
- ShadowViewMutation &mutation) const {
704
- #ifdef LAYOUT_ANIMATIONS_LOGS
705
- LOG(INFO) << "start exiting animation for tag " << tag << std::endl;
706
- #endif
707
- auto surfaceId = mutation.oldChildShadowView.surfaceId;
708
-
709
- uiScheduler_->scheduleOnUI(
710
- [weakThis = weak_from_this(), tag, mutation, surfaceId]() {
711
- auto strongThis = weakThis.lock();
712
- if (!strongThis) {
713
- return;
714
- }
715
-
716
- auto oldView = mutation.oldChildShadowView;
717
- Rect window{};
718
- {
719
- auto &mutex = strongThis->mutex;
720
- auto lock = std::unique_lock<std::recursive_mutex>(mutex);
721
- strongThis->createLayoutAnimation(mutation, oldView, surfaceId, tag);
722
- window = strongThis->surfaceManager.getWindow(surfaceId);
723
- }
724
-
725
- Snapshot values(oldView, window);
726
-
727
- auto &uiRuntime = strongThis->uiRuntime_;
728
- jsi::Object yogaValues(uiRuntime);
729
- yogaValues.setProperty(uiRuntime, "currentOriginX", values.x);
730
- yogaValues.setProperty(uiRuntime, "currentGlobalOriginX", values.x);
731
- yogaValues.setProperty(uiRuntime, "currentOriginY", values.y);
732
- yogaValues.setProperty(uiRuntime, "currentGlobalOriginY", values.y);
733
- yogaValues.setProperty(uiRuntime, "currentWidth", values.width);
734
- yogaValues.setProperty(uiRuntime, "currentHeight", values.height);
735
- yogaValues.setProperty(uiRuntime, "windowWidth", values.windowWidth);
736
- yogaValues.setProperty(uiRuntime, "windowHeight", values.windowHeight);
737
- strongThis->layoutAnimationsManager_->startLayoutAnimation(
738
- uiRuntime, tag, LayoutAnimationType::EXITING, yogaValues);
739
- strongThis->layoutAnimationsManager_->clearLayoutAnimationConfig(tag);
740
- });
741
- }
742
-
743
- void LayoutAnimationsProxy::startLayoutAnimation(
744
- const int tag,
745
- const ShadowViewMutation &mutation) const {
746
- #ifdef LAYOUT_ANIMATIONS_LOGS
747
- LOG(INFO) << "start layout animation for tag " << tag << std::endl;
748
- #endif
749
- auto surfaceId = mutation.oldChildShadowView.surfaceId;
750
-
751
- uiScheduler_->scheduleOnUI([weakThis = weak_from_this(),
752
- mutation,
753
- surfaceId,
754
- tag]() {
755
- auto strongThis = weakThis.lock();
756
- if (!strongThis) {
757
- return;
758
- }
759
-
760
- auto oldView = mutation.oldChildShadowView;
761
- Rect window{};
762
- {
763
- auto &mutex = strongThis->mutex;
764
- auto lock = std::unique_lock<std::recursive_mutex>(mutex);
765
- strongThis->createLayoutAnimation(mutation, oldView, surfaceId, tag);
766
- window = strongThis->surfaceManager.getWindow(surfaceId);
767
- }
768
-
769
- Snapshot currentValues(oldView, window);
770
- Snapshot targetValues(mutation.newChildShadowView, window);
771
-
772
- auto &uiRuntime = strongThis->uiRuntime_;
773
- jsi::Object yogaValues(uiRuntime);
774
- yogaValues.setProperty(uiRuntime, "currentOriginX", currentValues.x);
775
- yogaValues.setProperty(uiRuntime, "currentGlobalOriginX", currentValues.x);
776
- yogaValues.setProperty(uiRuntime, "currentOriginY", currentValues.y);
777
- yogaValues.setProperty(uiRuntime, "currentGlobalOriginY", currentValues.y);
778
- yogaValues.setProperty(uiRuntime, "currentWidth", currentValues.width);
779
- yogaValues.setProperty(uiRuntime, "currentHeight", currentValues.height);
780
- yogaValues.setProperty(uiRuntime, "targetOriginX", targetValues.x);
781
- yogaValues.setProperty(uiRuntime, "targetGlobalOriginX", targetValues.x);
782
- yogaValues.setProperty(uiRuntime, "targetOriginY", targetValues.y);
783
- yogaValues.setProperty(uiRuntime, "targetGlobalOriginY", targetValues.y);
784
- yogaValues.setProperty(uiRuntime, "targetWidth", targetValues.width);
785
- yogaValues.setProperty(uiRuntime, "targetHeight", targetValues.height);
786
- yogaValues.setProperty(uiRuntime, "windowWidth", targetValues.windowWidth);
787
- yogaValues.setProperty(
788
- uiRuntime, "windowHeight", targetValues.windowHeight);
789
- strongThis->layoutAnimationsManager_->startLayoutAnimation(
790
- uiRuntime, tag, LayoutAnimationType::LAYOUT, yogaValues);
791
- });
792
- }
793
-
794
- void LayoutAnimationsProxy::updateOngoingAnimationTarget(
795
- const int tag,
796
- const ShadowViewMutation &mutation) const {
797
- layoutAnimations_[tag].finalView =
798
- std::make_shared<ShadowView>(mutation.newChildShadowView);
799
- }
800
-
801
- void LayoutAnimationsProxy::maybeCancelAnimation(const int tag) const {
802
- if (!layoutAnimations_.contains(tag)) {
803
- return;
804
- }
805
- layoutAnimations_.erase(tag);
806
- uiScheduler_->scheduleOnUI([weakThis = weak_from_this(), tag]() {
807
- auto strongThis = weakThis.lock();
808
- if (!strongThis) {
809
- return;
810
- }
811
-
812
- auto &uiRuntime = strongThis->uiRuntime_;
813
- strongThis->layoutAnimationsManager_->cancelLayoutAnimation(uiRuntime, tag);
814
- });
815
- }
816
-
817
- void LayoutAnimationsProxy::transferConfigFromNativeID(
818
- const std::string nativeIdString,
819
- const int tag) const {
820
- if (nativeIdString.empty()) {
821
- return;
822
- }
823
- try {
824
- auto nativeId = stoi(nativeIdString);
825
- layoutAnimationsManager_->transferConfigFromNativeID(nativeId, tag);
826
- } catch (std::invalid_argument) {
827
- } catch (std::out_of_range) {
828
- }
829
- }
830
-
831
- // When entering animations start, we temporarily set opacity to 0
832
- // so that we can immediately insert the view at the right position
833
- // and schedule the animation on the UI thread
834
- std::shared_ptr<ShadowView> LayoutAnimationsProxy::cloneViewWithoutOpacity(
835
- facebook::react::ShadowViewMutation &mutation,
836
- const PropsParserContext &propsParserContext) const {
837
- auto newView = std::make_shared<ShadowView>(mutation.newChildShadowView);
838
- folly::dynamic opacity = folly::dynamic::object("opacity", 0);
839
- auto newProps = getComponentDescriptorForShadowView(*newView).cloneProps(
840
- propsParserContext, newView->props, RawProps(opacity));
841
- newView->props = newProps;
842
- return newView;
843
- }
844
-
845
- void LayoutAnimationsProxy::maybeRestoreOpacity(
846
- LayoutAnimation &layoutAnimation,
847
- const jsi::Object &newStyle) const {
848
- if (layoutAnimation.opacity && !newStyle.hasProperty(uiRuntime_, "opacity")) {
849
- newStyle.setProperty(
850
- uiRuntime_, "opacity", jsi::Value(*layoutAnimation.opacity));
851
- layoutAnimation.opacity.reset();
852
- }
853
- }
854
-
855
- void LayoutAnimationsProxy::maybeUpdateWindowDimensions(
856
- facebook::react::ShadowViewMutation &mutation,
857
- SurfaceId surfaceId) const {
858
- if (mutation.type == ShadowViewMutation::Update &&
859
- !std::strcmp(
860
- mutation.oldChildShadowView.componentName, RootComponentName)) {
861
- surfaceManager.updateWindow(
862
- surfaceId,
863
- mutation.newChildShadowView.layoutMetrics.frame.size.width,
864
- mutation.newChildShadowView.layoutMetrics.frame.size.height);
865
- }
866
- }
867
-
868
- } // namespace reanimated
869
-
870
- #endif // RCT_NEW_ARCH_ENABLED
1
+ #include <reanimated/LayoutAnimations/LayoutAnimationsProxy_Legacy.h>
2
+ #include <reanimated/NativeModules/ReanimatedModuleProxy.h>
3
+
4
+ #include <react/renderer/animations/utils.h>
5
+ #include <react/renderer/mounting/ShadowViewMutation.h>
6
+
7
+ #include <memory>
8
+ #include <ranges>
9
+ #include <set>
10
+ #include <string>
11
+ #include <unordered_map>
12
+ #include <unordered_set>
13
+ #include <utility>
14
+ #include <vector>
15
+
16
+ namespace reanimated {
17
+
18
+ // We never modify the Shadow Tree, we just send some additional
19
+ // mutations to the mounting layer.
20
+ // When animations finish, the Host Tree will represent the most recent Shadow
21
+ // Tree
22
+ // On android this code will be sometimes executed on the JS thread.
23
+ // That's why we have to schedule some of animation manager function on the UI
24
+ // thread
25
+ std::optional<MountingTransaction> LayoutAnimationsProxy_Legacy::pullTransaction(
26
+ SurfaceId surfaceId,
27
+ MountingTransaction::Number transactionNumber,
28
+ const TransactionTelemetry &telemetry,
29
+ ShadowViewMutationList mutations) const {
30
+ #ifdef LAYOUT_ANIMATIONS_LOGS
31
+ LOG(INFO) << std::endl;
32
+ LOG(INFO) << "pullTransaction " << std::this_thread::get_id() << " " << surfaceId << std::endl;
33
+ #endif
34
+ auto lock = std::unique_lock<std::recursive_mutex>(mutex);
35
+ PropsParserContext propsParserContext{surfaceId, *contextContainer_};
36
+ ShadowViewMutationList filteredMutations;
37
+ auto &[deadNodes] = surfaceContext_[surfaceId];
38
+
39
+ std::vector<std::shared_ptr<MutationNode>> roots;
40
+ std::unordered_map<Tag, Tag> movedViews;
41
+
42
+ addOngoingAnimations(surfaceId, filteredMutations);
43
+
44
+ #ifdef ANDROID
45
+ restoreOpacityInCaseOfFlakyEnteringAnimation(surfaceId);
46
+ #endif // ANDROID
47
+ for (const auto tag : finishedAnimationTags_) {
48
+ auto &updateMap = surfaceManager.getUpdateMap(surfaceId);
49
+ layoutAnimations_.erase(tag);
50
+ updateMap.erase(tag);
51
+ }
52
+ finishedAnimationTags_.clear();
53
+
54
+ parseRemoveMutations(movedViews, mutations, roots);
55
+
56
+ auto shouldAnimate = !surfacesToRemove_.contains(surfaceId);
57
+ surfacesToRemove_.erase(surfaceId);
58
+ handleRemovals(filteredMutations, roots, deadNodes, shouldAnimate);
59
+
60
+ handleUpdatesAndEnterings(filteredMutations, movedViews, mutations, propsParserContext, surfaceId);
61
+
62
+ addOngoingAnimations(surfaceId, filteredMutations);
63
+
64
+ return MountingTransaction{surfaceId, transactionNumber, std::move(filteredMutations), telemetry};
65
+ }
66
+
67
+ std::optional<SurfaceId> LayoutAnimationsProxy_Legacy::progressLayoutAnimation(int tag, const jsi::Object &newStyle) {
68
+ #ifdef LAYOUT_ANIMATIONS_LOGS
69
+ LOG(INFO) << "progress layout animation for tag " << tag << std::endl;
70
+ #endif
71
+ auto lock = std::unique_lock<std::recursive_mutex>(mutex);
72
+ auto layoutAnimationIt = layoutAnimations_.find(tag);
73
+
74
+ if (layoutAnimationIt == layoutAnimations_.end()) {
75
+ return {};
76
+ }
77
+
78
+ auto &layoutAnimation = layoutAnimationIt->second;
79
+
80
+ maybeRestoreOpacity(layoutAnimation, newStyle);
81
+
82
+ auto rawProps = std::make_shared<RawProps>(uiRuntime_, jsi::Value(uiRuntime_, newStyle));
83
+
84
+ PropsParserContext propsParserContext{layoutAnimation.finalView.surfaceId, *contextContainer_};
85
+ #ifdef RN_SERIALIZABLE_STATE
86
+ rawProps = std::make_shared<RawProps>(
87
+ folly::dynamic::merge(layoutAnimation.finalView.props->rawProps, (folly::dynamic)*rawProps));
88
+ #endif
89
+ auto newProps = getComponentDescriptorForShadowView(layoutAnimation.finalView)
90
+ .cloneProps(propsParserContext, layoutAnimation.finalView.props, std::move(*rawProps));
91
+ auto &updateMap = surfaceManager.getUpdateMap(layoutAnimation.finalView.surfaceId);
92
+ updateMap.insert_or_assign(tag, UpdateValues{newProps, Frame(uiRuntime_, newStyle)});
93
+
94
+ return layoutAnimation.finalView.surfaceId;
95
+ }
96
+
97
+ std::optional<SurfaceId> LayoutAnimationsProxy_Legacy::endLayoutAnimation(int tag, bool shouldRemove) {
98
+ #ifdef LAYOUT_ANIMATIONS_LOGS
99
+ LOG(INFO) << "end layout animation for " << tag << " - should remove " << shouldRemove << std::endl;
100
+ #endif
101
+ auto lock = std::unique_lock<std::recursive_mutex>(mutex);
102
+ auto layoutAnimationIt = layoutAnimations_.find(tag);
103
+
104
+ if (layoutAnimationIt == layoutAnimations_.end()) {
105
+ return {};
106
+ }
107
+
108
+ auto &layoutAnimation = layoutAnimationIt->second;
109
+
110
+ // multiple layout animations can be triggered for a view
111
+ // one after the other, so we need to keep count of how many
112
+ // were actually triggered, so that we don't cleanup necessary
113
+ // structures too early
114
+ if (layoutAnimation.count > 1) {
115
+ layoutAnimation.count--;
116
+ return {};
117
+ }
118
+ finishedAnimationTags_.push_back(tag);
119
+ auto surfaceId = layoutAnimation.finalView.surfaceId;
120
+
121
+ if (!shouldRemove || !nodeForTag_.contains(tag)) {
122
+ return {};
123
+ }
124
+
125
+ auto node = nodeForTag_[tag];
126
+ auto mutationNode = std::static_pointer_cast<MutationNode>(node);
127
+ mutationNode->state = DEAD;
128
+ auto &[deadNodes] = surfaceContext_[surfaceId];
129
+ deadNodes.insert(mutationNode);
130
+
131
+ return surfaceId;
132
+ }
133
+
134
+ /**
135
+ Organizes removed views into a tree structure, allowing for convenient
136
+ traversals and index maintenance
137
+ */
138
+ void LayoutAnimationsProxy_Legacy::parseRemoveMutations(
139
+ std::unordered_map<Tag, Tag> &movedViews,
140
+ ShadowViewMutationList &mutations,
141
+ std::vector<std::shared_ptr<MutationNode>> &roots) const {
142
+ std::set<Tag> deletedViews;
143
+ std::unordered_map<Tag, std::vector<std::shared_ptr<MutationNode>>> childrenForTag, unflattenedChildrenForTag;
144
+
145
+ std::vector<std::shared_ptr<MutationNode>> mutationNodes;
146
+
147
+ // iterate from the end, so that parents appear before children
148
+ for (auto it = mutations.rbegin(); it != mutations.rend(); it++) {
149
+ auto &mutation = *it;
150
+ if (mutation.type == ShadowViewMutation::Delete) {
151
+ deletedViews.insert(mutation.oldChildShadowView.tag);
152
+ }
153
+ if (mutation.type == ShadowViewMutation::Remove) {
154
+ updateIndexForMutation(mutation);
155
+ auto tag = mutation.oldChildShadowView.tag;
156
+ auto parentTag = mutation.parentTag;
157
+ auto unflattenedParentTag = parentTag; // temporary
158
+
159
+ std::shared_ptr<MutationNode> mutationNode;
160
+ std::shared_ptr<Node> node = nodeForTag_[tag], parent = nodeForTag_[parentTag],
161
+ unflattenedParent = nodeForTag_[unflattenedParentTag];
162
+
163
+ if (!node) {
164
+ mutationNode = std::make_shared<MutationNode>(mutation);
165
+ } else {
166
+ mutationNode = std::make_shared<MutationNode>(mutation, std::move(*node));
167
+ for (auto &subNode : mutationNode->children) {
168
+ subNode->parent = mutationNode;
169
+ }
170
+ for (auto &subNode : mutationNode->unflattenedChildren) {
171
+ subNode->unflattenedParent = mutationNode;
172
+ }
173
+ }
174
+ if (!deletedViews.contains(mutation.oldChildShadowView.tag)) {
175
+ mutationNode->state = MOVED;
176
+ movedViews.insert_or_assign(mutation.oldChildShadowView.tag, -1);
177
+ }
178
+ nodeForTag_[tag] = mutationNode;
179
+
180
+ if (!parent) {
181
+ parent = std::make_shared<Node>(parentTag);
182
+ nodeForTag_[parentTag] = parent;
183
+ }
184
+
185
+ if (!unflattenedParent) {
186
+ if (parentTag == unflattenedParentTag) {
187
+ unflattenedParent = parent;
188
+ } else {
189
+ unflattenedParent = std::make_shared<Node>(unflattenedParentTag);
190
+ nodeForTag_[unflattenedParentTag] = unflattenedParent;
191
+ }
192
+ }
193
+
194
+ mutationNodes.push_back(mutationNode);
195
+
196
+ childrenForTag[parentTag].push_back(mutationNode);
197
+ unflattenedChildrenForTag[unflattenedParentTag].push_back(mutationNode);
198
+ mutationNode->parent = parent;
199
+ mutationNode->unflattenedParent = unflattenedParent;
200
+ }
201
+ if (mutation.type == ShadowViewMutation::Update && movedViews.contains(mutation.newChildShadowView.tag)) {
202
+ auto node = nodeForTag_[mutation.newChildShadowView.tag];
203
+ auto mutationNode = std::static_pointer_cast<MutationNode>(node);
204
+ mutationNode->mutation.oldChildShadowView = mutation.oldChildShadowView;
205
+ }
206
+ }
207
+
208
+ for (const auto &mutation : mutations) {
209
+ if (mutation.type == ShadowViewMutation::Insert && movedViews.contains(mutation.newChildShadowView.tag)) {
210
+ movedViews[mutation.newChildShadowView.tag] = mutation.parentTag;
211
+ }
212
+ }
213
+
214
+ for (auto &[parentTag, children] : childrenForTag) {
215
+ auto &parent = nodeForTag_[parentTag];
216
+ parent->insertChildren(children);
217
+ for (auto &child : children) {
218
+ child->parent = parent;
219
+ }
220
+ }
221
+ for (auto &[unflattenedParentTag, children] : unflattenedChildrenForTag) {
222
+ auto &unflattenedParent = nodeForTag_[unflattenedParentTag];
223
+ unflattenedParent->insertUnflattenedChildren(children);
224
+ for (auto &child : children) {
225
+ child->unflattenedParent = unflattenedParent;
226
+ }
227
+ }
228
+
229
+ for (auto &mutationNode : mutationNodes) {
230
+ if (!mutationNode->unflattenedParent->isMutationNode()) {
231
+ roots.push_back(mutationNode);
232
+ }
233
+ }
234
+ }
235
+
236
+ void LayoutAnimationsProxy_Legacy::handleRemovals(
237
+ ShadowViewMutationList &filteredMutations,
238
+ std::vector<std::shared_ptr<MutationNode>> &roots,
239
+ std::unordered_set<std::shared_ptr<MutationNode>> &deadNodes,
240
+ bool shouldAnimate) const {
241
+ // iterate from the end, so that children
242
+ // with higher indices appear first in the mutations list
243
+ for (auto it = roots.rbegin(); it != roots.rend(); it++) {
244
+ auto &node = *it;
245
+ if (!startAnimationsRecursively(node, true, shouldAnimate, false, filteredMutations)) {
246
+ filteredMutations.push_back(node->mutation);
247
+ node->unflattenedParent->removeChildFromUnflattenedTree(node); //???
248
+ if (node->state != MOVED) {
249
+ maybeCancelAnimation(node->tag);
250
+ filteredMutations.push_back(ShadowViewMutation::DeleteMutation(node->mutation.oldChildShadowView));
251
+ nodeForTag_.erase(node->tag);
252
+ node->state = DELETED;
253
+ #ifdef LAYOUT_ANIMATIONS_LOGS
254
+ LOG(INFO) << "delete " << node->tag << std::endl;
255
+ #endif
256
+ }
257
+ }
258
+ }
259
+
260
+ for (const auto &node : deadNodes) {
261
+ if (node->state != DELETED) {
262
+ endAnimationsRecursively(node, filteredMutations);
263
+ maybeDropAncestors(node->unflattenedParent, node, filteredMutations);
264
+ }
265
+ }
266
+ deadNodes.clear();
267
+ }
268
+
269
+ void LayoutAnimationsProxy_Legacy::handleUpdatesAndEnterings(
270
+ ShadowViewMutationList &filteredMutations,
271
+ const std::unordered_map<Tag, Tag> &movedViews,
272
+ ShadowViewMutationList &mutations,
273
+ const PropsParserContext &propsParserContext,
274
+ SurfaceId surfaceId) const {
275
+ std::unordered_map<Tag, ShadowView> oldShadowViewsForReparentings;
276
+ for (auto &mutation : mutations) {
277
+ maybeUpdateWindowDimensions(mutation, surfaceId);
278
+
279
+ Tag tag = mutation.type == ShadowViewMutation::Type::Create || mutation.type == ShadowViewMutation::Type::Insert
280
+ ? mutation.newChildShadowView.tag
281
+ : mutation.oldChildShadowView.tag;
282
+
283
+ switch (mutation.type) {
284
+ case ShadowViewMutation::Type::Create: {
285
+ filteredMutations.push_back(mutation);
286
+ break;
287
+ }
288
+ case ShadowViewMutation::Type::Insert: {
289
+ updateIndexForMutation(mutation);
290
+
291
+ const auto parentTag = mutation.parentTag;
292
+ const auto mutationParent = parentTag;
293
+ if (nodeForTag_.contains(parentTag)) {
294
+ nodeForTag_[parentTag]->applyMutationToIndices(mutation);
295
+ }
296
+
297
+ if (movedViews.contains(tag)) {
298
+ auto layoutAnimationIt = layoutAnimations_.find(tag);
299
+ if (layoutAnimationIt == layoutAnimations_.end()) {
300
+ if (oldShadowViewsForReparentings.contains(tag)) {
301
+ filteredMutations.push_back(ShadowViewMutation::InsertMutation(
302
+ mutationParent, oldShadowViewsForReparentings[tag], mutation.index));
303
+ } else {
304
+ filteredMutations.push_back(mutation);
305
+ }
306
+ continue;
307
+ }
308
+
309
+ auto oldView = layoutAnimationIt->second.currentView;
310
+ filteredMutations.push_back(ShadowViewMutation::InsertMutation(mutationParent, oldView, mutation.index));
311
+ if (movedViews.contains(tag)) {
312
+ layoutAnimationIt->second.parentTag = movedViews.at(tag);
313
+ }
314
+ continue;
315
+ }
316
+
317
+ transferConfigFromNativeID(mutation.newChildShadowView.props->nativeId, mutation.newChildShadowView.tag);
318
+ if (!layoutAnimationsManager_->hasLayoutAnimation(tag, LayoutAnimationType::ENTERING)) {
319
+ filteredMutations.push_back(mutation);
320
+ continue;
321
+ }
322
+
323
+ startEnteringAnimation(tag, mutation);
324
+ filteredMutations.push_back(mutation);
325
+
326
+ // temporarily set opacity to 0 to prevent flickering on android
327
+ std::shared_ptr<ShadowView> newView = cloneViewWithoutOpacity(mutation, propsParserContext);
328
+
329
+ filteredMutations.push_back(
330
+ ShadowViewMutation::UpdateMutation(mutation.newChildShadowView, *newView, mutationParent));
331
+ break;
332
+ }
333
+
334
+ case ShadowViewMutation::Type::Update: {
335
+ auto shouldAnimate = hasLayoutChanged(mutation);
336
+ if (!layoutAnimationsManager_->hasLayoutAnimation(tag, LayoutAnimationType::LAYOUT) ||
337
+ (!shouldAnimate && !layoutAnimations_.contains(tag))) {
338
+ // We should cancel any ongoing animation here to ensure that the
339
+ // proper final state is reached for this view However, due to how
340
+ // RNSScreens handle adding headers (a second commit is triggered to
341
+ // offset all the elements by the header height) this would lead to
342
+ // all entering animations being cancelled when a screen with a header
343
+ // is pushed onto a stack
344
+ // TODO: find a better solution for this problem
345
+ filteredMutations.push_back(mutation);
346
+ continue;
347
+ } else if (!shouldAnimate) {
348
+ updateOngoingAnimationTarget(tag, mutation);
349
+ continue;
350
+ }
351
+
352
+ // store the oldChildShadowView, so that we can use this ShadowView when
353
+ // the view is inserted
354
+ oldShadowViewsForReparentings[tag] = mutation.oldChildShadowView;
355
+ if (movedViews.contains(tag)) {
356
+ mutation.parentTag = movedViews.at(tag);
357
+ }
358
+ if (mutation.parentTag != -1) {
359
+ startLayoutAnimation(tag, mutation);
360
+ }
361
+ break;
362
+ }
363
+
364
+ case ShadowViewMutation::Type::Remove:
365
+ case ShadowViewMutation::Type::Delete: {
366
+ break;
367
+ }
368
+
369
+ default:
370
+ filteredMutations.push_back(mutation);
371
+ }
372
+ }
373
+ }
374
+
375
+ void LayoutAnimationsProxy_Legacy::addOngoingAnimations(SurfaceId surfaceId, ShadowViewMutationList &mutations) const {
376
+ auto &updateMap = surfaceManager.getUpdateMap(surfaceId);
377
+ #ifdef ANDROID
378
+ std::vector<int> tagsToUpdate;
379
+ tagsToUpdate.reserve(updateMap.size());
380
+
381
+ for (auto &[tag, updateValues] : updateMap) {
382
+ tagsToUpdate.push_back(tag);
383
+ }
384
+
385
+ auto maybeCorrectedTags = preserveMountedTags_(tagsToUpdate);
386
+ if (!maybeCorrectedTags.has_value()) {
387
+ return;
388
+ }
389
+
390
+ auto correctedTags = maybeCorrectedTags->get();
391
+
392
+ // since the map is not updated, we can assume that the ordering of tags in
393
+ // correctedTags matches the iterator
394
+ int i = -1;
395
+ #endif
396
+ for (auto &[tag, updateValues] : updateMap) {
397
+ #ifdef ANDROID
398
+ i++;
399
+ if (correctedTags[i] == -1) {
400
+ // skip views that have not been mounted yet
401
+ // on Android we start entering animations from the JS thread
402
+ // so it might happen, that the first frame of the animation goes through
403
+ // before the view is first mounted
404
+ // https://github.com/software-mansion/react-native-reanimated/issues/7493
405
+ continue;
406
+ }
407
+ #endif
408
+
409
+ auto layoutAnimationIt = layoutAnimations_.find(tag);
410
+
411
+ if (layoutAnimationIt == layoutAnimations_.end()) {
412
+ continue;
413
+ }
414
+
415
+ auto &layoutAnimation = layoutAnimationIt->second;
416
+ layoutAnimation.isViewAlreadyMounted = true;
417
+ auto newView = layoutAnimation.finalView;
418
+ newView.props = updateValues.newProps;
419
+ updateLayoutMetrics(newView.layoutMetrics, updateValues.frame);
420
+
421
+ mutations.push_back(
422
+ ShadowViewMutation::UpdateMutation(layoutAnimation.currentView, newView, layoutAnimation.parentTag));
423
+ layoutAnimation.currentView = newView;
424
+ }
425
+ updateMap.clear();
426
+ }
427
+
428
+ void LayoutAnimationsProxy_Legacy::endAnimationsRecursively(
429
+ const std::shared_ptr<MutationNode> &node,
430
+ ShadowViewMutationList &mutations) const {
431
+ maybeCancelAnimation(node->tag);
432
+ node->state = DELETED;
433
+ // iterate from the end, so that children
434
+ // with higher indices appear first in the mutations list
435
+ for (auto it = node->unflattenedChildren.rbegin(); it != node->unflattenedChildren.rend(); it++) {
436
+ auto &subNode = *it;
437
+ if (subNode->state != DELETED) {
438
+ endAnimationsRecursively(subNode, mutations);
439
+ }
440
+ }
441
+ mutations.push_back(node->mutation);
442
+ nodeForTag_.erase(node->tag);
443
+ #ifdef LAYOUT_ANIMATIONS_LOGS
444
+ LOG(INFO) << "delete " << node->tag << std::endl;
445
+ #endif
446
+ mutations.push_back(ShadowViewMutation::DeleteMutation(node->mutation.oldChildShadowView));
447
+ }
448
+
449
+ void LayoutAnimationsProxy_Legacy::maybeDropAncestors(
450
+ const std::shared_ptr<Node> &parent,
451
+ const std::shared_ptr<MutationNode> &child,
452
+ ShadowViewMutationList &cleanupMutations) const {
453
+ parent->removeChildFromUnflattenedTree(child);
454
+ if (!parent->isMutationNode()) {
455
+ return;
456
+ }
457
+
458
+ auto node = std::static_pointer_cast<MutationNode>(parent);
459
+
460
+ if (node->children.size() == 0 && node->state != ANIMATING) {
461
+ nodeForTag_.erase(node->tag);
462
+ cleanupMutations.push_back(node->mutation);
463
+ maybeCancelAnimation(node->tag);
464
+ node->state = DELETED;
465
+ #ifdef LAYOUT_ANIMATIONS_LOGS
466
+ LOG(INFO) << "delete " << node->tag << std::endl;
467
+ #endif
468
+ cleanupMutations.push_back(ShadowViewMutation::DeleteMutation(node->mutation.oldChildShadowView));
469
+ maybeDropAncestors(node->unflattenedParent, node, cleanupMutations);
470
+ }
471
+ }
472
+
473
+ const ComponentDescriptor &LayoutAnimationsProxy_Legacy::getComponentDescriptorForShadowView(
474
+ const ShadowView &shadowView) const {
475
+ return componentDescriptorRegistry_->at(shadowView.componentHandle);
476
+ }
477
+
478
+ bool LayoutAnimationsProxy_Legacy::startAnimationsRecursively(
479
+ const std::shared_ptr<MutationNode> &node,
480
+ bool shouldRemoveSubviewsWithoutAnimations,
481
+ bool shouldAnimate,
482
+ bool isScreenPop,
483
+ ShadowViewMutationList &mutations) const {
484
+ if (isRNSScreen(node)) {
485
+ isScreenPop = true;
486
+ }
487
+
488
+ shouldAnimate = !isScreenPop && layoutAnimationsManager_->shouldAnimateExiting(node->tag, shouldAnimate);
489
+
490
+ bool hasExitAnimation =
491
+ shouldAnimate && layoutAnimationsManager_->hasLayoutAnimation(node->tag, LayoutAnimationType::EXITING);
492
+ bool hasAnimatedChildren = false;
493
+
494
+ shouldRemoveSubviewsWithoutAnimations =
495
+ shouldRemoveSubviewsWithoutAnimations && (!hasExitAnimation || node->state == MOVED);
496
+ std::vector<std::shared_ptr<MutationNode>> toBeRemoved;
497
+
498
+ // iterate from the end, so that children
499
+ // with higher indices appear first in the mutations list
500
+ for (auto it = node->unflattenedChildren.rbegin(); it != node->unflattenedChildren.rend(); it++) {
501
+ auto &subNode = *it;
502
+ #ifdef LAYOUT_ANIMATIONS_LOGS
503
+ LOG(INFO) << "child " << subNode->tag << " "
504
+ << " " << shouldAnimate << " " << shouldRemoveSubviewsWithoutAnimations << std::endl;
505
+ #endif
506
+ if (subNode->state != UNDEFINED && subNode->state != MOVED) {
507
+ if (shouldAnimate && subNode->state != DEAD) {
508
+ hasAnimatedChildren = true;
509
+ } else {
510
+ endAnimationsRecursively(subNode, mutations);
511
+ toBeRemoved.push_back(subNode);
512
+ }
513
+ } else if (startAnimationsRecursively(
514
+ subNode, shouldRemoveSubviewsWithoutAnimations, shouldAnimate, isScreenPop, mutations)) {
515
+ #ifdef LAYOUT_ANIMATIONS_LOGS
516
+ LOG(INFO) << "child " << subNode->tag << " start animations returned true " << std::endl;
517
+ #endif
518
+ hasAnimatedChildren = true;
519
+ } else if (subNode->state == MOVED) {
520
+ mutations.push_back(subNode->mutation);
521
+ toBeRemoved.push_back(subNode);
522
+ } else if (shouldRemoveSubviewsWithoutAnimations) {
523
+ maybeCancelAnimation(subNode->tag);
524
+ mutations.push_back(subNode->mutation);
525
+ toBeRemoved.push_back(subNode);
526
+ subNode->state = DELETED;
527
+ nodeForTag_.erase(subNode->tag);
528
+ #ifdef LAYOUT_ANIMATIONS_LOGS
529
+ LOG(INFO) << "delete " << subNode->tag << std::endl;
530
+ #endif
531
+ mutations.push_back(ShadowViewMutation::DeleteMutation(subNode->mutation.oldChildShadowView));
532
+ } else {
533
+ subNode->state = WAITING;
534
+ }
535
+ }
536
+
537
+ for (auto &subNode : toBeRemoved) {
538
+ node->removeChildFromUnflattenedTree(subNode);
539
+ }
540
+
541
+ if (node->state == MOVED) {
542
+ auto replacement = std::make_shared<Node>(*node);
543
+ for (const auto &subNode : node->children) {
544
+ subNode->parent = replacement;
545
+ }
546
+ for (const auto &subNode : node->unflattenedChildren) {
547
+ subNode->unflattenedParent = replacement;
548
+ }
549
+ nodeForTag_[replacement->tag] = replacement;
550
+ return false;
551
+ }
552
+
553
+ bool wantAnimateExit = hasExitAnimation || hasAnimatedChildren;
554
+
555
+ if (hasExitAnimation) {
556
+ node->state = ANIMATING;
557
+ startExitingAnimation(node->tag, node->mutation);
558
+ } else {
559
+ layoutAnimationsManager_->clearLayoutAnimationConfig(node->tag);
560
+ }
561
+
562
+ return wantAnimateExit;
563
+ }
564
+
565
+ void LayoutAnimationsProxy_Legacy::updateIndexForMutation(ShadowViewMutation &mutation) const {
566
+ if (mutation.index == -1) {
567
+ return;
568
+ }
569
+
570
+ const auto parentTag = mutation.parentTag;
571
+
572
+ if (!nodeForTag_.contains(parentTag)) {
573
+ return;
574
+ }
575
+
576
+ auto parent = nodeForTag_[parentTag];
577
+ int size = 0, prevIndex = -1, offset = 0;
578
+
579
+ for (auto &subNode : parent->children) {
580
+ size += subNode->mutation.index - prevIndex - 1;
581
+ if (mutation.index < size) {
582
+ break;
583
+ }
584
+ offset++;
585
+ prevIndex = subNode->mutation.index;
586
+ }
587
+ #ifdef LAYOUT_ANIMATIONS_LOGS
588
+ int tag =
589
+ mutation.type == ShadowViewMutation::Insert ? mutation.newChildShadowView.tag : mutation.oldChildShadowView.tag;
590
+ LOG(INFO) << "update index for " << tag << " in " << parentTag << ": " << mutation.index << " -> "
591
+ << mutation.index + offset << std::endl;
592
+ #endif
593
+ mutation.index += offset;
594
+ }
595
+
596
+ bool LayoutAnimationsProxy_Legacy::shouldOverridePullTransaction() const {
597
+ return true;
598
+ }
599
+
600
+ void LayoutAnimationsProxy_Legacy::createLayoutAnimation(
601
+ const ShadowViewMutation &mutation,
602
+ ShadowView &oldView,
603
+ const SurfaceId &surfaceId,
604
+ const int tag) const {
605
+ int count = 1;
606
+ auto layoutAnimationIt = layoutAnimations_.find(tag);
607
+
608
+ if (layoutAnimationIt != layoutAnimations_.end()) {
609
+ auto &layoutAnimation = layoutAnimationIt->second;
610
+ oldView = layoutAnimation.currentView;
611
+ count = layoutAnimation.count + 1;
612
+ }
613
+
614
+ auto finalView =
615
+ mutation.type == ShadowViewMutation::Remove ? mutation.oldChildShadowView : mutation.newChildShadowView;
616
+ auto currentView = oldView;
617
+
618
+ layoutAnimations_.insert_or_assign(
619
+ tag,
620
+ LayoutAnimation{
621
+ .finalView = finalView,
622
+ .currentView = currentView,
623
+ .parentTag = mutation.parentTag,
624
+ .opacity = {},
625
+ .isViewAlreadyMounted = false,
626
+ .count = count});
627
+ }
628
+
629
+ void LayoutAnimationsProxy_Legacy::startEnteringAnimation(const int tag, ShadowViewMutation &mutation) const {
630
+ #ifdef LAYOUT_ANIMATIONS_LOGS
631
+ LOG(INFO) << "start entering animation for tag " << tag << std::endl;
632
+ #endif
633
+ auto finalView = mutation.newChildShadowView;
634
+ auto current = mutation.newChildShadowView;
635
+
636
+ auto &viewProps = static_cast<const ViewProps &>(*mutation.newChildShadowView.props);
637
+ auto opacity = viewProps.opacity;
638
+
639
+ uiScheduler_->scheduleOnUI([weakThis = weak_from_this(), finalView, current, mutation, opacity, tag]() {
640
+ auto strongThis = weakThis.lock();
641
+ if (!strongThis) {
642
+ return;
643
+ }
644
+
645
+ Rect window{};
646
+ {
647
+ auto &mutex = strongThis->mutex;
648
+ auto lock = std::unique_lock<std::recursive_mutex>(mutex);
649
+ strongThis->layoutAnimations_.insert_or_assign(
650
+ tag,
651
+ LayoutAnimation{
652
+ .finalView = finalView, .currentView = current, .parentTag = mutation.parentTag, .opacity = opacity});
653
+ window = strongThis->surfaceManager.getWindow(mutation.newChildShadowView.surfaceId);
654
+ }
655
+
656
+ Snapshot values(mutation.newChildShadowView, window);
657
+ auto &uiRuntime = strongThis->uiRuntime_;
658
+ jsi::Object yogaValues(uiRuntime);
659
+ yogaValues.setProperty(uiRuntime, "targetOriginX", values.x);
660
+ yogaValues.setProperty(uiRuntime, "targetGlobalOriginX", values.x);
661
+ yogaValues.setProperty(uiRuntime, "targetOriginY", values.y);
662
+ yogaValues.setProperty(uiRuntime, "targetGlobalOriginY", values.y);
663
+ yogaValues.setProperty(uiRuntime, "targetWidth", values.width);
664
+ yogaValues.setProperty(uiRuntime, "targetHeight", values.height);
665
+ yogaValues.setProperty(uiRuntime, "windowWidth", values.windowWidth);
666
+ yogaValues.setProperty(uiRuntime, "windowHeight", values.windowHeight);
667
+ strongThis->layoutAnimationsManager_->startLayoutAnimation(
668
+ uiRuntime, tag, LayoutAnimationType::ENTERING, yogaValues);
669
+ });
670
+ }
671
+
672
+ void LayoutAnimationsProxy_Legacy::startExitingAnimation(const int tag, ShadowViewMutation &mutation) const {
673
+ #ifdef LAYOUT_ANIMATIONS_LOGS
674
+ LOG(INFO) << "start exiting animation for tag " << tag << std::endl;
675
+ #endif
676
+ auto surfaceId = mutation.oldChildShadowView.surfaceId;
677
+
678
+ uiScheduler_->scheduleOnUI([weakThis = weak_from_this(), tag, mutation, surfaceId]() {
679
+ auto strongThis = weakThis.lock();
680
+ if (!strongThis) {
681
+ return;
682
+ }
683
+
684
+ auto oldView = mutation.oldChildShadowView;
685
+ Rect window{};
686
+ {
687
+ auto &mutex = strongThis->mutex;
688
+ auto lock = std::unique_lock<std::recursive_mutex>(mutex);
689
+ strongThis->createLayoutAnimation(mutation, oldView, surfaceId, tag);
690
+ window = strongThis->surfaceManager.getWindow(surfaceId);
691
+ }
692
+
693
+ Snapshot values(oldView, window);
694
+
695
+ auto &uiRuntime = strongThis->uiRuntime_;
696
+ jsi::Object yogaValues(uiRuntime);
697
+ yogaValues.setProperty(uiRuntime, "currentOriginX", values.x);
698
+ yogaValues.setProperty(uiRuntime, "currentGlobalOriginX", values.x);
699
+ yogaValues.setProperty(uiRuntime, "currentOriginY", values.y);
700
+ yogaValues.setProperty(uiRuntime, "currentGlobalOriginY", values.y);
701
+ yogaValues.setProperty(uiRuntime, "currentWidth", values.width);
702
+ yogaValues.setProperty(uiRuntime, "currentHeight", values.height);
703
+ yogaValues.setProperty(uiRuntime, "windowWidth", values.windowWidth);
704
+ yogaValues.setProperty(uiRuntime, "windowHeight", values.windowHeight);
705
+ strongThis->layoutAnimationsManager_->startLayoutAnimation(
706
+ uiRuntime, tag, LayoutAnimationType::EXITING, yogaValues);
707
+ strongThis->layoutAnimationsManager_->clearLayoutAnimationConfig(tag);
708
+ });
709
+ }
710
+
711
+ void LayoutAnimationsProxy_Legacy::startLayoutAnimation(const int tag, const ShadowViewMutation &mutation) const {
712
+ #ifdef LAYOUT_ANIMATIONS_LOGS
713
+ LOG(INFO) << "start layout animation for tag " << tag << std::endl;
714
+ #endif
715
+ auto surfaceId = mutation.oldChildShadowView.surfaceId;
716
+
717
+ uiScheduler_->scheduleOnUI([weakThis = weak_from_this(), mutation, surfaceId, tag]() {
718
+ auto strongThis = weakThis.lock();
719
+ if (!strongThis) {
720
+ return;
721
+ }
722
+
723
+ auto oldView = mutation.oldChildShadowView;
724
+ Rect window{};
725
+ {
726
+ auto &mutex = strongThis->mutex;
727
+ auto lock = std::unique_lock<std::recursive_mutex>(mutex);
728
+ strongThis->createLayoutAnimation(mutation, oldView, surfaceId, tag);
729
+ window = strongThis->surfaceManager.getWindow(surfaceId);
730
+ }
731
+
732
+ Snapshot currentValues(oldView, window);
733
+ Snapshot targetValues(mutation.newChildShadowView, window);
734
+
735
+ auto &uiRuntime = strongThis->uiRuntime_;
736
+ jsi::Object yogaValues(uiRuntime);
737
+ yogaValues.setProperty(uiRuntime, "currentOriginX", currentValues.x);
738
+ yogaValues.setProperty(uiRuntime, "currentGlobalOriginX", currentValues.x);
739
+ yogaValues.setProperty(uiRuntime, "currentOriginY", currentValues.y);
740
+ yogaValues.setProperty(uiRuntime, "currentGlobalOriginY", currentValues.y);
741
+ yogaValues.setProperty(uiRuntime, "currentWidth", currentValues.width);
742
+ yogaValues.setProperty(uiRuntime, "currentHeight", currentValues.height);
743
+ yogaValues.setProperty(uiRuntime, "targetOriginX", targetValues.x);
744
+ yogaValues.setProperty(uiRuntime, "targetGlobalOriginX", targetValues.x);
745
+ yogaValues.setProperty(uiRuntime, "targetOriginY", targetValues.y);
746
+ yogaValues.setProperty(uiRuntime, "targetGlobalOriginY", targetValues.y);
747
+ yogaValues.setProperty(uiRuntime, "targetWidth", targetValues.width);
748
+ yogaValues.setProperty(uiRuntime, "targetHeight", targetValues.height);
749
+ yogaValues.setProperty(uiRuntime, "windowWidth", targetValues.windowWidth);
750
+ yogaValues.setProperty(uiRuntime, "windowHeight", targetValues.windowHeight);
751
+ strongThis->layoutAnimationsManager_->startLayoutAnimation(uiRuntime, tag, LayoutAnimationType::LAYOUT, yogaValues);
752
+ });
753
+ }
754
+
755
+ void LayoutAnimationsProxy_Legacy::updateOngoingAnimationTarget(const int tag, const ShadowViewMutation &mutation)
756
+ const {
757
+ auto copy = mutation.newChildShadowView;
758
+ layoutAnimations_[tag].finalView = copy;
759
+ }
760
+
761
+ void LayoutAnimationsProxy_Legacy::maybeCancelAnimation(const int tag) const {
762
+ if (!layoutAnimations_.contains(tag)) {
763
+ return;
764
+ }
765
+ layoutAnimations_.erase(tag);
766
+ uiScheduler_->scheduleOnUI([weakThis = weak_from_this(), tag]() {
767
+ auto strongThis = weakThis.lock();
768
+ if (!strongThis) {
769
+ return;
770
+ }
771
+
772
+ auto &uiRuntime = strongThis->uiRuntime_;
773
+ strongThis->layoutAnimationsManager_->cancelLayoutAnimation(uiRuntime, tag);
774
+ });
775
+ }
776
+
777
+ void LayoutAnimationsProxy_Legacy::transferConfigFromNativeID(const std::string &nativeIdString, const int tag) const {
778
+ if (nativeIdString.empty()) {
779
+ return;
780
+ }
781
+ try {
782
+ auto nativeId = stoi(nativeIdString);
783
+ layoutAnimationsManager_->transferConfigFromNativeID(nativeId, tag);
784
+ } catch (std::invalid_argument) {
785
+ } catch (std::out_of_range) {}
786
+ }
787
+
788
+ // When entering animations start, we temporarily set opacity to 0
789
+ // so that we can immediately insert the view at the right position
790
+ // and schedule the animation on the UI thread
791
+ std::shared_ptr<ShadowView> LayoutAnimationsProxy_Legacy::cloneViewWithoutOpacity(
792
+ facebook::react::ShadowViewMutation &mutation,
793
+ const PropsParserContext &propsParserContext) const {
794
+ auto newView = std::make_shared<ShadowView>(mutation.newChildShadowView);
795
+ folly::dynamic opacity = folly::dynamic::object("opacity", 0);
796
+ auto newProps =
797
+ getComponentDescriptorForShadowView(*newView).cloneProps(propsParserContext, newView->props, RawProps(opacity));
798
+ newView->props = newProps;
799
+ return newView;
800
+ }
801
+
802
+ void LayoutAnimationsProxy_Legacy::maybeRestoreOpacity(LayoutAnimation &layoutAnimation, const jsi::Object &newStyle)
803
+ const {
804
+ if (layoutAnimation.opacity && !newStyle.hasProperty(uiRuntime_, "opacity")) {
805
+ newStyle.setProperty(uiRuntime_, "opacity", jsi::Value(*layoutAnimation.opacity));
806
+ if (layoutAnimation.isViewAlreadyMounted) {
807
+ // We want to reset opacity only when we are sure that this update will be
808
+ // applied to the native view. Otherwise, we want to update opacity using
809
+ // the `restoreOpacityInCaseOfFlakyEnteringAnimation` method.
810
+ layoutAnimation.opacity.reset();
811
+ }
812
+ }
813
+ }
814
+
815
+ void LayoutAnimationsProxy_Legacy::maybeUpdateWindowDimensions(
816
+ facebook::react::ShadowViewMutation &mutation,
817
+ SurfaceId surfaceId) const {
818
+ if (mutation.type == ShadowViewMutation::Update &&
819
+ !std::strcmp(mutation.oldChildShadowView.componentName, RootComponentName)) {
820
+ surfaceManager.updateWindow(
821
+ surfaceId,
822
+ mutation.newChildShadowView.layoutMetrics.frame.size.width,
823
+ mutation.newChildShadowView.layoutMetrics.frame.size.height);
824
+ }
825
+ }
826
+
827
+ void Node::applyMutationToIndices(ShadowViewMutation mutation) {
828
+ const auto parentTag = mutation.parentTag;
829
+ if (tag != parentTag) {
830
+ return;
831
+ }
832
+
833
+ int delta = mutation.type == ShadowViewMutation::Insert ? 1 : -1;
834
+ for (auto it = children.rbegin(); it != children.rend(); ++it) {
835
+ const auto& child = *it;
836
+ if (child->mutation.index < mutation.index) {
837
+ return;
838
+ }
839
+ child->mutation.index += delta;
840
+ }
841
+ }
842
+
843
+ // Should only be called on unflattened parents
844
+ void Node::removeChildFromUnflattenedTree(std::shared_ptr<MutationNode> child) {
845
+ for (int i = unflattenedChildren.size() - 1; i >= 0; i--) {
846
+ if (unflattenedChildren[i]->tag == child->tag) {
847
+ unflattenedChildren.erase(unflattenedChildren.begin() + i);
848
+ break;
849
+ }
850
+ }
851
+
852
+ auto &flattenedChildren = child->parent->children;
853
+ for (int i = flattenedChildren.size() - 1; i >= 0; i--) {
854
+ if (flattenedChildren[i]->tag == child->tag) {
855
+ flattenedChildren.erase(flattenedChildren.begin() + i);
856
+ return;
857
+ }
858
+ flattenedChildren[i]->mutation.index--;
859
+ }
860
+ }
861
+
862
+ void Node::insertChildren(std::vector<std::shared_ptr<MutationNode>> &newChildren) {
863
+ mergeAndSwap(children, newChildren);
864
+ }
865
+
866
+ void Node::insertUnflattenedChildren(std::vector<std::shared_ptr<MutationNode>> &newChildren) {
867
+ mergeAndSwap(unflattenedChildren, newChildren);
868
+ }
869
+
870
+ inline bool Node::isMutationNode() {
871
+ return false;
872
+ }
873
+
874
+ inline bool MutationNode::isMutationNode() {
875
+ return true;
876
+ }
877
+
878
+ // UIManagerAnimationDelegate
879
+
880
+ void LayoutAnimationsProxy_Legacy::uiManagerDidConfigureNextLayoutAnimation(
881
+ jsi::Runtime &runtime,
882
+ const RawValue &config,
883
+ const jsi::Value &successCallbackValue,
884
+ const jsi::Value &failureCallbackValue) const {}
885
+
886
+ void LayoutAnimationsProxy_Legacy::setComponentDescriptorRegistry(
887
+ const SharedComponentDescriptorRegistry &componentDescriptorRegistry) {}
888
+
889
+ bool LayoutAnimationsProxy_Legacy::shouldAnimateFrame() const {
890
+ return false;
891
+ }
892
+
893
+ void LayoutAnimationsProxy_Legacy::stopSurface(SurfaceId surfaceId) {
894
+ surfacesToRemove_.insert(surfaceId);
895
+ }
896
+
897
+ } // namespace reanimated