react-native-reanimated 3.0.0-rc.8 → 3.0.0

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 (339) hide show
  1. package/Common/cpp/AnimatedSensor/AnimatedSensorModule.cpp +30 -12
  2. package/Common/cpp/AnimatedSensor/AnimatedSensorModule.h +2 -0
  3. package/Common/cpp/Fabric/FabricUtils.cpp +3 -107
  4. package/Common/cpp/Fabric/FabricUtils.h +3 -24
  5. package/Common/cpp/Fabric/ReanimatedUIManagerBinding.cpp +54 -37
  6. package/Common/cpp/LayoutAnimations/LayoutAnimationType.h +8 -0
  7. package/Common/cpp/LayoutAnimations/LayoutAnimationsManager.cpp +81 -26
  8. package/Common/cpp/LayoutAnimations/LayoutAnimationsManager.h +20 -3
  9. package/Common/cpp/NativeModules/NativeReanimatedModule.cpp +122 -121
  10. package/Common/cpp/NativeModules/NativeReanimatedModule.h +21 -14
  11. package/Common/cpp/NativeModules/NativeReanimatedModuleSpec.cpp +15 -7
  12. package/Common/cpp/NativeModules/NativeReanimatedModuleSpec.h +8 -4
  13. package/Common/cpp/ReanimatedRuntime/ReanimatedHermesRuntime.cpp +50 -1
  14. package/Common/cpp/ReanimatedRuntime/ReanimatedHermesRuntime.h +10 -1
  15. package/Common/cpp/ReanimatedRuntime/ReanimatedRuntime.cpp +5 -1
  16. package/Common/cpp/Registries/EventHandlerRegistry.cpp +8 -34
  17. package/Common/cpp/Registries/EventHandlerRegistry.h +7 -13
  18. package/Common/cpp/SharedItems/Shareables.cpp +11 -63
  19. package/Common/cpp/SharedItems/Shareables.h +113 -93
  20. package/Common/cpp/Tools/CollectionUtils.h +14 -0
  21. package/Common/cpp/Tools/JsiUtils.cpp +26 -0
  22. package/Common/cpp/Tools/JsiUtils.h +176 -0
  23. package/Common/cpp/Tools/PlatformDepMethodsHolder.h +5 -5
  24. package/Common/cpp/Tools/ReanimatedVersion.cpp +17 -0
  25. package/Common/cpp/Tools/ReanimatedVersion.h +11 -0
  26. package/Common/cpp/Tools/RuntimeDecorator.cpp +67 -247
  27. package/Common/cpp/Tools/RuntimeDecorator.h +2 -3
  28. package/Common/cpp/Tools/WorkletEventHandler.cpp +3 -2
  29. package/Common/cpp/Tools/WorkletEventHandler.h +14 -6
  30. package/RNReanimated.podspec +2 -1
  31. package/android/CMakeLists.txt +188 -181
  32. package/android/build.gradle +362 -311
  33. package/android/proguard-rules.pro +2 -0
  34. package/android/src/fabric/java/com/swmansion/reanimated/NativeProxy.java +63 -295
  35. package/android/src/main/cpp/LayoutAnimations.cpp +35 -5
  36. package/android/src/main/cpp/LayoutAnimations.h +23 -6
  37. package/android/src/main/cpp/NativeProxy.cpp +143 -98
  38. package/android/src/main/cpp/NativeProxy.h +22 -28
  39. package/android/src/main/java/com/swmansion/reanimated/ReanimatedPackage.java +5 -4
  40. package/android/src/main/java/com/swmansion/reanimated/Utils.java +7 -1
  41. package/android/src/main/java/com/swmansion/reanimated/keyboardObserver/ReanimatedKeyboardEventListener.java +10 -3
  42. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/AnimationsManager.java +218 -35
  43. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/LayoutAnimations.java +43 -17
  44. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/NativeMethodsHolder.java +6 -2
  45. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/SharedElement.java +19 -0
  46. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/SharedTransitionManager.java +610 -0
  47. package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/Snapshot.java +93 -23
  48. package/android/src/main/java/com/swmansion/reanimated/nativeProxy/AnimationFrameCallback.java +19 -0
  49. package/android/src/main/java/com/swmansion/reanimated/nativeProxy/EventHandler.java +35 -0
  50. package/android/src/main/java/com/swmansion/reanimated/nativeProxy/KeyboardEventDataUpdater.java +16 -0
  51. package/android/src/main/java/com/swmansion/reanimated/nativeProxy/NativeProxyCommon.java +206 -0
  52. package/android/src/main/java/com/swmansion/reanimated/nativeProxy/SensorSetter.java +17 -0
  53. package/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensor.java +9 -3
  54. package/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensorContainer.java +3 -4
  55. package/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensorListener.java +31 -7
  56. package/android/src/paper/java/com/swmansion/reanimated/NativeProxy.java +90 -307
  57. package/android/src/reactNativeVersionPatch/ReanimatedUIManager/70/com/swmansion/reanimated/ReanimatedUIManagerFactory.java +16 -0
  58. package/android/src/reactNativeVersionPatch/ReanimatedUIManager/latest/com/swmansion/reanimated/ReanimatedUIManagerFactory.java +63 -0
  59. package/android/src/reactNativeVersionPatch/ReanimatedUIManager/latest/com/swmansion/reanimated/layoutReanimation/ReanimatedUIManager.java +271 -0
  60. package/android/src/reactNativeVersionPatch/nativeHierarchyManager/latest/com/swmansion/reanimated/layoutReanimation/ReanimatedNativeHierarchyManager.java +76 -20
  61. package/ios/LayoutReanimation/REAAnimationsManager.h +31 -5
  62. package/ios/LayoutReanimation/REAAnimationsManager.m +265 -77
  63. package/ios/LayoutReanimation/REAFrame.h +10 -0
  64. package/ios/LayoutReanimation/REAFrame.m +15 -0
  65. package/ios/LayoutReanimation/REAScreensHelper.h +19 -0
  66. package/ios/LayoutReanimation/REAScreensHelper.m +106 -0
  67. package/ios/LayoutReanimation/REASharedElement.h +15 -0
  68. package/ios/LayoutReanimation/REASharedElement.m +16 -0
  69. package/ios/LayoutReanimation/REASharedTransitionManager.h +17 -0
  70. package/ios/LayoutReanimation/REASharedTransitionManager.m +632 -0
  71. package/ios/LayoutReanimation/REASnapshot.h +1 -0
  72. package/ios/LayoutReanimation/REASnapshot.m +96 -11
  73. package/ios/LayoutReanimation/REAUIManager.mm +67 -60
  74. package/ios/REAModule.mm +2 -7
  75. package/ios/REANodesManager.mm +1 -21
  76. package/ios/keyboardObserver/REAKeyboardEventObserver.m +72 -36
  77. package/ios/native/NativeProxy.mm +75 -114
  78. package/ios/native/REAInitializer.mm +2 -7
  79. package/ios/native/REAJSIUtils.h +60 -2
  80. package/ios/sensor/ReanimatedSensor.h +6 -2
  81. package/ios/sensor/ReanimatedSensor.m +43 -7
  82. package/ios/sensor/ReanimatedSensorContainer.h +4 -1
  83. package/ios/sensor/ReanimatedSensorContainer.m +8 -2
  84. package/lib/commonjs/createAnimatedComponent.js +232 -28
  85. package/lib/commonjs/createAnimatedComponent.js.map +1 -1
  86. package/lib/commonjs/reanimated2/Colors.js +43 -22
  87. package/lib/commonjs/reanimated2/Colors.js.map +1 -1
  88. package/lib/commonjs/reanimated2/NativeReanimated/NativeReanimated.js +18 -35
  89. package/lib/commonjs/reanimated2/NativeReanimated/NativeReanimated.js.map +1 -1
  90. package/lib/commonjs/reanimated2/animation/styleAnimation.js +5 -1
  91. package/lib/commonjs/reanimated2/animation/styleAnimation.js.map +1 -1
  92. package/lib/commonjs/reanimated2/animation/util.js +17 -15
  93. package/lib/commonjs/reanimated2/animation/util.js.map +1 -1
  94. package/lib/commonjs/reanimated2/commonTypes.js +33 -1
  95. package/lib/commonjs/reanimated2/commonTypes.js.map +1 -1
  96. package/lib/commonjs/reanimated2/component/FlatList.js +19 -3
  97. package/lib/commonjs/reanimated2/component/FlatList.js.map +1 -1
  98. package/lib/commonjs/reanimated2/core.js +34 -83
  99. package/lib/commonjs/reanimated2/core.js.map +1 -1
  100. package/lib/commonjs/reanimated2/errors.js +66 -0
  101. package/lib/commonjs/reanimated2/errors.js.map +1 -0
  102. package/lib/commonjs/reanimated2/frameCallback/FrameCallbackRegistryUI.js +2 -2
  103. package/lib/commonjs/reanimated2/frameCallback/FrameCallbackRegistryUI.js.map +1 -1
  104. package/lib/commonjs/reanimated2/globals.d.js.map +1 -1
  105. package/lib/commonjs/reanimated2/hook/index.js +0 -6
  106. package/lib/commonjs/reanimated2/hook/index.js.map +1 -1
  107. package/lib/commonjs/reanimated2/hook/useAnimatedKeyboard.js +5 -2
  108. package/lib/commonjs/reanimated2/hook/useAnimatedKeyboard.js.map +1 -1
  109. package/lib/commonjs/reanimated2/hook/useAnimatedReaction.js +13 -1
  110. package/lib/commonjs/reanimated2/hook/useAnimatedReaction.js.map +1 -1
  111. package/lib/commonjs/reanimated2/hook/useAnimatedRef.js +1 -1
  112. package/lib/commonjs/reanimated2/hook/useAnimatedRef.js.map +1 -1
  113. package/lib/commonjs/reanimated2/hook/useAnimatedSensor.js +89 -16
  114. package/lib/commonjs/reanimated2/hook/useAnimatedSensor.js.map +1 -1
  115. package/lib/commonjs/reanimated2/hook/useAnimatedStyle.js +43 -50
  116. package/lib/commonjs/reanimated2/hook/useAnimatedStyle.js.map +1 -1
  117. package/lib/commonjs/reanimated2/hook/useDerivedValue.js +13 -1
  118. package/lib/commonjs/reanimated2/hook/useDerivedValue.js.map +1 -1
  119. package/lib/commonjs/reanimated2/hook/useScrollViewOffset.js +2 -2
  120. package/lib/commonjs/reanimated2/hook/useScrollViewOffset.js.map +1 -1
  121. package/lib/commonjs/reanimated2/hook/utils.js +18 -65
  122. package/lib/commonjs/reanimated2/hook/utils.js.map +1 -1
  123. package/lib/commonjs/reanimated2/index.js +13 -0
  124. package/lib/commonjs/reanimated2/index.js.map +1 -1
  125. package/lib/commonjs/reanimated2/initializers.js +196 -0
  126. package/lib/commonjs/reanimated2/initializers.js.map +1 -0
  127. package/lib/commonjs/reanimated2/interpolateColor.js +96 -19
  128. package/lib/commonjs/reanimated2/interpolateColor.js.map +1 -1
  129. package/lib/commonjs/reanimated2/jestUtils.js +1 -1
  130. package/lib/commonjs/reanimated2/jestUtils.js.map +1 -1
  131. package/lib/commonjs/reanimated2/js-reanimated/JSReanimated.js +101 -16
  132. package/lib/commonjs/reanimated2/js-reanimated/JSReanimated.js.map +1 -1
  133. package/lib/commonjs/reanimated2/js-reanimated/Mapper.js +22 -0
  134. package/lib/commonjs/reanimated2/js-reanimated/Mapper.js.map +1 -1
  135. package/lib/commonjs/reanimated2/js-reanimated/WebSensor.js +2 -0
  136. package/lib/commonjs/reanimated2/js-reanimated/WebSensor.js.map +1 -0
  137. package/lib/commonjs/reanimated2/js-reanimated/commonTypes.js.map +1 -1
  138. package/lib/commonjs/reanimated2/js-reanimated/global.js +4 -9
  139. package/lib/commonjs/reanimated2/js-reanimated/global.js.map +1 -1
  140. package/lib/commonjs/reanimated2/js-reanimated/index.js +0 -1
  141. package/lib/commonjs/reanimated2/js-reanimated/index.js.map +1 -1
  142. package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/commonTypes.js +11 -0
  143. package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/commonTypes.js.map +1 -1
  144. package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/index.js +8 -0
  145. package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/index.js.map +1 -1
  146. package/lib/commonjs/reanimated2/layoutReanimation/animationsManager.js +16 -12
  147. package/lib/commonjs/reanimated2/layoutReanimation/animationsManager.js.map +1 -1
  148. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Bounce.js +16 -23
  149. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Bounce.js.map +1 -1
  150. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.js +8 -14
  151. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.js.map +1 -1
  152. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Roll.js +8 -14
  153. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Roll.js.map +1 -1
  154. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Slide.js +8 -15
  155. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Slide.js.map +1 -1
  156. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Zoom.js +16 -23
  157. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Zoom.js.map +1 -1
  158. package/lib/commonjs/reanimated2/layoutReanimation/index.js +13 -0
  159. package/lib/commonjs/reanimated2/layoutReanimation/index.js.map +1 -1
  160. package/lib/commonjs/reanimated2/layoutReanimation/sharedTransitions/index.js +94 -0
  161. package/lib/commonjs/reanimated2/layoutReanimation/sharedTransitions/index.js.map +1 -0
  162. package/lib/commonjs/reanimated2/mappers.js +18 -6
  163. package/lib/commonjs/reanimated2/mappers.js.map +1 -1
  164. package/lib/commonjs/reanimated2/mock.js +45 -0
  165. package/lib/commonjs/reanimated2/mock.js.map +1 -1
  166. package/lib/commonjs/reanimated2/mutables.js +4 -2
  167. package/lib/commonjs/reanimated2/mutables.js.map +1 -1
  168. package/lib/commonjs/reanimated2/platform-specific/checkVersion.js +42 -0
  169. package/lib/commonjs/reanimated2/platform-specific/checkVersion.js.map +1 -0
  170. package/lib/commonjs/reanimated2/platform-specific/checkVersion.web.js +15 -0
  171. package/lib/commonjs/reanimated2/platform-specific/checkVersion.web.js.map +1 -0
  172. package/lib/commonjs/reanimated2/pluginUtils.js +11 -0
  173. package/lib/commonjs/reanimated2/pluginUtils.js.map +1 -0
  174. package/lib/commonjs/reanimated2/shareables.js +38 -11
  175. package/lib/commonjs/reanimated2/shareables.js.map +1 -1
  176. package/lib/commonjs/reanimated2/threads.js +114 -4
  177. package/lib/commonjs/reanimated2/threads.js.map +1 -1
  178. package/lib/commonjs/reanimated2/utils.js +7 -0
  179. package/lib/commonjs/reanimated2/utils.js.map +1 -1
  180. package/lib/commonjs/reanimated2/valueSetter.js +1 -3
  181. package/lib/commonjs/reanimated2/valueSetter.js.map +1 -1
  182. package/lib/module/createAnimatedComponent.js +229 -29
  183. package/lib/module/createAnimatedComponent.js.map +1 -1
  184. package/lib/module/reanimated2/Colors.js +35 -19
  185. package/lib/module/reanimated2/Colors.js.map +1 -1
  186. package/lib/module/reanimated2/NativeReanimated/NativeReanimated.js +18 -34
  187. package/lib/module/reanimated2/NativeReanimated/NativeReanimated.js.map +1 -1
  188. package/lib/module/reanimated2/animation/styleAnimation.js +5 -1
  189. package/lib/module/reanimated2/animation/styleAnimation.js.map +1 -1
  190. package/lib/module/reanimated2/animation/util.js +17 -16
  191. package/lib/module/reanimated2/animation/util.js.map +1 -1
  192. package/lib/module/reanimated2/commonTypes.js +29 -0
  193. package/lib/module/reanimated2/commonTypes.js.map +1 -1
  194. package/lib/module/reanimated2/component/FlatList.js +18 -4
  195. package/lib/module/reanimated2/component/FlatList.js.map +1 -1
  196. package/lib/module/reanimated2/core.js +30 -76
  197. package/lib/module/reanimated2/core.js.map +1 -1
  198. package/lib/module/reanimated2/errors.js +58 -0
  199. package/lib/module/reanimated2/errors.js.map +1 -0
  200. package/lib/module/reanimated2/frameCallback/FrameCallbackRegistryUI.js +2 -2
  201. package/lib/module/reanimated2/frameCallback/FrameCallbackRegistryUI.js.map +1 -1
  202. package/lib/module/reanimated2/globals.d.js.map +1 -1
  203. package/lib/module/reanimated2/hook/index.js +1 -1
  204. package/lib/module/reanimated2/hook/index.js.map +1 -1
  205. package/lib/module/reanimated2/hook/useAnimatedKeyboard.js +5 -2
  206. package/lib/module/reanimated2/hook/useAnimatedKeyboard.js.map +1 -1
  207. package/lib/module/reanimated2/hook/useAnimatedReaction.js +12 -1
  208. package/lib/module/reanimated2/hook/useAnimatedReaction.js.map +1 -1
  209. package/lib/module/reanimated2/hook/useAnimatedRef.js +2 -2
  210. package/lib/module/reanimated2/hook/useAnimatedRef.js.map +1 -1
  211. package/lib/module/reanimated2/hook/useAnimatedSensor.js +88 -13
  212. package/lib/module/reanimated2/hook/useAnimatedSensor.js.map +1 -1
  213. package/lib/module/reanimated2/hook/useAnimatedStyle.js +45 -52
  214. package/lib/module/reanimated2/hook/useAnimatedStyle.js.map +1 -1
  215. package/lib/module/reanimated2/hook/useDerivedValue.js +12 -1
  216. package/lib/module/reanimated2/hook/useDerivedValue.js.map +1 -1
  217. package/lib/module/reanimated2/hook/useScrollViewOffset.js +2 -2
  218. package/lib/module/reanimated2/hook/useScrollViewOffset.js.map +1 -1
  219. package/lib/module/reanimated2/hook/utils.js +17 -60
  220. package/lib/module/reanimated2/hook/utils.js.map +1 -1
  221. package/lib/module/reanimated2/index.js +1 -0
  222. package/lib/module/reanimated2/index.js.map +1 -1
  223. package/lib/module/reanimated2/initializers.js +182 -0
  224. package/lib/module/reanimated2/initializers.js.map +1 -0
  225. package/lib/module/reanimated2/interpolateColor.js +96 -19
  226. package/lib/module/reanimated2/interpolateColor.js.map +1 -1
  227. package/lib/module/reanimated2/jestUtils.js +1 -1
  228. package/lib/module/reanimated2/jestUtils.js.map +1 -1
  229. package/lib/module/reanimated2/js-reanimated/JSReanimated.js +101 -16
  230. package/lib/module/reanimated2/js-reanimated/JSReanimated.js.map +1 -1
  231. package/lib/module/reanimated2/js-reanimated/Mapper.js +21 -0
  232. package/lib/module/reanimated2/js-reanimated/Mapper.js.map +1 -1
  233. package/lib/module/reanimated2/js-reanimated/WebSensor.js +2 -0
  234. package/lib/module/reanimated2/js-reanimated/WebSensor.js.map +1 -0
  235. package/lib/module/reanimated2/js-reanimated/commonTypes.js.map +1 -1
  236. package/lib/module/reanimated2/js-reanimated/global.js +4 -9
  237. package/lib/module/reanimated2/js-reanimated/global.js.map +1 -1
  238. package/lib/module/reanimated2/js-reanimated/index.js +0 -1
  239. package/lib/module/reanimated2/js-reanimated/index.js.map +1 -1
  240. package/lib/module/reanimated2/layoutReanimation/animationBuilder/commonTypes.js +9 -1
  241. package/lib/module/reanimated2/layoutReanimation/animationBuilder/commonTypes.js.map +1 -1
  242. package/lib/module/reanimated2/layoutReanimation/animationBuilder/index.js +1 -0
  243. package/lib/module/reanimated2/layoutReanimation/animationBuilder/index.js.map +1 -1
  244. package/lib/module/reanimated2/layoutReanimation/animationsManager.js +15 -10
  245. package/lib/module/reanimated2/layoutReanimation/animationsManager.js.map +1 -1
  246. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Bounce.js +16 -21
  247. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Bounce.js.map +1 -1
  248. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.js +8 -12
  249. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.js.map +1 -1
  250. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Roll.js +8 -12
  251. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Roll.js.map +1 -1
  252. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Slide.js +8 -13
  253. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Slide.js.map +1 -1
  254. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Zoom.js +16 -21
  255. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Zoom.js.map +1 -1
  256. package/lib/module/reanimated2/layoutReanimation/index.js +1 -0
  257. package/lib/module/reanimated2/layoutReanimation/index.js.map +1 -1
  258. package/lib/module/reanimated2/layoutReanimation/sharedTransitions/index.js +82 -0
  259. package/lib/module/reanimated2/layoutReanimation/sharedTransitions/index.js.map +1 -0
  260. package/lib/module/reanimated2/mappers.js +16 -6
  261. package/lib/module/reanimated2/mappers.js.map +1 -1
  262. package/lib/module/reanimated2/mock.js +45 -0
  263. package/lib/module/reanimated2/mock.js.map +1 -1
  264. package/lib/module/reanimated2/mutables.js +4 -2
  265. package/lib/module/reanimated2/mutables.js.map +1 -1
  266. package/lib/module/reanimated2/platform-specific/checkVersion.js +35 -0
  267. package/lib/module/reanimated2/platform-specific/checkVersion.js.map +1 -0
  268. package/lib/module/reanimated2/platform-specific/checkVersion.web.js +8 -0
  269. package/lib/module/reanimated2/platform-specific/checkVersion.web.js.map +1 -0
  270. package/lib/module/reanimated2/pluginUtils.js +4 -0
  271. package/lib/module/reanimated2/pluginUtils.js.map +1 -0
  272. package/lib/module/reanimated2/shareables.js +38 -9
  273. package/lib/module/reanimated2/shareables.js.map +1 -1
  274. package/lib/module/reanimated2/threads.js +105 -4
  275. package/lib/module/reanimated2/threads.js.map +1 -1
  276. package/lib/module/reanimated2/utils.js +5 -0
  277. package/lib/module/reanimated2/utils.js.map +1 -1
  278. package/lib/module/reanimated2/valueSetter.js +1 -2
  279. package/lib/module/reanimated2/valueSetter.js.map +1 -1
  280. package/package.json +9 -8
  281. package/{plugin.js → plugin/index.js} +173 -228
  282. package/react-native-reanimated.d.ts +57 -10
  283. package/scripts/reanimated_utils.rb +15 -2
  284. package/src/createAnimatedComponent.tsx +238 -28
  285. package/src/reanimated2/Colors.ts +38 -11
  286. package/src/reanimated2/NativeReanimated/NativeReanimated.ts +63 -41
  287. package/src/reanimated2/animation/styleAnimation.ts +8 -1
  288. package/src/reanimated2/animation/util.ts +29 -16
  289. package/src/reanimated2/commonTypes.ts +28 -1
  290. package/src/reanimated2/component/FlatList.tsx +30 -5
  291. package/src/reanimated2/core.ts +45 -75
  292. package/src/reanimated2/errors.ts +57 -0
  293. package/src/reanimated2/frameCallback/FrameCallbackRegistryUI.ts +2 -2
  294. package/src/reanimated2/globals.d.ts +34 -18
  295. package/src/reanimated2/hook/index.ts +1 -1
  296. package/src/reanimated2/hook/useAnimatedKeyboard.ts +10 -4
  297. package/src/reanimated2/hook/useAnimatedReaction.ts +12 -5
  298. package/src/reanimated2/hook/useAnimatedRef.ts +1 -4
  299. package/src/reanimated2/hook/useAnimatedSensor.ts +88 -11
  300. package/src/reanimated2/hook/useAnimatedStyle.ts +43 -45
  301. package/src/reanimated2/hook/useDerivedValue.ts +8 -1
  302. package/src/reanimated2/hook/useScrollViewOffset.ts +2 -2
  303. package/src/reanimated2/hook/utils.ts +15 -61
  304. package/src/reanimated2/index.ts +1 -0
  305. package/src/reanimated2/initializers.ts +184 -0
  306. package/src/reanimated2/interpolateColor.ts +104 -20
  307. package/src/reanimated2/jestUtils.ts +1 -1
  308. package/src/reanimated2/js-reanimated/JSReanimated.ts +105 -18
  309. package/src/reanimated2/js-reanimated/Mapper.ts +32 -0
  310. package/src/reanimated2/js-reanimated/WebSensor.ts +34 -0
  311. package/src/reanimated2/js-reanimated/commonTypes.ts +0 -1
  312. package/src/reanimated2/js-reanimated/global.ts +4 -8
  313. package/src/reanimated2/js-reanimated/index.ts +0 -1
  314. package/src/reanimated2/layoutReanimation/animationBuilder/commonTypes.ts +13 -1
  315. package/src/reanimated2/layoutReanimation/animationBuilder/index.ts +1 -0
  316. package/src/reanimated2/layoutReanimation/animationsManager.ts +17 -12
  317. package/src/reanimated2/layoutReanimation/defaultAnimations/Bounce.ts +16 -19
  318. package/src/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.ts +14 -11
  319. package/src/reanimated2/layoutReanimation/defaultAnimations/Roll.ts +21 -11
  320. package/src/reanimated2/layoutReanimation/defaultAnimations/Slide.ts +32 -11
  321. package/src/reanimated2/layoutReanimation/defaultAnimations/Zoom.ts +36 -19
  322. package/src/reanimated2/layoutReanimation/index.ts +1 -0
  323. package/src/reanimated2/layoutReanimation/sharedTransitions/index.ts +87 -0
  324. package/src/reanimated2/mappers.ts +17 -6
  325. package/src/reanimated2/mock.ts +128 -0
  326. package/src/reanimated2/mutables.ts +2 -0
  327. package/src/reanimated2/platform-specific/checkVersion.ts +39 -0
  328. package/src/reanimated2/platform-specific/checkVersion.web.ts +6 -0
  329. package/src/reanimated2/pluginUtils.ts +8 -0
  330. package/src/reanimated2/shareables.ts +47 -11
  331. package/src/reanimated2/threads.ts +103 -1
  332. package/src/reanimated2/utils.ts +6 -0
  333. package/src/reanimated2/valueSetter.ts +1 -2
  334. package/lib/commonjs/reanimated2/time.js +0 -55
  335. package/lib/commonjs/reanimated2/time.js.map +0 -1
  336. package/lib/module/reanimated2/time.js +0 -37
  337. package/lib/module/reanimated2/time.js.map +0 -1
  338. package/src/reanimated2/time.ts +0 -30
  339. /package/android/src/{main/java → reactNativeVersionPatch/ReanimatedUIManager/70}/com/swmansion/reanimated/layoutReanimation/ReanimatedUIManager.java +0 -0
@@ -1,27 +1,112 @@
1
1
  #import <Foundation/Foundation.h>
2
+ #import <RNReanimated/REAScreensHelper.h>
2
3
  #import <RNReanimated/REASnapshot.h>
4
+ #import <React/UIView+React.h>
3
5
 
4
6
  NS_ASSUME_NONNULL_BEGIN
5
7
 
6
- @implementation REASnapshot {
7
- UIView *_view;
8
- }
8
+ @implementation REASnapshot
9
+
10
+ const int ScreenStackPresentationModal = 1; // RNSScreenStackPresentationModal
11
+ const int DEFAULT_MODAL_TOP_OFFSET = 69; // Default iOS modal is shifted from screen top edge by 69px
9
12
 
10
13
  - (instancetype)init:(UIView *)view
11
14
  {
12
15
  self = [super init];
13
- _view = view;
14
- UIView *windowView = UIApplication.sharedApplication.keyWindow;
15
- CGPoint originFromRootPerspective = [[view superview] convertPoint:view.center toView:windowView];
16
+ [self makeSnapshotForView:view useAbsolutePositionOnly:NO];
17
+ return self;
18
+ }
19
+
20
+ - (instancetype)initWithAbsolutePosition:(UIView *)view
21
+ {
22
+ self = [super init];
23
+ [self makeSnapshotForView:view useAbsolutePositionOnly:YES];
24
+ return self;
25
+ }
26
+
27
+ - (void)makeSnapshotForView:(UIView *)view useAbsolutePositionOnly:(BOOL)useAbsolutePositionOnly
28
+ {
29
+ UIView *mainWindow = UIApplication.sharedApplication.keyWindow;
30
+ CGPoint absolutePosition = [[view superview] convertPoint:view.center toView:mainWindow];
16
31
  _values = [NSMutableDictionary new];
32
+ _values[@"windowWidth"] = [NSNumber numberWithDouble:mainWindow.bounds.size.width];
33
+ _values[@"windowHeight"] = [NSNumber numberWithDouble:mainWindow.bounds.size.height];
17
34
  _values[@"width"] = [NSNumber numberWithDouble:(double)(view.bounds.size.width)];
18
35
  _values[@"height"] = [NSNumber numberWithDouble:(double)(view.bounds.size.height)];
19
- _values[@"originX"] = [NSNumber numberWithDouble:view.center.x - view.bounds.size.width / 2.0];
20
- _values[@"originY"] = [NSNumber numberWithDouble:view.center.y - view.bounds.size.height / 2.0];
21
- _values[@"globalOriginX"] = [NSNumber numberWithDouble:originFromRootPerspective.x - view.bounds.size.width / 2.0];
22
- _values[@"globalOriginY"] = [NSNumber numberWithDouble:originFromRootPerspective.y - view.bounds.size.height / 2.0];
36
+ _values[@"globalOriginX"] = [NSNumber numberWithDouble:absolutePosition.x - view.bounds.size.width / 2.0];
37
+ _values[@"globalOriginY"] = [NSNumber numberWithDouble:absolutePosition.y - view.bounds.size.height / 2.0];
38
+ if (useAbsolutePositionOnly) {
39
+ _values[@"originX"] = _values[@"globalOriginX"];
40
+ _values[@"originY"] = _values[@"globalOriginY"];
41
+ _values[@"originXByParent"] = [NSNumber numberWithDouble:view.center.x - view.bounds.size.width / 2.0];
42
+ _values[@"originYByParent"] = [NSNumber numberWithDouble:view.center.y - view.bounds.size.height / 2.0];
23
43
 
24
- return self;
44
+ UIView *navigationContainer = view.reactViewController.navigationController.view;
45
+ UIView *header = [navigationContainer.subviews count] > 1 ? navigationContainer.subviews[1] : nil;
46
+ if (header != nil) {
47
+ CGFloat headerHeight = header.frame.size.height;
48
+ CGFloat headerOriginY = header.frame.origin.y;
49
+ UIView *screen = [REAScreensHelper getScreenForView:view];
50
+ if ([REAScreensHelper isScreenModal:screen] && screen.superview == nil) {
51
+ int additionalModalOffset = 0;
52
+ UIView *screenWrapper = [REAScreensHelper getScreenWrapper:view];
53
+ int screenType = [REAScreensHelper getScreenType:screenWrapper];
54
+ if (screenType == ScreenStackPresentationModal) {
55
+ additionalModalOffset = DEFAULT_MODAL_TOP_OFFSET;
56
+ }
57
+ float originY = [_values[@"originY"] doubleValue] + headerHeight + headerOriginY + additionalModalOffset;
58
+ _values[@"originY"] = @(originY);
59
+ }
60
+ _values[@"headerHeight"] = @(headerHeight);
61
+ } else {
62
+ _values[@"headerHeight"] = @(0);
63
+ }
64
+
65
+ UIView *transformedView = [self findTransformedView:view];
66
+ if (transformedView != nil) {
67
+ // iOS affine matrix: https://developer.apple.com/documentation/corefoundation/cgaffinetransform?language=objc
68
+ CGAffineTransform transform = transformedView.transform;
69
+ NSNumber *a = @(transform.a);
70
+ NSNumber *b = @(transform.b);
71
+ NSNumber *c = @(transform.c);
72
+ NSNumber *d = @(transform.d);
73
+ NSNumber *tx = @(transform.tx);
74
+ NSNumber *ty = @(transform.tx);
75
+ _values[@"transformMatrix"] = @[ a, b, @(0), c, d, @(0), tx, ty, @(1) ];
76
+ _values[@"originX"] = @([_values[@"originX"] doubleValue] - [tx doubleValue]);
77
+ _values[@"originY"] = @([_values[@"originY"] doubleValue] - [ty doubleValue]);
78
+ } else {
79
+ // Identity matrix is an default value
80
+ _values[@"transformMatrix"] = @[ @(1), @(0), @(0), @(0), @(1), @(0), @(0), @(0), @(1) ];
81
+ }
82
+ } else {
83
+ _values[@"originX"] = [NSNumber numberWithDouble:view.center.x - view.bounds.size.width / 2.0];
84
+ _values[@"originY"] = [NSNumber numberWithDouble:view.center.y - view.bounds.size.height / 2.0];
85
+ }
86
+ }
87
+
88
+ - (UIView *)findTransformedView:(UIView *)view
89
+ {
90
+ UIView *transformedView;
91
+ bool isTransformed = false;
92
+ do {
93
+ if (transformedView == nil) {
94
+ transformedView = view;
95
+ } else {
96
+ transformedView = transformedView.superview;
97
+ }
98
+ CGAffineTransform transform = transformedView.transform;
99
+ isTransformed = transform.a != 1 || transform.b != 0 || transform.c != 0 || transform.d != 1 || transform.tx != 0 ||
100
+ transform.ty != 0;
101
+ } while (!isTransformed &&
102
+ transformedView != nil
103
+ // Ignore views above screen
104
+ && ![REAScreensHelper isRNSScreenType:transformedView]);
105
+
106
+ if (isTransformed && transformedView != nil) {
107
+ return transformedView;
108
+ }
109
+ return nil;
25
110
  }
26
111
 
27
112
  @end
@@ -24,12 +24,6 @@
24
24
  removeAtIndices:(NSArray<NSNumber *> *)removeAtIndices
25
25
  registry:(NSMutableDictionary<NSNumber *, id<RCTComponent>> *)registry;
26
26
 
27
- - (void)_removeChildren:(NSArray<UIView *> *)children fromContainer:(UIView *)container;
28
-
29
- - (void)_removeChildren:(NSArray<UIView *> *)children
30
- fromContainer:(UIView *)container
31
- withAnimation:(RCTLayoutAnimationGroup *)animation;
32
-
33
27
  - (RCTViewManagerUIBlock)uiBlockWithLayoutUpdateForRootView:(RCTRootShadowView *)rootShadowView;
34
28
 
35
29
  - (NSArray<id<RCTComponent>> *)_childrenToRemoveFromContainer:(id<RCTComponent>)container
@@ -37,7 +31,6 @@
37
31
  @end
38
32
 
39
33
  @implementation REAUIManager {
40
- RCTLayoutAnimationGroup *_reactLayoutAnimationGroup;
41
34
  NSMutableDictionary<NSNumber *, NSMutableSet<id<RCTComponent>> *> *_toBeRemovedRegister;
42
35
  NSMutableDictionary<NSNumber *, NSNumber *> *_parentMapper;
43
36
  REAAnimationsManager *_animationsManager;
@@ -49,15 +42,14 @@
49
42
  return NSStringFromClass([RCTUIManager class]);
50
43
  }
51
44
 
45
+ - (void)invalidate
46
+ {
47
+ [_animationsManager invalidate];
48
+ [super invalidate];
49
+ }
50
+
52
51
  - (void)setBridge:(RCTBridge *)bridge
53
52
  {
54
- // setting a layout animation group with a deleting animation in order to
55
- // allows us to call a different method in RCTUIManager for cleaning up exiting views
56
- RCTLayoutAnimation *deletingAnimation = [[RCTLayoutAnimation alloc] initWithDuration:0 config:@{}];
57
- _reactLayoutAnimationGroup = [[RCTLayoutAnimationGroup alloc] initWithCreatingLayoutAnimation:nil
58
- updatingLayoutAnimation:nil
59
- deletingLayoutAnimation:deletingAnimation
60
- callback:nil];
61
53
  if (!_blockSetter) {
62
54
  _blockSetter = true;
63
55
 
@@ -79,21 +71,6 @@
79
71
  }
80
72
  }
81
73
 
82
- - (void)_removeChildren:(NSArray<UIView *> *)children
83
- fromContainer:(UIView *)container
84
- withAnimation:(RCTLayoutAnimationGroup *)animation
85
- {
86
- if (animation == _reactLayoutAnimationGroup) {
87
- // if a removed view in this batch has an `exiting` animation,
88
- // let REAAnimationsManager handle the removal
89
- [_animationsManager removeChildren:children fromContainer:container];
90
- } else {
91
- // otherwise, if there's a layout animation group set,
92
- // delegate to the React Native implementation for layout animations
93
- [super _removeChildren:children fromContainer:container withAnimation:animation];
94
- }
95
- }
96
-
97
74
  - (void)_manageChildren:(NSNumber *)containerTag
98
75
  moveFromIndices:(NSArray<NSNumber *> *)moveFromIndices
99
76
  moveToIndices:(NSArray<NSNumber *> *)moveToIndices
@@ -102,40 +79,32 @@
102
79
  removeAtIndices:(NSArray<NSNumber *> *)removeAtIndices
103
80
  registry:(NSMutableDictionary<NSNumber *, id<RCTComponent>> *)registry
104
81
  {
105
- if (!reanimated::FeaturesConfig::isLayoutAnimationEnabled()) {
106
- [super _manageChildren:containerTag
107
- moveFromIndices:moveFromIndices
108
- moveToIndices:moveToIndices
109
- addChildReactTags:addChildReactTags
110
- addAtIndices:addAtIndices
111
- removeAtIndices:removeAtIndices
112
- registry:registry];
113
- return;
114
- }
82
+ bool isLayoutAnimationEnabled = reanimated::FeaturesConfig::isLayoutAnimationEnabled();
83
+ id<RCTComponent> container;
84
+ NSArray<id<RCTComponent>> *permanentlyRemovedChildren;
85
+ BOOL containerIsRootOfViewController = NO;
86
+ if (isLayoutAnimationEnabled) {
87
+ container = registry[containerTag];
88
+ permanentlyRemovedChildren = [self _childrenToRemoveFromContainer:container atIndices:removeAtIndices];
89
+
90
+ if ([container isKindOfClass:[UIView class]]) {
91
+ UIViewController *controller = ((UIView *)container).reactViewController;
92
+ UIViewController *parentController = ((UIView *)container).superview.reactViewController;
93
+ containerIsRootOfViewController = controller != parentController;
94
+ }
115
95
 
116
- // Reanimated changes /start
117
- BOOL isUIViewRegistry = ((id)registry == (id)[self valueForKey:@"_viewRegistry"]);
118
- if (isUIViewRegistry) {
119
- BOOL wasProxyRemovalSet = [self valueForKey:@"_layoutAnimationGroup"] == _reactLayoutAnimationGroup;
120
- BOOL wantProxyRemoval = NO;
121
- if (!wasProxyRemovalSet) {
122
- id<RCTComponent> container = registry[containerTag];
96
+ // we check if the container we`re removing from is a root view
97
+ // of some view controller. In that case, we skip running exiting animations
98
+ // in its children, to prevent issues with RN Screens.
99
+ if (containerIsRootOfViewController) {
123
100
  NSArray<id<RCTComponent>> *permanentlyRemovedChildren = [self _childrenToRemoveFromContainer:container
124
101
  atIndices:removeAtIndices];
125
- for (UIView *removedChild in permanentlyRemovedChildren) {
126
- if ([_animationsManager wantsHandleRemovalOfView:removedChild]) {
127
- wantProxyRemoval = YES;
128
- break;
129
- }
130
- [_animationsManager removeAnimationsFromSubtree:removedChild];
131
- }
132
- if (wantProxyRemoval) {
133
- // set layout animation group
134
- [super setNextLayoutAnimationGroup:_reactLayoutAnimationGroup];
102
+ for (UIView *view in permanentlyRemovedChildren) {
103
+ [_animationsManager endAnimationsRecursive:view];
135
104
  }
105
+ [_animationsManager removeAnimationsFromSubtree:(UIView *)container];
136
106
  }
137
107
  }
138
- // Reanimated changes /end
139
108
 
140
109
  [super _manageChildren:containerTag
141
110
  moveFromIndices:moveFromIndices
@@ -144,6 +113,28 @@
144
113
  addAtIndices:addAtIndices
145
114
  removeAtIndices:removeAtIndices
146
115
  registry:registry];
116
+
117
+ if (!isLayoutAnimationEnabled) {
118
+ return;
119
+ }
120
+
121
+ if (containerIsRootOfViewController) {
122
+ return;
123
+ }
124
+
125
+ // we sort the (index, view) pairs to make sure we insert views back in order
126
+ NSMutableArray<NSArray<id> *> *removedViewsWithIndices = [NSMutableArray new];
127
+ for (int i = 0; i < removeAtIndices.count; i++) {
128
+ removedViewsWithIndices[i] = @[ removeAtIndices[i], permanentlyRemovedChildren[i] ];
129
+ }
130
+ [removedViewsWithIndices
131
+ sortUsingComparator:^NSComparisonResult(NSArray<id> *_Nonnull obj1, NSArray<id> *_Nonnull obj2) {
132
+ return [(NSNumber *)obj1[0] compare:(NSNumber *)obj2[0]];
133
+ }];
134
+
135
+ [_animationsManager reattachAnimatedChildren:permanentlyRemovedChildren
136
+ toContainer:container
137
+ atIndices:removeAtIndices];
147
138
  }
148
139
 
149
140
  - (void)callAnimationForTree:(UIView *)view parentTag:(NSNumber *)parentTag
@@ -238,6 +229,8 @@
238
229
 
239
230
  __block NSUInteger completionsCalled = 0;
240
231
 
232
+ NSMutableDictionary<NSNumber *, REASnapshot *> *snapshotsBefore = [NSMutableDictionary dictionary];
233
+
241
234
  NSInteger index = 0;
242
235
  for (NSNumber *reactTag in reactTags) {
243
236
  RCTFrameData frameData = frameDataArray[index++];
@@ -274,6 +267,7 @@
274
267
 
275
268
  // Reanimated changes /start
276
269
  REASnapshot *snapshotBefore = isNew ? nil : [self->_animationsManager prepareSnapshotBeforeMountForView:view];
270
+ snapshotsBefore[reactTag] = snapshotBefore;
277
271
  // Reanimated changes /end
278
272
 
279
273
  if (creatingLayoutAnimation) {
@@ -320,17 +314,30 @@
320
314
  [view reactSetFrame:frame];
321
315
  completion(YES);
322
316
  }
317
+ }
318
+
319
+ // Reanimated changes /start
320
+ index = 0;
321
+ for (NSNumber *reactTag in reactTags) {
322
+ RCTFrameData frameData = frameDataArray[index++];
323
+ UIView *view = viewRegistry[reactTag];
324
+ BOOL isNew = frameData.isNew;
325
+ CGRect frame = frameData.frame;
326
+
327
+ REASnapshot *snapshotBefore = snapshotsBefore[reactTag];
323
328
 
324
- // Reanimated changes /start
325
329
  if (isNew || snapshotBefore != nil) {
326
- [self->_animationsManager viewDidMount:view withBeforeSnapshot:snapshotBefore];
330
+ [self->_animationsManager viewDidMount:view withBeforeSnapshot:snapshotBefore withNewFrame:frame];
327
331
  }
328
- // Reanimated changes /end
329
332
  }
333
+
330
334
  // Clean up
331
335
  // below line serves as this one uiManager->_layoutAnimationGroup = nil;, because we don't have access to the
332
336
  // private field
333
337
  [uiManager setNextLayoutAnimationGroup:nil];
338
+
339
+ [self->_animationsManager viewsDidLayout];
340
+ // Reanimated changes /end
334
341
  };
335
342
  }
336
343
 
package/ios/REAModule.mm CHANGED
@@ -19,14 +19,9 @@
19
19
 
20
20
  #import <RNReanimated/REAModule.h>
21
21
  #import <RNReanimated/REANodesManager.h>
22
+ #import <RNReanimated/ReanimatedVersion.h>
22
23
  #import <RNReanimated/SingleInstanceChecker.h>
23
24
 
24
- #ifdef REANIMATED_VERSION
25
- #define STRINGIZE(x) #x
26
- #define STRINGIZE2(x) STRINGIZE(x)
27
- #define REANIMATED_VERSION_STRING STRINGIZE2(REANIMATED_VERSION)
28
- #endif // REANIMATED_VERSION
29
-
30
25
  using namespace facebook::react;
31
26
  using namespace reanimated;
32
27
 
@@ -222,7 +217,7 @@ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(installTurboModule)
222
217
 
223
218
  runtime.global().setProperty(runtime, "_IS_FABRIC", true);
224
219
 
225
- auto version = jsi::String::createFromUtf8(runtime, REANIMATED_VERSION_STRING);
220
+ auto version = getReanimatedVersionString(runtime);
226
221
  runtime.global().setProperty(runtime, "_REANIMATED_VERSION_CPP", version);
227
222
 
228
223
  runtime.global().setProperty(
@@ -313,24 +313,6 @@ using namespace facebook::react;
313
313
  }
314
314
  #endif
315
315
 
316
- - (BOOL)isDirectEvent:(id<RCTEvent>)event
317
- {
318
- static NSArray<NSString *> *directEventNames;
319
- static dispatch_once_t directEventNamesToken;
320
- dispatch_once(&directEventNamesToken, ^{
321
- directEventNames = @[
322
- @"topContentSizeChange",
323
- @"topMomentumScrollBegin",
324
- @"topMomentumScrollEnd",
325
- @"topScroll",
326
- @"topScrollBeginDrag",
327
- @"topScrollEndDrag"
328
- ];
329
- });
330
-
331
- return [directEventNames containsObject:RCTNormalizeInputEventName(event.eventName)];
332
- }
333
-
334
316
  - (void)dispatchEvent:(id<RCTEvent>)event
335
317
  {
336
318
  NSString *key = [NSString stringWithFormat:@"%@%@", event.viewTag, RCTNormalizeInputEventName(event.eventName)];
@@ -349,9 +331,7 @@ using namespace facebook::react;
349
331
  return;
350
332
  }
351
333
  eventHandler(eventHash, event);
352
- if ([strongSelf isDirectEvent:event]) {
353
- [strongSelf performOperations];
354
- }
334
+ [strongSelf performOperations];
355
335
  });
356
336
  }
357
337
  }
@@ -18,6 +18,7 @@ typedef NS_ENUM(NSUInteger, KeyboardState) {
18
18
  int _windowsCount;
19
19
  UIView *_keyboardView;
20
20
  KeyboardState _state;
21
+ bool _shouldInvalidateDisplayLink;
21
22
  }
22
23
 
23
24
  - (instancetype)init
@@ -26,6 +27,14 @@ typedef NS_ENUM(NSUInteger, KeyboardState) {
26
27
  _listeners = [[NSMutableDictionary alloc] init];
27
28
  _nextListenerId = @0;
28
29
  _state = UNKNOWN;
30
+ _shouldInvalidateDisplayLink = false;
31
+
32
+ NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
33
+
34
+ [notificationCenter addObserver:self
35
+ selector:@selector(clearListeners)
36
+ name:RCTBridgeDidInvalidateModulesNotification
37
+ object:nil];
29
38
  return self;
30
39
  }
31
40
 
@@ -79,15 +88,19 @@ typedef NS_ENUM(NSUInteger, KeyboardState) {
79
88
 
80
89
  - (void)runAnimation
81
90
  {
82
- displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(updateKeyboardFrame)];
83
- [displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];
91
+ if (!displayLink) {
92
+ displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(updateKeyboardFrame)];
93
+ [displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];
94
+ }
84
95
  }
85
96
 
86
97
  - (void)stopAnimation
87
98
  {
88
- [displayLink invalidate];
89
- displayLink = nil;
90
99
  [self updateKeyboardFrame];
100
+ // there might be a case that keyboard will change height in the next frame
101
+ // (for example changing keyboard language so that suggestions appear)
102
+ // so we invalidate display link after we handle that in the next frame
103
+ _shouldInvalidateDisplayLink = true;
91
104
  }
92
105
 
93
106
  - (void)updateKeyboardFrame
@@ -101,6 +114,12 @@ typedef NS_ENUM(NSUInteger, KeyboardState) {
101
114
  for (NSString *key in _listeners.allKeys) {
102
115
  ((KeyboardEventListenerBlock)_listeners[key])(_state, keyboardHeight);
103
116
  }
117
+
118
+ if (_shouldInvalidateDisplayLink) {
119
+ _shouldInvalidateDisplayLink = false;
120
+ [displayLink invalidate];
121
+ displayLink = nil;
122
+ }
104
123
  }
105
124
 
106
125
  - (CGFloat)computeKeyboardHeight:(UIView *)keyboardView
@@ -139,44 +158,51 @@ typedef NS_ENUM(NSUInteger, KeyboardState) {
139
158
  {
140
159
  NSNumber *listenerId = [_nextListenerId copy];
141
160
  _nextListenerId = [NSNumber numberWithInt:[_nextListenerId intValue] + 1];
142
- if ([_listeners count] == 0) {
143
- NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
144
-
145
- [notificationCenter addObserver:self
146
- selector:@selector(keyboardWillHide:)
147
- name:UIKeyboardWillHideNotification
148
- object:nil];
149
-
150
- [notificationCenter addObserver:self
151
- selector:@selector(keyboardWillShow:)
152
- name:UIKeyboardWillShowNotification
153
- object:nil];
154
-
155
- [notificationCenter addObserver:self
156
- selector:@selector(keyboardDidHide:)
157
- name:UIKeyboardDidHideNotification
158
- object:nil];
159
-
160
- [notificationCenter addObserver:self
161
- selector:@selector(keyboardDidShow:)
162
- name:UIKeyboardDidShowNotification
163
- object:nil];
164
- }
161
+ RCTExecuteOnMainQueue(^() {
162
+ if ([self->_listeners count] == 0) {
163
+ NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
164
+
165
+ [notificationCenter addObserver:self
166
+ selector:@selector(keyboardWillHide:)
167
+ name:UIKeyboardWillHideNotification
168
+ object:nil];
169
+
170
+ [notificationCenter addObserver:self
171
+ selector:@selector(keyboardWillShow:)
172
+ name:UIKeyboardWillShowNotification
173
+ object:nil];
174
+
175
+ [notificationCenter addObserver:self
176
+ selector:@selector(keyboardDidHide:)
177
+ name:UIKeyboardDidHideNotification
178
+ object:nil];
179
+
180
+ [notificationCenter addObserver:self
181
+ selector:@selector(keyboardDidShow:)
182
+ name:UIKeyboardDidShowNotification
183
+ object:nil];
184
+ }
165
185
 
166
- [_listeners setObject:listener forKey:listenerId];
167
- if (_state == UNKNOWN) {
168
- [self recognizeInitialKeyboardState];
169
- }
186
+ [self->_listeners setObject:listener forKey:listenerId];
187
+ if (self->_state == UNKNOWN) {
188
+ [self recognizeInitialKeyboardState];
189
+ }
190
+ });
170
191
  return [listenerId intValue];
171
192
  }
172
193
 
173
194
  - (void)unsubscribeFromKeyboardEvents:(int)listenerId
174
195
  {
175
- NSNumber *_listenerId = [NSNumber numberWithInt:listenerId];
176
- [_listeners removeObjectForKey:_listenerId];
177
- if ([_listeners count] == 0) {
178
- [[NSNotificationCenter defaultCenter] removeObserver:self];
179
- }
196
+ RCTExecuteOnMainQueue(^() {
197
+ NSNumber *_listenerId = [NSNumber numberWithInt:listenerId];
198
+ [self->_listeners removeObjectForKey:_listenerId];
199
+ if ([self->_listeners count] == 0) {
200
+ [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
201
+ [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
202
+ [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardDidHideNotification object:nil];
203
+ [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardDidShowNotification object:nil];
204
+ }
205
+ });
180
206
  }
181
207
 
182
208
  - (void)recognizeInitialKeyboardState
@@ -193,6 +219,16 @@ typedef NS_ENUM(NSUInteger, KeyboardState) {
193
219
  });
194
220
  }
195
221
 
222
+ - (void)clearListeners
223
+ {
224
+ RCTUnsafeExecuteOnMainQueueSync(^() {
225
+ [self->_listeners removeAllObjects];
226
+ [self->displayLink invalidate];
227
+ self->displayLink = nil;
228
+ [[NSNotificationCenter defaultCenter] removeObserver:self];
229
+ });
230
+ }
231
+
196
232
  #endif
197
233
 
198
234
  @end