@react-native-ohos/react-native-reanimated 4.0.2 → 4.1.0-beta.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 (196) hide show
  1. package/CHANGELOG.md +1070 -0
  2. package/LICENSE +21 -0
  3. package/README.md +842 -0
  4. package/compatibility.json +20 -26
  5. package/harmony/reanimated/BuildProfile.ets +1 -1
  6. package/harmony/reanimated/index.ets +4 -2
  7. package/harmony/reanimated/oh-package-lock.json5 +1 -1
  8. package/harmony/reanimated/oh-package.json5 +1 -1
  9. package/harmony/reanimated/src/main/cpp/CMakeLists.txt +23 -6
  10. package/harmony/reanimated/src/main/cpp/Common/NativeView/CMakeLists.txt +56 -0
  11. package/harmony/reanimated/src/main/cpp/Common/NativeView/react/renderer/components/rnreanimated/ComponentDescriptors.h +19 -0
  12. package/harmony/reanimated/src/main/cpp/Common/NativeView/react/renderer/components/rnreanimated/REASharedTransitionBoundaryComponentDescriptor.h +30 -0
  13. package/harmony/reanimated/src/main/cpp/Common/NativeView/react/renderer/components/rnreanimated/REASharedTransitionBoundaryShadowNode.cpp +15 -0
  14. package/harmony/reanimated/src/main/cpp/Common/NativeView/react/renderer/components/rnreanimated/REASharedTransitionBoundaryShadowNode.h +41 -0
  15. package/harmony/reanimated/src/main/cpp/Common/NativeView/react/renderer/components/rnreanimated/REASharedTransitionBoundaryState.h +30 -0
  16. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/AnimatedSensor/AnimatedSensorModule.cpp +8 -9
  17. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/AnimatedSensor/AnimatedSensorModule.h +3 -6
  18. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/InterpolatorRegistry.cpp +203 -150
  19. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/InterpolatorRegistry.h +1 -6
  20. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/definitions.h +2 -7
  21. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/values/CSSAngle.cpp +0 -1
  22. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/values/CSSColor.cpp +2 -18
  23. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/values/CSSDiscreteArray.cpp +11 -11
  24. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/values/CSSDiscreteArray.h +2 -6
  25. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/values/CSSLength.cpp +4 -1
  26. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/values/CSSNumber.cpp +5 -0
  27. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/values/CSSNumber.h +8 -0
  28. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/values/CSSValue.h +27 -46
  29. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/values/CSSValueVariant.cpp +20 -20
  30. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/values/CSSValueVariant.h +2 -2
  31. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/common/values/complex/CSSDropShadow.h +3 -3
  32. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/configs/CSSAnimationConfig.cpp +10 -2
  33. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/configs/CSSAnimationConfig.h +5 -3
  34. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/configs/CSSKeyframesConfig.cpp +20 -17
  35. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/configs/CSSKeyframesConfig.h +5 -8
  36. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/configs/CSSTransitionConfig.cpp +33 -66
  37. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/configs/CSSTransitionConfig.h +29 -22
  38. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/configs/common.cpp +14 -2
  39. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/configs/common.h +8 -2
  40. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/core/CSSAnimation.cpp +50 -91
  41. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/core/CSSAnimation.h +43 -18
  42. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/core/CSSAnimationsGroup.cpp +63 -0
  43. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/core/CSSAnimationsGroup.h +37 -0
  44. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/core/CSSLoopAnimation.cpp +100 -0
  45. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/core/CSSLoopAnimation.h +49 -0
  46. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/core/CSSPlatformAnimation.h +13 -0
  47. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/core/CSSPlatformAnimationFactory.h +32 -0
  48. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/core/transition/CSSLoopTransition.cpp +156 -0
  49. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/core/transition/CSSLoopTransition.h +71 -0
  50. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/core/transition/CSSPlatformTransitionProxy.cpp +141 -0
  51. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/core/transition/CSSPlatformTransitionProxy.h +104 -0
  52. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/core/transition/CSSTransition.cpp +97 -0
  53. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/core/transition/CSSTransition.h +69 -0
  54. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/easing/EasingConfigs.cpp +89 -0
  55. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/easing/EasingConfigs.h +36 -0
  56. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/InterpolatorFactory.cpp +12 -0
  57. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/InterpolatorFactory.h +11 -2
  58. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/PropertyInterpolator.cpp +2 -3
  59. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/PropertyInterpolator.h +3 -5
  60. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/filters/FilterOperation.cpp +3 -3
  61. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/filters/FilterOperation.h +1 -1
  62. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/groups/ArrayPropertiesInterpolator.cpp +38 -37
  63. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/groups/ArrayPropertiesInterpolator.h +3 -6
  64. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/groups/RecordPropertiesInterpolator.cpp +54 -32
  65. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/groups/RecordPropertiesInterpolator.h +5 -7
  66. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/operations/OperationsStyleInterpolator.cpp +46 -46
  67. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/operations/OperationsStyleInterpolator.h +8 -7
  68. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/operations/StyleOperation.h +4 -57
  69. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/styles/AnimationStyleInterpolator.cpp +23 -0
  70. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/styles/AnimationStyleInterpolator.h +10 -8
  71. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/styles/AnimationStyleInterpolatorFactory.cpp +77 -0
  72. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/styles/AnimationStyleInterpolatorFactory.h +38 -0
  73. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/styles/TransitionStyleInterpolator.cpp +47 -68
  74. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/styles/TransitionStyleInterpolator.h +21 -9
  75. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/transforms/TransformOperation.cpp +4 -1
  76. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/transforms/TransformOperationInterpolator.cpp +35 -78
  77. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/transforms/TransformOperationInterpolator.h +44 -13
  78. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/transforms/operations/matrix.cpp +13 -11
  79. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/values/ResolvableValueInterpolator.cpp +4 -0
  80. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/values/SimpleValueInterpolator.cpp +7 -3
  81. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/values/ValueInterpolator.cpp +20 -27
  82. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/interpolation/values/ValueInterpolator.h +12 -9
  83. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/misc/ViewStylesRepository.cpp +63 -36
  84. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/misc/ViewStylesRepository.h +6 -8
  85. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/progress/AnimationProgressProvider.cpp +55 -46
  86. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/progress/AnimationProgressProvider.h +8 -5
  87. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/progress/RawProgressProvider.cpp +1 -2
  88. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/progress/RawProgressProvider.h +3 -2
  89. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/progress/TransitionProgressProvider.cpp +76 -71
  90. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/progress/TransitionProgressProvider.h +17 -14
  91. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/registries/CSSAnimationsRegistry.cpp +145 -273
  92. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/registries/CSSAnimationsRegistry.h +43 -44
  93. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/registries/CSSKeyframesRegistry.cpp +19 -19
  94. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/registries/CSSKeyframesRegistry.h +16 -12
  95. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/registries/CSSTransitionsRegistry.cpp +95 -114
  96. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/registries/CSSTransitionsRegistry.h +38 -25
  97. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/registries/StaticPropsRegistry.cpp +9 -34
  98. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/registries/StaticPropsRegistry.h +0 -10
  99. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/svg/values/CSSLengthArray.cpp +47 -0
  100. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/svg/values/CSSLengthArray.h +24 -0
  101. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/svg/values/CSSLengthVector.cpp +87 -0
  102. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/svg/values/CSSLengthVector.h +28 -0
  103. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/svg/values/SVGPath.cpp +326 -0
  104. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/svg/values/SVGPath.h +65 -0
  105. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/svg/values/SVGStops.cpp +164 -0
  106. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/svg/values/SVGStops.h +51 -0
  107. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/svg/values/SVGStrokeDashArray.cpp +14 -66
  108. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/svg/values/SVGStrokeDashArray.h +7 -18
  109. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/utils/platform.cpp +284 -0
  110. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/utils/platform.h +31 -0
  111. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/utils/props.cpp +13 -132
  112. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/utils/props.h +3 -21
  113. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/utils/reversingShortening.h +43 -0
  114. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Compat/WorkletsApi.h +13 -0
  115. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Events/UIEventHandler.cpp +33 -0
  116. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Events/UIEventHandler.h +39 -0
  117. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Events/UIEventHandlerRegistry.cpp +95 -0
  118. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Events/UIEventHandlerRegistry.h +40 -0
  119. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ReanimatedCommitHook.cpp +20 -23
  120. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ReanimatedCommitHook.h +2 -6
  121. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ReanimatedMountHook.cpp +26 -18
  122. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ReanimatedMountHook.h +4 -8
  123. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ShadowTreeCloner.cpp +16 -28
  124. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/ShadowTreeCloner.h +3 -4
  125. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/updates/AnimatedPropsRegistry.cpp +72 -24
  126. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/updates/AnimatedPropsRegistry.h +17 -7
  127. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/updates/OperationsLoop.cpp +152 -0
  128. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/updates/OperationsLoop.h +86 -0
  129. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/updates/PropsLayoutFilter.h +98 -0
  130. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/updates/UpdatesRegistry.cpp +162 -28
  131. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/updates/UpdatesRegistry.h +69 -11
  132. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/updates/UpdatesRegistryManager.cpp +41 -17
  133. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/updates/UpdatesRegistryManager.h +14 -3
  134. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Fabric/updates/propNameFromString.h +130 -0
  135. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsManager.cpp +1 -0
  136. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsManager.h +5 -7
  137. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxyCommon.cpp +7 -4
  138. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxyCommon.h +52 -9
  139. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy_Experimental.cpp +174 -62
  140. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy_Experimental.h +12 -11
  141. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy_Legacy.cpp +251 -128
  142. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsProxy_Legacy.h +23 -19
  143. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/LayoutAnimationsUtils.h +34 -6
  144. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/LayoutAnimations/SharedTransitions.cpp +71 -64
  145. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxy.cpp +938 -700
  146. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxy.h +123 -76
  147. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/NativeModules/SynchronousPropsBufferSerializer.cpp +313 -0
  148. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/NativeModules/SynchronousPropsBufferSerializer.h +18 -0
  149. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/PseudoStyles/PseudoSelector.h +41 -0
  150. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/PseudoStyles/PseudoStylesRegistry.cpp +113 -0
  151. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/PseudoStyles/PseudoStylesRegistry.h +73 -0
  152. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/RuntimeDecorators/RNRuntimeDecorator.cpp +4 -4
  153. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/RuntimeDecorators/UIRuntimeDecorator.cpp +23 -48
  154. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/RuntimeDecorators/UIRuntimeDecorator.h +13 -14
  155. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/PlatformDepMethodsHolder.h +20 -3
  156. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/ReaJSIUtils.h +227 -0
  157. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/ReanimatedVersion.cpp +51 -14
  158. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/ReanimatedVersion.h +2 -5
  159. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/Tools/SingleInstanceChecker.h +76 -0
  160. package/harmony/reanimated/src/main/cpp/OHOSCSSPlatformTransitions.cpp +353 -0
  161. package/harmony/reanimated/src/main/cpp/OHOSCSSPlatformTransitions.h +95 -0
  162. package/harmony/reanimated/src/main/cpp/PseudoSelectorManager.cpp +140 -0
  163. package/harmony/reanimated/src/main/cpp/PseudoSelectorManager.h +52 -0
  164. package/harmony/reanimated/src/main/cpp/REASharedTransitionBoundaryComponentInstance.cpp +45 -0
  165. package/harmony/reanimated/src/main/cpp/REASharedTransitionBoundaryComponentInstance.h +33 -0
  166. package/harmony/reanimated/src/main/cpp/REASharedTransitionBoundaryJSIBinder.h +20 -0
  167. package/harmony/reanimated/src/main/cpp/ReanimatedModule.cpp +98 -18
  168. package/harmony/reanimated/src/main/cpp/ReanimatedModule.h +4 -2
  169. package/harmony/reanimated/src/main/cpp/ReanimatedNodesManager.cpp +1 -1
  170. package/harmony/reanimated/src/main/cpp/ReanimatedNodesManager.h +1 -1
  171. package/harmony/reanimated/src/main/cpp/ReanimatedPackage.cpp +24 -1
  172. package/harmony/reanimated/src/main/cpp/ReanimatedPackage.h +7 -2
  173. package/harmony/reanimated/src/main/cpp/ReanimatedSensor.cpp +88 -57
  174. package/harmony/reanimated/src/main/cpp/ReanimatedSensor.h +4 -2
  175. package/harmony/reanimated/src/main/cpp/ReanimatedSensorContainer.cpp +1 -1
  176. package/harmony/reanimated/src/main/cpp/ReanimatedSensorContainer.h +1 -1
  177. package/harmony/reanimated/src/main/cpp/ReanimatedUIScheduler.cpp +9 -7
  178. package/harmony/reanimated/src/main/cpp/ReanimatedUIScheduler.h +6 -5
  179. package/harmony/reanimated/src/main/cpp/TransformParser.h +1 -1
  180. package/harmony/reanimated/src/main/cpp/codegen/react/renderer/components/rnreanimated/EventEmitters.h +19 -0
  181. package/harmony/reanimated/src/main/cpp/codegen/react/renderer/components/rnreanimated/Props.h +31 -0
  182. package/harmony/reanimated/src/main/ets/KeyboardState.ts +11 -0
  183. package/harmony/reanimated/src/main/ets/ReanimatedModule.ts +106 -17
  184. package/harmony/reanimated/src/main/ets/{ReanimatedPackage.ts → ReanimatedPackage.ets} +4 -3
  185. package/harmony/reanimated.har +0 -0
  186. package/package.json +52 -24
  187. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/core/CSSTransition.cpp +0 -145
  188. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/core/CSSTransition.h +0 -47
  189. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/svg/values/SVGLength.cpp +0 -93
  190. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/svg/values/SVGLength.h +0 -36
  191. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/utils/DelayedItemsManager.cpp +0 -75
  192. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/CSS/utils/DelayedItemsManager.h +0 -45
  193. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxySpec.cpp +0 -183
  194. package/harmony/reanimated/src/main/cpp/Common/cpp/reanimated/NativeModules/ReanimatedModuleProxySpec.h +0 -93
  195. package/harmony/reanimated/src/main/ets/AnimationManager.ts +0 -61
  196. /package/harmony/reanimated/{ts.ts → ts.ets} +0 -0
@@ -0,0 +1,41 @@
1
+ #pragma once
2
+
3
+ #include <optional>
4
+ #include <string>
5
+
6
+ namespace reanimated {
7
+
8
+ // Defines all supported selectors and their merge priority (last = highest priority).
9
+ // When you update this remember to also change kPseudoSelectorBits so it uses the last value
10
+ enum class PseudoSelector : std::uint8_t {
11
+ FocusWithin = 0,
12
+ Focus = 1,
13
+ Hover = 2,
14
+ Active = 3,
15
+ ActiveDeepest = 4,
16
+ };
17
+
18
+ inline constexpr int kPseudoSelectorBits = static_cast<int>(PseudoSelector::ActiveDeepest) + 1;
19
+
20
+ using PseudoSelectorMask = std::uint8_t;
21
+
22
+ inline std::optional<PseudoSelector> pseudoSelectorFromString(const std::string &s) {
23
+ if (s == ":focus-within") {
24
+ return PseudoSelector::FocusWithin;
25
+ }
26
+ if (s == ":focus") {
27
+ return PseudoSelector::Focus;
28
+ }
29
+ if (s == ":hover") {
30
+ return PseudoSelector::Hover;
31
+ }
32
+ if (s == ":active") {
33
+ return PseudoSelector::Active;
34
+ }
35
+ if (s == ":active-deepest") {
36
+ return PseudoSelector::ActiveDeepest;
37
+ }
38
+ return std::nullopt;
39
+ }
40
+
41
+ } // namespace reanimated
@@ -0,0 +1,113 @@
1
+ #include <reanimated/PseudoStyles/PseudoStylesRegistry.h>
2
+
3
+ #include <react/debug/react_native_assert.h>
4
+
5
+ #include <string>
6
+ #include <utility>
7
+
8
+ namespace reanimated {
9
+
10
+ using namespace facebook::react;
11
+
12
+ PseudoStylesRegistry::PseudoStylesRegistry(
13
+ PlatformAttachPseudoSelectorFunction attachFn,
14
+ PlatformDetachPseudoSelectorFunction detachFn,
15
+ std::shared_ptr<css::CSSTransitionsRegistry> cssTransitionsRegistry,
16
+ std::shared_ptr<UpdatesRegistryManager> updatesRegistryManager)
17
+ : attachFn_(std::move(attachFn)),
18
+ detachFn_(std::move(detachFn)),
19
+ cssTransitionsRegistry_(std::move(cssTransitionsRegistry)),
20
+ updatesRegistryManager_(std::move(updatesRegistryManager)) {}
21
+
22
+ // static
23
+ std::array<folly::dynamic, (1u << kPseudoSelectorBits)> PseudoStylesRegistry::recomputeAllStyles(
24
+ const TagEntry &entry) {
25
+ const PseudoSelectorMask maxMask = (1u << kPseudoSelectorBits);
26
+ std::array<folly::dynamic, (1u << kPseudoSelectorBits)> newPrecomputedStyles;
27
+
28
+ for (PseudoSelectorMask mask = 0; mask < maxMask; ++mask) {
29
+ folly::dynamic style = entry.defaults;
30
+
31
+ for (const auto &[sel, data] : entry.selectors) {
32
+ if (mask & (1u << static_cast<int>(sel))) {
33
+ style.update(data.selectorStyle);
34
+ }
35
+ }
36
+
37
+ newPrecomputedStyles[mask] = std::move(style);
38
+ }
39
+
40
+ return newPrecomputedStyles;
41
+ }
42
+
43
+ void PseudoStylesRegistry::registerPseudoStyles(
44
+ Tag tag,
45
+ const std::shared_ptr<const ShadowNode> &shadowNode,
46
+ const folly::dynamic &defaults,
47
+ const std::vector<SelectorRegistration> &selectors) {
48
+ react_native_assert(UpdatesRegistryManager::isLockedByCurrentThread());
49
+
50
+ auto &entry = registry_[tag];
51
+ entry.shadowNode = shadowNode;
52
+ entry.defaults = defaults;
53
+ for (const auto &registration : selectors) {
54
+ entry.selectors[registration.selector] = {registration.selectorStyle};
55
+ }
56
+ entry.precomputedStyles = recomputeAllStyles(entry);
57
+
58
+ for (const auto &registration : selectors) {
59
+ const auto selector = registration.selector;
60
+ attachFn_(
61
+ tag,
62
+ selector,
63
+ [weakThis = std::weak_ptr<PseudoStylesRegistry>(shared_from_this()), tag, selector](bool isActive) {
64
+ if (auto strongThis = weakThis.lock()) {
65
+ strongThis->onSelectorStateChanged(tag, selector, isActive);
66
+ }
67
+ });
68
+ }
69
+ }
70
+
71
+ void PseudoStylesRegistry::remove(Tag tag) {
72
+ react_native_assert(UpdatesRegistryManager::isLockedByCurrentThread());
73
+
74
+ auto it = registry_.find(tag);
75
+ if (it == registry_.end()) {
76
+ return;
77
+ }
78
+ auto selectorsToDetach = std::move(it->second.selectors);
79
+ registry_.erase(it);
80
+
81
+ for (const auto &[selector, data] : selectorsToDetach) {
82
+ detachFn_(tag, selector);
83
+ }
84
+ }
85
+
86
+ void PseudoStylesRegistry::onSelectorStateChanged(Tag tag, PseudoSelector selector, bool isActive) {
87
+ auto lock = updatesRegistryManager_->lock();
88
+
89
+ auto it = registry_.find(tag);
90
+ if (it == registry_.end()) {
91
+ return;
92
+ }
93
+ TagEntry &entry = it->second;
94
+
95
+ const PseudoSelectorMask oldMask = entry.activeMask;
96
+ const PseudoSelectorMask bit = 1u << static_cast<int>(selector);
97
+ entry.activeMask = isActive ? (oldMask | bit) : (oldMask & ~bit);
98
+
99
+ const auto shadowNode = entry.shadowNode;
100
+ const auto &fromStyle = entry.precomputedStyles[oldMask];
101
+ const auto &toStyle = entry.precomputedStyles[entry.activeMask];
102
+
103
+ css::PropertyValueDynamicDiffsMap valueChanges;
104
+ for (const auto &[propKey, toVal] : toStyle.items()) {
105
+ const auto propName = propKey.asString();
106
+ const folly::dynamic &fromVal = fromStyle.count(propName) ? fromStyle[propName] : toVal;
107
+ valueChanges.emplace(propName, std::make_pair(fromVal, toVal));
108
+ }
109
+
110
+ cssTransitionsRegistry_->run(shadowNode, valueChanges);
111
+ }
112
+
113
+ } // namespace reanimated
@@ -0,0 +1,73 @@
1
+ #pragma once
2
+
3
+ #include <reanimated/CSS/common/definitions.h>
4
+ #include <reanimated/CSS/registries/CSSTransitionsRegistry.h>
5
+ #include <reanimated/Fabric/updates/UpdatesRegistryManager.h>
6
+ #include <reanimated/PseudoStyles/PseudoSelector.h>
7
+ #include <reanimated/Tools/PlatformDepMethodsHolder.h>
8
+
9
+ #include <react/renderer/core/ShadowNode.h>
10
+
11
+ #include <folly/dynamic.h>
12
+ #include <array>
13
+ #include <map>
14
+ #include <memory>
15
+ #include <unordered_map>
16
+ #include <vector>
17
+
18
+ namespace reanimated {
19
+
20
+ using namespace facebook;
21
+ using namespace react;
22
+
23
+ class PseudoStylesRegistry : public std::enable_shared_from_this<PseudoStylesRegistry> {
24
+ public:
25
+ PseudoStylesRegistry(
26
+ PlatformAttachPseudoSelectorFunction attachFn,
27
+ PlatformDetachPseudoSelectorFunction detachFn,
28
+ std::shared_ptr<css::CSSTransitionsRegistry> cssTransitionsRegistry,
29
+ std::shared_ptr<UpdatesRegistryManager> updatesRegistryManager);
30
+
31
+ struct SelectorRegistration {
32
+ PseudoSelector selector;
33
+ folly::dynamic selectorStyle;
34
+ };
35
+
36
+ void registerPseudoStyles(
37
+ Tag tag,
38
+ const std::shared_ptr<const ShadowNode> &shadowNode,
39
+ const folly::dynamic &defaults,
40
+ const std::vector<SelectorRegistration> &selectors);
41
+
42
+ void remove(Tag tag);
43
+
44
+ private:
45
+ struct SelectorData {
46
+ folly::dynamic selectorStyle;
47
+ };
48
+
49
+ struct TagEntry {
50
+ std::shared_ptr<const ShadowNode> shadowNode;
51
+
52
+ folly::dynamic defaults = folly::dynamic::object();
53
+ std::map<PseudoSelector, SelectorData> selectors;
54
+
55
+ std::array<folly::dynamic, (1u << kPseudoSelectorBits)> precomputedStyles;
56
+
57
+ PseudoSelectorMask activeMask = 0;
58
+ };
59
+
60
+ std::unordered_map<Tag, TagEntry> registry_;
61
+
62
+ PlatformAttachPseudoSelectorFunction attachFn_;
63
+ PlatformDetachPseudoSelectorFunction detachFn_;
64
+
65
+ std::shared_ptr<css::CSSTransitionsRegistry> cssTransitionsRegistry_;
66
+ std::shared_ptr<UpdatesRegistryManager> updatesRegistryManager_;
67
+
68
+ static std::array<folly::dynamic, (1u << kPseudoSelectorBits)> recomputeAllStyles(const TagEntry &entry);
69
+
70
+ void onSelectorStateChanged(Tag tag, PseudoSelector selector, bool isActive);
71
+ };
72
+
73
+ } // namespace reanimated
@@ -1,6 +1,6 @@
1
1
  #include <reanimated/RuntimeDecorators/RNRuntimeDecorator.h>
2
+ #include <reanimated/Tools/ReaJSIUtils.h>
2
3
  #include <reanimated/Tools/ReanimatedVersion.h>
3
- #include <worklets/Tools/WorkletsJSIUtils.h>
4
4
 
5
5
  #include <memory>
6
6
 
@@ -20,7 +20,7 @@ void RNRuntimeDecorator::decorate(
20
20
  rnRuntime.global().setProperty(rnRuntime, "_WORKLET_RUNTIME", workletRuntimeValue);
21
21
 
22
22
  #ifndef NDEBUG
23
- checkJSVersion(rnRuntime, reanimatedModuleProxy->getJSLogger());
23
+ checkJSVersion(rnRuntime);
24
24
  #endif // NDEBUG
25
25
 
26
26
  #ifdef IS_REANIMATED_EXAMPLE_APP
@@ -32,14 +32,14 @@ void RNRuntimeDecorator::decorate(
32
32
  rnRuntime.global().setProperty(rnRuntime, "_REANIMATED_IS_REDUCED_MOTION", reanimatedModuleProxy->isReducedMotion());
33
33
 
34
34
  rnRuntime.global().setProperty(
35
- rnRuntime, "__reanimatedModuleProxy", jsi::Object::createFromHostObject(rnRuntime, reanimatedModuleProxy));
35
+ rnRuntime, "__reanimatedModuleProxy", reanimatedModuleProxy->toOptimizedObject(rnRuntime));
36
36
  }
37
37
 
38
38
  #ifdef IS_REANIMATED_EXAMPLE_APP
39
39
  void RNRuntimeDecorator::installDebugBindings(
40
40
  jsi::Runtime &rnRuntime,
41
41
  const std::shared_ptr<ReanimatedModuleProxy> &reanimatedModuleProxy) {
42
- #if TARGET_OS_X
42
+ #if defined(TARGET_OS_X) && TARGET_OS_X
43
43
  jsi_utils::installJsiFunction(
44
44
  rnRuntime, "__getTagFromShadowNodeWrapper", [](jsi::Runtime &rt, const jsi::Value &shadowNodeWrapper) {
45
45
  auto node = Bridging<std::shared_ptr<const ShadowNode>>::fromJs(rt, shadowNodeWrapper);
@@ -1,58 +1,33 @@
1
1
  #include <reanimated/RuntimeDecorators/UIRuntimeDecorator.h>
2
- #include <worklets/Tools/WorkletsJSIUtils.h>
3
-
4
- #include <utility>
2
+ #include <reanimated/Tools/ReaJSIUtils.h>
5
3
 
6
4
  namespace reanimated {
7
5
 
8
- using namespace worklets;
9
-
10
6
  void UIRuntimeDecorator::decorate(
11
7
  jsi::Runtime &uiRuntime,
12
- ObtainPropFunction obtainPropFunction,
13
- UpdatePropsFunction updateProps,
14
- MeasureFunction measure,
15
- DispatchCommandFunction dispatchCommand,
16
- GetAnimationTimestampFunction getAnimationTimestamp,
17
- SetGestureStateFunction setGestureState,
18
- ProgressLayoutAnimationFunction progressLayoutAnimation,
19
- EndLayoutAnimationFunction endLayoutAnimation,
20
- MaybeFlushUIUpdatesQueueFunction maybeFlushUIUpdatesQueue) {
21
-
22
- jsi_utils::installJsiFunction(uiRuntime, "_updateProps", std::move(updateProps));
23
- jsi_utils::installJsiFunction(uiRuntime, "_dispatchCommand", std::move(dispatchCommand));
24
- jsi_utils::installJsiFunction(uiRuntime, "_measure", std::move(measure));
25
- jsi_utils::installJsiFunction(uiRuntime, "_getAnimationTimestamp", std::move(getAnimationTimestamp));
26
- jsi_utils::installJsiFunction(uiRuntime, "_notifyAboutProgress", std::move(progressLayoutAnimation));
27
- jsi_utils::installJsiFunction(uiRuntime, "_notifyAboutEnd", std::move(endLayoutAnimation));
28
- jsi_utils::installJsiFunction(uiRuntime, "_setGestureState", std::move(setGestureState));
29
- jsi_utils::installJsiFunction(uiRuntime, "_obtainProp", std::move(obtainPropFunction));
30
-
31
- subscribeForMicrotasksFinalization(uiRuntime, std::move(maybeFlushUIUpdatesQueue));
32
- }
33
-
34
- void UIRuntimeDecorator::subscribeForMicrotasksFinalization(
35
- jsi::Runtime &uiRuntime,
36
- MaybeFlushUIUpdatesQueueFunction maybeFlushUIUpdatesQueue) {
37
- auto maybeMicrotaskQueueFinalizers = uiRuntime.global().getProperty(uiRuntime, "_microtaskQueueFinalizers");
38
-
39
- if (maybeMicrotaskQueueFinalizers.isUndefined()) {
40
- throw std::runtime_error(
41
- "[Reanimated] Expected microtaskQueueFinalizers to be defined. "
42
- "Perhaps Worklets failed to initialize the UI Runtime?");
8
+ const ObtainPropFunction &obtainPropFunction,
9
+ const UpdatePropsFunction &updateProps,
10
+ const MeasureFunction &measure,
11
+ const DispatchCommandFunction &dispatchCommand,
12
+ const GetAnimationTimestampFunction &getAnimationTimestamp,
13
+ const SetGestureStateFunction &setGestureState,
14
+ const ProgressLayoutAnimationFunction &progressLayoutAnimation,
15
+ const EndLayoutAnimationFunction &endLayoutAnimation,
16
+ const MaybeFlushUIUpdatesQueueFunction &maybeFlushUIUpdatesQueue,
17
+ const std::optional<worklets::RequestAnimationFrameHostFunction> &requestAnimationFrame) {
18
+
19
+ jsi_utils::installJsiFunction(uiRuntime, "_updateProps", updateProps);
20
+ jsi_utils::installJsiFunction(uiRuntime, "_dispatchCommand", dispatchCommand);
21
+ jsi_utils::installJsiFunction(uiRuntime, "_measure", measure);
22
+ jsi_utils::installJsiFunction(uiRuntime, "_getAnimationTimestamp", getAnimationTimestamp);
23
+ jsi_utils::installJsiFunction(uiRuntime, "_notifyAboutProgress", progressLayoutAnimation);
24
+ jsi_utils::installJsiFunction(uiRuntime, "_notifyAboutEnd", endLayoutAnimation);
25
+ jsi_utils::installJsiFunction(uiRuntime, "_setGestureState", setGestureState);
26
+ jsi_utils::installJsiFunction(uiRuntime, "_obtainProp", obtainPropFunction);
27
+ jsi_utils::installJsiFunction(uiRuntime, "_maybeFlushUIUpdatesQueue", maybeFlushUIUpdatesQueue);
28
+ if (requestAnimationFrame.has_value()) {
29
+ worklets::installRequestAnimationFrame(uiRuntime, *requestAnimationFrame);
43
30
  }
44
-
45
- const auto microtaskQueueFinalizers = maybeMicrotaskQueueFinalizers.asObject(uiRuntime).asArray(uiRuntime);
46
-
47
- microtaskQueueFinalizers.getPropertyAsFunction(uiRuntime, "push")
48
- .callWithThis(
49
- uiRuntime,
50
- microtaskQueueFinalizers,
51
- jsi::Function::createFromHostFunction(
52
- uiRuntime,
53
- jsi::PropNameID::forAscii(uiRuntime, "_maybeFlushUIUpdatesQueue"),
54
- 0,
55
- jsi_utils::createHostFunction(std::move(maybeFlushUIUpdatesQueue))));
56
31
  }
57
32
 
58
33
  } // namespace reanimated
@@ -3,6 +3,9 @@
3
3
  #include <jsi/jsi.h>
4
4
 
5
5
  #include <reanimated/Tools/PlatformDepMethodsHolder.h>
6
+ #include <worklets/Compat/StableApi.h>
7
+
8
+ #include <optional>
6
9
 
7
10
  using namespace facebook;
8
11
 
@@ -12,20 +15,16 @@ class UIRuntimeDecorator {
12
15
  public:
13
16
  static void decorate(
14
17
  jsi::Runtime &uiRuntime,
15
- const ObtainPropFunction obtainPropFunction,
16
- const UpdatePropsFunction updateProps,
17
- const MeasureFunction measure,
18
- const DispatchCommandFunction dispatchCommand,
19
- const GetAnimationTimestampFunction getAnimationTimestamp,
20
- const SetGestureStateFunction setGestureState,
21
- const ProgressLayoutAnimationFunction progressLayoutAnimation,
22
- const EndLayoutAnimationFunction endLayoutAnimation,
23
- const MaybeFlushUIUpdatesQueueFunction maybeFlushUIUpdatesQueue);
24
-
25
- private:
26
- static void subscribeForMicrotasksFinalization(
27
- jsi::Runtime &uiRuntime,
28
- MaybeFlushUIUpdatesQueueFunction maybeFlushUIUpdatesQueue);
18
+ const ObtainPropFunction &obtainPropFunction,
19
+ const UpdatePropsFunction &updateProps,
20
+ const MeasureFunction &measure,
21
+ const DispatchCommandFunction &dispatchCommand,
22
+ const GetAnimationTimestampFunction &getAnimationTimestamp,
23
+ const SetGestureStateFunction &setGestureState,
24
+ const ProgressLayoutAnimationFunction &progressLayoutAnimation,
25
+ const EndLayoutAnimationFunction &endLayoutAnimation,
26
+ const MaybeFlushUIUpdatesQueueFunction &maybeFlushUIUpdatesQueue,
27
+ const std::optional<worklets::RequestAnimationFrameHostFunction> &requestAnimationFrame);
29
28
  };
30
29
 
31
30
  } // namespace reanimated
@@ -1,8 +1,12 @@
1
1
  #pragma once
2
2
 
3
+ #include <reanimated/CSS/core/transition/CSSPlatformTransitionProxy.h>
4
+ #include <reanimated/PseudoStyles/PseudoSelector.h>
5
+
3
6
  #include <folly/dynamic.h>
4
7
  #include <jsi/jsi.h>
5
8
  #include <react/renderer/core/ReactPrimitives.h>
9
+ #include <reanimated/CSS/core/CSSPlatformAnimationFactory.h>
6
10
 
7
11
  #include <memory>
8
12
  #include <string>
@@ -27,11 +31,11 @@ using MeasureFunction = std::function<jsi::Value(jsi::Runtime &rt, const jsi::Va
27
31
  using RequestRenderFunction = std::function<void(std::function<void(const double)>)>;
28
32
  #ifdef ANDROID
29
33
  using SynchronouslyUpdateUIPropsFunction = std::function<void(const std::vector<int> &, const std::vector<double> &)>;
30
- #elif __APPLE__
34
+ #elif defined(__APPLE__) || defined(__OHOS__)
35
+ // OHOS follows the Apple-style API: per-tag update with a folly::dynamic props
36
+ // map (see ReanimatedModule.cpp synchronouslyUpdateUIPropsFunction).
31
37
  using SynchronouslyUpdateUIPropsFunction = std::function<void(const int, const folly::dynamic &)>;
32
38
  #endif // ANDROID
33
- //TODO
34
- using SynchronouslyUpdateUIPropsFunction = std::function<void(const int, const folly::dynamic &)>;
35
39
  using PreserveMountedTagsFunction = std::function<std::optional<std::unique_ptr<int[]>>(std::vector<int> &)>;
36
40
  using GetAnimationTimestampFunction = std::function<double(void)>;
37
41
 
@@ -46,6 +50,10 @@ using KeyboardEventUnsubscribeFunction = std::function<void(int)>;
46
50
  using MaybeFlushUIUpdatesQueueFunction = std::function<void()>;
47
51
 
48
52
  using ForceScreenSnapshotFunction = std::function<void(Tag tag)>;
53
+
54
+ using PlatformAttachPseudoSelectorFunction = std::function<void(Tag, PseudoSelector, std::function<void(bool)>)>;
55
+ using PlatformDetachPseudoSelectorFunction = std::function<void(Tag, PseudoSelector)>;
56
+
49
57
  struct PlatformDepMethodsHolder {
50
58
  RequestRenderFunction requestRender;
51
59
  #ifdef ANDROID
@@ -62,6 +70,15 @@ struct PlatformDepMethodsHolder {
62
70
  KeyboardEventSubscribeFunction subscribeForKeyboardEvents;
63
71
  KeyboardEventUnsubscribeFunction unsubscribeFromKeyboardEvents;
64
72
  MaybeFlushUIUpdatesQueueFunction maybeFlushUIUpdatesQueueFunction;
73
+ PlatformAttachPseudoSelectorFunction attachPseudoSelector;
74
+ PlatformDetachPseudoSelectorFunction detachPseudoSelector;
75
+ css::CSSCanRoutePropertyFunction cssCanRouteProperty;
76
+ css::CSSApplyTransitionJSIFunction cssApplyTransitionJSI;
77
+ css::CSSApplyTransitionDynamicFunction cssApplyTransitionDynamic;
78
+ css::CSSRemoveTransitionFunction cssRemoveTransition;
79
+ // Last so platform initializers that don't supply it (iOS, Android today)
80
+ // can omit it and rely on value-init (= null shared_ptr).
81
+ std::shared_ptr<css::CSSPlatformAnimationFactory> platformAnimationFactory;
65
82
  };
66
83
 
67
84
  } // namespace reanimated
@@ -0,0 +1,227 @@
1
+ #pragma once
2
+
3
+ #include <jsi/jsi.h>
4
+ #include <react/debug/react_native_assert.h>
5
+
6
+ #include <concepts>
7
+ #include <memory>
8
+ #include <string>
9
+ #include <tuple>
10
+ #include <type_traits>
11
+ #include <utility>
12
+
13
+ using namespace facebook;
14
+
15
+ namespace reanimated::jsi_utils {
16
+
17
+ // `get` functions take a pointer to `jsi::Value` and
18
+ // call an appropriate method to cast to the native type
19
+ template <typename T>
20
+ inline T get(jsi::Runtime &rt, const jsi::Value *value);
21
+
22
+ template <>
23
+ inline double get<double>(jsi::Runtime &, const jsi::Value *value) {
24
+ return value->asNumber();
25
+ }
26
+
27
+ template <>
28
+ inline int get<int>(jsi::Runtime &, const jsi::Value *value) {
29
+ return value->asNumber();
30
+ }
31
+
32
+ template <>
33
+ inline bool get<bool>(jsi::Runtime &, const jsi::Value *value) {
34
+ if (!value->isBool()) {
35
+ throw jsi::JSINativeException("[Reanimated] Expected a boolean.");
36
+ }
37
+ return value->getBool();
38
+ }
39
+
40
+ template <>
41
+ inline jsi::Object get<jsi::Object>(jsi::Runtime &rt, const jsi::Value *value) {
42
+ return value->asObject(rt);
43
+ }
44
+
45
+ template <>
46
+ inline jsi::Value const &get<jsi::Value const &>(jsi::Runtime &, const jsi::Value *value) {
47
+ return *value;
48
+ }
49
+
50
+ // `convertArgs` functions take a variadic template parameter of target (C++)
51
+ // argument types `Targs` and a `jsi::Value` array `args`, and converts `args`
52
+ // to a tuple of typed C++ arguments to be passed to the native implementation.
53
+ // This is accomplished by dispatching (at compile time) to the correct
54
+ // implementation based on the first type of `Targs`, using SFINAE to select the
55
+ // correct specialization, and concatenating with the result of recursion on the
56
+ // rest of `Targs`
57
+
58
+ // BEGIN implementations for `convertArgs` specializations.
59
+ // specialization for empty `Targs` - returns an empty tuple
60
+ template <typename... TArgs>
61
+ inline std::enable_if_t<(sizeof...(TArgs) == 0), std::tuple<>> convertArgs(jsi::Runtime &, const jsi::Value *) {
62
+ return std::make_tuple();
63
+ }
64
+
65
+ // calls `get<First>` on the first argument to retrieve the native type,
66
+ // then calls recursively on the rest of `args`
67
+ // and returns the concatenation of results
68
+ template <typename T, typename... Rest>
69
+ inline std::tuple<T, Rest...> convertArgs(jsi::Runtime &rt, const jsi::Value *args) {
70
+ auto arg = std::tuple<T>(get<T>(rt, args));
71
+ auto rest = convertArgs<Rest...>(rt, std::next(args));
72
+ return std::tuple_cat(std::move(arg), std::move(rest));
73
+ }
74
+ // END implementations for `convertArgs` specializations.
75
+
76
+ // returns a tuple with the result of casting `args` to appropriate
77
+ // native C++ types needed to call `function`
78
+ template <typename Ret, typename... Args>
79
+ std::tuple<Args...>
80
+ getArgsForFunction(const std::function<Ret(Args...)> &, jsi::Runtime &rt, const jsi::Value *args, const size_t count) {
81
+ react_native_assert(sizeof...(Args) == count && "Argument list has different length than expected");
82
+ return convertArgs<Args...>(rt, args);
83
+ }
84
+
85
+ // returns a tuple with the result of casting `args` to appropriate
86
+ // native C++ types needed to call `function`,
87
+ // passing `rt` as the first argument
88
+ template <typename Ret, typename... Args>
89
+ std::tuple<jsi::Runtime &, Args...> getArgsForFunction(
90
+ const std::function<Ret(jsi::Runtime &, Args...)> &,
91
+ jsi::Runtime &rt,
92
+ const jsi::Value *args,
93
+ const size_t count) {
94
+ react_native_assert(sizeof...(Args) == count && "Argument list has different length than expected");
95
+ return std::tuple_cat(std::tie(rt), convertArgs<Args...>(rt, args));
96
+ }
97
+
98
+ // calls `function` with `args`
99
+ template <typename Ret, typename... Args>
100
+ inline jsi::Value apply(std::function<Ret(Args...)> function, std::tuple<Args...> args) {
101
+ return std::apply(function, std::move(args));
102
+ }
103
+
104
+ // calls string-returning `function` with `args`,
105
+ // and returns the string
106
+ template <typename... Args>
107
+ inline jsi::Value apply(jsi::Runtime &rt, std::function<std::string(Args...)> function, std::tuple<Args...> args) {
108
+ return jsi::String::createFromUtf8(rt, std::apply(function, std::move(args)));
109
+ }
110
+
111
+ // calls void-returning `function` with `args`,
112
+ // and returns `undefined`
113
+ template <typename... Args>
114
+ inline jsi::Value apply(std::function<void(Args...)> function, std::tuple<Args...> args) {
115
+ std::apply(function, std::move(args));
116
+ return jsi::Value::undefined();
117
+ }
118
+
119
+ // returns a function with JSI calling convention
120
+ // from a native function `function`
121
+ template <typename Fun>
122
+ jsi::HostFunctionType createHostFunction(const Fun &function) {
123
+ return [function](jsi::Runtime &rt, const jsi::Value &, const jsi::Value *args, const size_t count) {
124
+ auto argz = getArgsForFunction(function, rt, args, count);
125
+ return apply(function, std::move(argz));
126
+ };
127
+ }
128
+
129
+ // returns a function with JSI calling convention
130
+ // from a native function `function` returning a string
131
+ template <typename... Args>
132
+ jsi::HostFunctionType createHostFunction(const std::function<std::string(Args...)> &function) {
133
+ return [function](jsi::Runtime &rt, const jsi::Value &, const jsi::Value *args, const size_t count) {
134
+ auto argz = getArgsForFunction(function, rt, args, count);
135
+ return apply(rt, function, std::move(argz));
136
+ };
137
+ }
138
+
139
+ // used to determine if `function<Ret(Args...)>`
140
+ // takes `Runtime &` as its first argument
141
+ template <typename... Args>
142
+ struct takes_runtime {
143
+ static constexpr size_t value = 0;
144
+ };
145
+
146
+ // specialization for `function<Ret(Runtime &, Rest...)`
147
+ template <typename... Rest>
148
+ struct takes_runtime<jsi::Runtime &, Rest...> {
149
+ static constexpr size_t value = 1;
150
+ };
151
+
152
+ // creates a JSI compatible function from `function`
153
+ // and installs it as a global function named `name`
154
+ // in the `rt` JS runtime
155
+ template <typename Ret, typename... Args>
156
+ void installJsiFunction(jsi::Runtime &rt, std::string_view name, const std::function<Ret(Args...)> &function) {
157
+ auto clb = createHostFunction(function);
158
+ auto argsCount = static_cast<unsigned int>(sizeof...(Args) - takes_runtime<Args...>::value);
159
+ jsi::Value jsiFunction =
160
+ jsi::Function::createFromHostFunction(rt, jsi::PropNameID::forAscii(rt, name.data()), argsCount, clb);
161
+ rt.global().setProperty(rt, name.data(), jsiFunction);
162
+ }
163
+
164
+ // this should take care of passing types convertible to `function`
165
+ template <typename Fun>
166
+ void installJsiFunction(jsi::Runtime &rt, std::string_view name, Fun function) {
167
+ installJsiFunction(rt, name, std::function(std::forward<Fun>(function)));
168
+ }
169
+
170
+ jsi::Array convertStringToArray(jsi::Runtime &rt, const std::string &value, const unsigned int expectedSize);
171
+
172
+ jsi::Object optimizedFromHostObject(jsi::Runtime &rt, std::shared_ptr<jsi::HostObject> &&hostObject);
173
+
174
+ template <size_t TIndex, size_t TLength>
175
+ requires(TIndex < TLength)
176
+ constexpr const jsi::Value &at(const jsi::Value (&args)[TLength]) noexcept {
177
+ return args[TIndex];
178
+ }
179
+
180
+ template <size_t TLength, typename TFun>
181
+ requires(TLength > 0) &&
182
+ std::is_invocable_v<TFun &&, jsi::Runtime &, const jsi::Value &, const jsi::Value (&)[TLength]>
183
+ void addMethod(jsi::Runtime &rt, jsi::Object &obj, const char *name, TFun &&func) {
184
+ obj.setProperty(
185
+ rt,
186
+ name,
187
+ jsi::Function::createFromHostFunction(
188
+ rt,
189
+ jsi::PropNameID::forAscii(rt, name),
190
+ TLength,
191
+ [func = std::forward<TFun>(func)](
192
+ jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args, size_t) mutable -> jsi::Value {
193
+ using TReturn =
194
+ std::invoke_result_t<TFun &, jsi::Runtime &, const jsi::Value &, const jsi::Value(&)[TLength]>;
195
+ auto &typed = *reinterpret_cast<const jsi::Value(*)[TLength]>(args);
196
+ if constexpr (std::is_void_v<TReturn>) {
197
+ func(rt, thisVal, typed);
198
+ return jsi::Value::undefined();
199
+ } else {
200
+ return func(rt, thisVal, typed);
201
+ }
202
+ }));
203
+ }
204
+
205
+ template <size_t TLength, typename TFun>
206
+ requires(TLength == 0) && std::is_invocable_v<TFun &&, jsi::Runtime &, const jsi::Value &>
207
+ void addMethod(jsi::Runtime &rt, jsi::Object &obj, const char *name, TFun &&func) {
208
+ obj.setProperty(
209
+ rt,
210
+ name,
211
+ jsi::Function::createFromHostFunction(
212
+ rt,
213
+ jsi::PropNameID::forAscii(rt, name),
214
+ 0,
215
+ [func = std::forward<TFun>(func)](
216
+ jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *, size_t) mutable -> jsi::Value {
217
+ using TReturn = std::invoke_result_t<TFun &, jsi::Runtime &, const jsi::Value &>;
218
+ if constexpr (std::is_void_v<TReturn>) {
219
+ func(rt, thisVal);
220
+ return jsi::Value::undefined();
221
+ } else {
222
+ return func(rt, thisVal);
223
+ }
224
+ }));
225
+ }
226
+
227
+ } // namespace reanimated::jsi_utils