react-native-reanimated 3.0.0-rc.9 → 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 (329) 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 +105 -109
  10. package/Common/cpp/NativeModules/NativeReanimatedModule.h +19 -12
  11. package/Common/cpp/NativeModules/NativeReanimatedModuleSpec.cpp +15 -7
  12. package/Common/cpp/NativeModules/NativeReanimatedModuleSpec.h +6 -2
  13. package/Common/cpp/ReanimatedRuntime/ReanimatedHermesRuntime.cpp +20 -1
  14. package/Common/cpp/ReanimatedRuntime/ReanimatedHermesRuntime.h +9 -0
  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 +9 -63
  19. package/Common/cpp/SharedItems/Shareables.h +77 -72
  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 +49 -230
  27. package/Common/cpp/Tools/RuntimeDecorator.h +0 -2
  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 +28 -4
  62. package/ios/LayoutReanimation/REAAnimationsManager.m +216 -61
  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 +64 -17
  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 +16 -33
  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/core.js +33 -14
  97. package/lib/commonjs/reanimated2/core.js.map +1 -1
  98. package/lib/commonjs/reanimated2/frameCallback/FrameCallbackRegistryUI.js +2 -2
  99. package/lib/commonjs/reanimated2/frameCallback/FrameCallbackRegistryUI.js.map +1 -1
  100. package/lib/commonjs/reanimated2/globals.d.js.map +1 -1
  101. package/lib/commonjs/reanimated2/hook/index.js +0 -6
  102. package/lib/commonjs/reanimated2/hook/index.js.map +1 -1
  103. package/lib/commonjs/reanimated2/hook/useAnimatedKeyboard.js +5 -2
  104. package/lib/commonjs/reanimated2/hook/useAnimatedKeyboard.js.map +1 -1
  105. package/lib/commonjs/reanimated2/hook/useAnimatedReaction.js +13 -1
  106. package/lib/commonjs/reanimated2/hook/useAnimatedReaction.js.map +1 -1
  107. package/lib/commonjs/reanimated2/hook/useAnimatedRef.js +1 -1
  108. package/lib/commonjs/reanimated2/hook/useAnimatedRef.js.map +1 -1
  109. package/lib/commonjs/reanimated2/hook/useAnimatedSensor.js +89 -16
  110. package/lib/commonjs/reanimated2/hook/useAnimatedSensor.js.map +1 -1
  111. package/lib/commonjs/reanimated2/hook/useAnimatedStyle.js +43 -40
  112. package/lib/commonjs/reanimated2/hook/useAnimatedStyle.js.map +1 -1
  113. package/lib/commonjs/reanimated2/hook/useDerivedValue.js +13 -1
  114. package/lib/commonjs/reanimated2/hook/useDerivedValue.js.map +1 -1
  115. package/lib/commonjs/reanimated2/hook/useScrollViewOffset.js +2 -2
  116. package/lib/commonjs/reanimated2/hook/useScrollViewOffset.js.map +1 -1
  117. package/lib/commonjs/reanimated2/hook/utils.js +18 -65
  118. package/lib/commonjs/reanimated2/hook/utils.js.map +1 -1
  119. package/lib/commonjs/reanimated2/index.js +13 -0
  120. package/lib/commonjs/reanimated2/index.js.map +1 -1
  121. package/lib/commonjs/reanimated2/initializers.js +71 -32
  122. package/lib/commonjs/reanimated2/initializers.js.map +1 -1
  123. package/lib/commonjs/reanimated2/interpolateColor.js +96 -19
  124. package/lib/commonjs/reanimated2/interpolateColor.js.map +1 -1
  125. package/lib/commonjs/reanimated2/jestUtils.js +1 -1
  126. package/lib/commonjs/reanimated2/jestUtils.js.map +1 -1
  127. package/lib/commonjs/reanimated2/js-reanimated/JSReanimated.js +103 -13
  128. package/lib/commonjs/reanimated2/js-reanimated/JSReanimated.js.map +1 -1
  129. package/lib/commonjs/reanimated2/js-reanimated/Mapper.js +22 -0
  130. package/lib/commonjs/reanimated2/js-reanimated/Mapper.js.map +1 -1
  131. package/lib/commonjs/reanimated2/js-reanimated/WebSensor.js +2 -0
  132. package/lib/commonjs/reanimated2/js-reanimated/WebSensor.js.map +1 -0
  133. package/lib/commonjs/reanimated2/js-reanimated/commonTypes.js.map +1 -1
  134. package/lib/commonjs/reanimated2/js-reanimated/global.js +0 -2
  135. package/lib/commonjs/reanimated2/js-reanimated/global.js.map +1 -1
  136. package/lib/commonjs/reanimated2/js-reanimated/index.js +0 -1
  137. package/lib/commonjs/reanimated2/js-reanimated/index.js.map +1 -1
  138. package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/commonTypes.js +11 -0
  139. package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/commonTypes.js.map +1 -1
  140. package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/index.js +8 -0
  141. package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/index.js.map +1 -1
  142. package/lib/commonjs/reanimated2/layoutReanimation/animationsManager.js +17 -9
  143. package/lib/commonjs/reanimated2/layoutReanimation/animationsManager.js.map +1 -1
  144. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Bounce.js +16 -23
  145. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Bounce.js.map +1 -1
  146. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.js +8 -14
  147. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.js.map +1 -1
  148. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Roll.js +8 -14
  149. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Roll.js.map +1 -1
  150. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Slide.js +8 -15
  151. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Slide.js.map +1 -1
  152. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Zoom.js +16 -23
  153. package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Zoom.js.map +1 -1
  154. package/lib/commonjs/reanimated2/layoutReanimation/index.js +13 -0
  155. package/lib/commonjs/reanimated2/layoutReanimation/index.js.map +1 -1
  156. package/lib/commonjs/reanimated2/layoutReanimation/sharedTransitions/index.js +94 -0
  157. package/lib/commonjs/reanimated2/layoutReanimation/sharedTransitions/index.js.map +1 -0
  158. package/lib/commonjs/reanimated2/mappers.js +18 -6
  159. package/lib/commonjs/reanimated2/mappers.js.map +1 -1
  160. package/lib/commonjs/reanimated2/mock.js +20 -1
  161. package/lib/commonjs/reanimated2/mock.js.map +1 -1
  162. package/lib/commonjs/reanimated2/mutables.js +4 -2
  163. package/lib/commonjs/reanimated2/mutables.js.map +1 -1
  164. package/lib/commonjs/reanimated2/platform-specific/checkVersion.js +42 -0
  165. package/lib/commonjs/reanimated2/platform-specific/checkVersion.js.map +1 -0
  166. package/lib/commonjs/reanimated2/platform-specific/checkVersion.web.js +15 -0
  167. package/lib/commonjs/reanimated2/platform-specific/checkVersion.web.js.map +1 -0
  168. package/lib/commonjs/reanimated2/pluginUtils.js +11 -0
  169. package/lib/commonjs/reanimated2/pluginUtils.js.map +1 -0
  170. package/lib/commonjs/reanimated2/shareables.js +36 -15
  171. package/lib/commonjs/reanimated2/shareables.js.map +1 -1
  172. package/lib/commonjs/reanimated2/threads.js +114 -4
  173. package/lib/commonjs/reanimated2/threads.js.map +1 -1
  174. package/lib/commonjs/reanimated2/utils.js +7 -0
  175. package/lib/commonjs/reanimated2/utils.js.map +1 -1
  176. package/lib/commonjs/reanimated2/valueSetter.js +1 -3
  177. package/lib/commonjs/reanimated2/valueSetter.js.map +1 -1
  178. package/lib/module/createAnimatedComponent.js +229 -29
  179. package/lib/module/createAnimatedComponent.js.map +1 -1
  180. package/lib/module/reanimated2/Colors.js +35 -19
  181. package/lib/module/reanimated2/Colors.js.map +1 -1
  182. package/lib/module/reanimated2/NativeReanimated/NativeReanimated.js +16 -32
  183. package/lib/module/reanimated2/NativeReanimated/NativeReanimated.js.map +1 -1
  184. package/lib/module/reanimated2/animation/styleAnimation.js +5 -1
  185. package/lib/module/reanimated2/animation/styleAnimation.js.map +1 -1
  186. package/lib/module/reanimated2/animation/util.js +17 -16
  187. package/lib/module/reanimated2/animation/util.js.map +1 -1
  188. package/lib/module/reanimated2/commonTypes.js +29 -0
  189. package/lib/module/reanimated2/commonTypes.js.map +1 -1
  190. package/lib/module/reanimated2/core.js +32 -7
  191. package/lib/module/reanimated2/core.js.map +1 -1
  192. package/lib/module/reanimated2/frameCallback/FrameCallbackRegistryUI.js +2 -2
  193. package/lib/module/reanimated2/frameCallback/FrameCallbackRegistryUI.js.map +1 -1
  194. package/lib/module/reanimated2/globals.d.js.map +1 -1
  195. package/lib/module/reanimated2/hook/index.js +1 -1
  196. package/lib/module/reanimated2/hook/index.js.map +1 -1
  197. package/lib/module/reanimated2/hook/useAnimatedKeyboard.js +5 -2
  198. package/lib/module/reanimated2/hook/useAnimatedKeyboard.js.map +1 -1
  199. package/lib/module/reanimated2/hook/useAnimatedReaction.js +12 -1
  200. package/lib/module/reanimated2/hook/useAnimatedReaction.js.map +1 -1
  201. package/lib/module/reanimated2/hook/useAnimatedRef.js +2 -2
  202. package/lib/module/reanimated2/hook/useAnimatedRef.js.map +1 -1
  203. package/lib/module/reanimated2/hook/useAnimatedSensor.js +88 -13
  204. package/lib/module/reanimated2/hook/useAnimatedSensor.js.map +1 -1
  205. package/lib/module/reanimated2/hook/useAnimatedStyle.js +46 -43
  206. package/lib/module/reanimated2/hook/useAnimatedStyle.js.map +1 -1
  207. package/lib/module/reanimated2/hook/useDerivedValue.js +12 -1
  208. package/lib/module/reanimated2/hook/useDerivedValue.js.map +1 -1
  209. package/lib/module/reanimated2/hook/useScrollViewOffset.js +2 -2
  210. package/lib/module/reanimated2/hook/useScrollViewOffset.js.map +1 -1
  211. package/lib/module/reanimated2/hook/utils.js +17 -60
  212. package/lib/module/reanimated2/hook/utils.js.map +1 -1
  213. package/lib/module/reanimated2/index.js +1 -0
  214. package/lib/module/reanimated2/index.js.map +1 -1
  215. package/lib/module/reanimated2/initializers.js +72 -33
  216. package/lib/module/reanimated2/initializers.js.map +1 -1
  217. package/lib/module/reanimated2/interpolateColor.js +96 -19
  218. package/lib/module/reanimated2/interpolateColor.js.map +1 -1
  219. package/lib/module/reanimated2/jestUtils.js +1 -1
  220. package/lib/module/reanimated2/jestUtils.js.map +1 -1
  221. package/lib/module/reanimated2/js-reanimated/JSReanimated.js +103 -13
  222. package/lib/module/reanimated2/js-reanimated/JSReanimated.js.map +1 -1
  223. package/lib/module/reanimated2/js-reanimated/Mapper.js +21 -0
  224. package/lib/module/reanimated2/js-reanimated/Mapper.js.map +1 -1
  225. package/lib/module/reanimated2/js-reanimated/WebSensor.js +2 -0
  226. package/lib/module/reanimated2/js-reanimated/WebSensor.js.map +1 -0
  227. package/lib/module/reanimated2/js-reanimated/commonTypes.js.map +1 -1
  228. package/lib/module/reanimated2/js-reanimated/global.js +0 -2
  229. package/lib/module/reanimated2/js-reanimated/global.js.map +1 -1
  230. package/lib/module/reanimated2/js-reanimated/index.js +0 -1
  231. package/lib/module/reanimated2/js-reanimated/index.js.map +1 -1
  232. package/lib/module/reanimated2/layoutReanimation/animationBuilder/commonTypes.js +9 -1
  233. package/lib/module/reanimated2/layoutReanimation/animationBuilder/commonTypes.js.map +1 -1
  234. package/lib/module/reanimated2/layoutReanimation/animationBuilder/index.js +1 -0
  235. package/lib/module/reanimated2/layoutReanimation/animationBuilder/index.js.map +1 -1
  236. package/lib/module/reanimated2/layoutReanimation/animationsManager.js +15 -8
  237. package/lib/module/reanimated2/layoutReanimation/animationsManager.js.map +1 -1
  238. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Bounce.js +16 -21
  239. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Bounce.js.map +1 -1
  240. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.js +8 -12
  241. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.js.map +1 -1
  242. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Roll.js +8 -12
  243. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Roll.js.map +1 -1
  244. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Slide.js +8 -13
  245. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Slide.js.map +1 -1
  246. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Zoom.js +16 -21
  247. package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Zoom.js.map +1 -1
  248. package/lib/module/reanimated2/layoutReanimation/index.js +1 -0
  249. package/lib/module/reanimated2/layoutReanimation/index.js.map +1 -1
  250. package/lib/module/reanimated2/layoutReanimation/sharedTransitions/index.js +82 -0
  251. package/lib/module/reanimated2/layoutReanimation/sharedTransitions/index.js.map +1 -0
  252. package/lib/module/reanimated2/mappers.js +16 -6
  253. package/lib/module/reanimated2/mappers.js.map +1 -1
  254. package/lib/module/reanimated2/mock.js +20 -1
  255. package/lib/module/reanimated2/mock.js.map +1 -1
  256. package/lib/module/reanimated2/mutables.js +4 -2
  257. package/lib/module/reanimated2/mutables.js.map +1 -1
  258. package/lib/module/reanimated2/platform-specific/checkVersion.js +35 -0
  259. package/lib/module/reanimated2/platform-specific/checkVersion.js.map +1 -0
  260. package/lib/module/reanimated2/platform-specific/checkVersion.web.js +8 -0
  261. package/lib/module/reanimated2/platform-specific/checkVersion.web.js.map +1 -0
  262. package/lib/module/reanimated2/pluginUtils.js +4 -0
  263. package/lib/module/reanimated2/pluginUtils.js.map +1 -0
  264. package/lib/module/reanimated2/shareables.js +36 -12
  265. package/lib/module/reanimated2/shareables.js.map +1 -1
  266. package/lib/module/reanimated2/threads.js +105 -4
  267. package/lib/module/reanimated2/threads.js.map +1 -1
  268. package/lib/module/reanimated2/utils.js +5 -0
  269. package/lib/module/reanimated2/utils.js.map +1 -1
  270. package/lib/module/reanimated2/valueSetter.js +1 -2
  271. package/lib/module/reanimated2/valueSetter.js.map +1 -1
  272. package/package.json +10 -10
  273. package/{plugin.js → plugin/index.js} +128 -249
  274. package/react-native-reanimated.d.ts +57 -10
  275. package/scripts/reanimated_utils.rb +15 -2
  276. package/src/createAnimatedComponent.tsx +238 -28
  277. package/src/reanimated2/Colors.ts +38 -11
  278. package/src/reanimated2/NativeReanimated/NativeReanimated.ts +52 -39
  279. package/src/reanimated2/animation/styleAnimation.ts +8 -1
  280. package/src/reanimated2/animation/util.ts +29 -16
  281. package/src/reanimated2/commonTypes.ts +28 -1
  282. package/src/reanimated2/core.ts +42 -9
  283. package/src/reanimated2/frameCallback/FrameCallbackRegistryUI.ts +2 -2
  284. package/src/reanimated2/globals.d.ts +12 -15
  285. package/src/reanimated2/hook/index.ts +1 -1
  286. package/src/reanimated2/hook/useAnimatedKeyboard.ts +10 -4
  287. package/src/reanimated2/hook/useAnimatedReaction.ts +12 -5
  288. package/src/reanimated2/hook/useAnimatedRef.ts +1 -4
  289. package/src/reanimated2/hook/useAnimatedSensor.ts +88 -11
  290. package/src/reanimated2/hook/useAnimatedStyle.ts +44 -36
  291. package/src/reanimated2/hook/useDerivedValue.ts +8 -1
  292. package/src/reanimated2/hook/useScrollViewOffset.ts +2 -2
  293. package/src/reanimated2/hook/utils.ts +15 -61
  294. package/src/reanimated2/index.ts +1 -0
  295. package/src/reanimated2/initializers.ts +76 -35
  296. package/src/reanimated2/interpolateColor.ts +104 -20
  297. package/src/reanimated2/jestUtils.ts +1 -1
  298. package/src/reanimated2/js-reanimated/JSReanimated.ts +98 -15
  299. package/src/reanimated2/js-reanimated/Mapper.ts +32 -0
  300. package/src/reanimated2/js-reanimated/WebSensor.ts +34 -0
  301. package/src/reanimated2/js-reanimated/commonTypes.ts +0 -1
  302. package/src/reanimated2/js-reanimated/global.ts +0 -1
  303. package/src/reanimated2/js-reanimated/index.ts +0 -1
  304. package/src/reanimated2/layoutReanimation/animationBuilder/commonTypes.ts +13 -1
  305. package/src/reanimated2/layoutReanimation/animationBuilder/index.ts +1 -0
  306. package/src/reanimated2/layoutReanimation/animationsManager.ts +17 -9
  307. package/src/reanimated2/layoutReanimation/defaultAnimations/Bounce.ts +16 -19
  308. package/src/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.ts +14 -11
  309. package/src/reanimated2/layoutReanimation/defaultAnimations/Roll.ts +21 -11
  310. package/src/reanimated2/layoutReanimation/defaultAnimations/Slide.ts +32 -11
  311. package/src/reanimated2/layoutReanimation/defaultAnimations/Zoom.ts +36 -19
  312. package/src/reanimated2/layoutReanimation/index.ts +1 -0
  313. package/src/reanimated2/layoutReanimation/sharedTransitions/index.ts +87 -0
  314. package/src/reanimated2/mappers.ts +17 -6
  315. package/src/reanimated2/mock.ts +24 -1
  316. package/src/reanimated2/mutables.ts +2 -0
  317. package/src/reanimated2/platform-specific/checkVersion.ts +39 -0
  318. package/src/reanimated2/platform-specific/checkVersion.web.ts +6 -0
  319. package/src/reanimated2/pluginUtils.ts +8 -0
  320. package/src/reanimated2/shareables.ts +45 -16
  321. package/src/reanimated2/threads.ts +103 -1
  322. package/src/reanimated2/utils.ts +6 -0
  323. package/src/reanimated2/valueSetter.ts +1 -2
  324. package/lib/commonjs/reanimated2/time.js +0 -55
  325. package/lib/commonjs/reanimated2/time.js.map +0 -1
  326. package/lib/module/reanimated2/time.js +0 -37
  327. package/lib/module/reanimated2/time.js.map +0 -1
  328. package/src/reanimated2/time.ts +0 -30
  329. /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
@@ -42,6 +42,12 @@
42
42
  return NSStringFromClass([RCTUIManager class]);
43
43
  }
44
44
 
45
+ - (void)invalidate
46
+ {
47
+ [_animationsManager invalidate];
48
+ [super invalidate];
49
+ }
50
+
45
51
  - (void)setBridge:(RCTBridge *)bridge
46
52
  {
47
53
  if (!_blockSetter) {
@@ -76,9 +82,28 @@
76
82
  bool isLayoutAnimationEnabled = reanimated::FeaturesConfig::isLayoutAnimationEnabled();
77
83
  id<RCTComponent> container;
78
84
  NSArray<id<RCTComponent>> *permanentlyRemovedChildren;
85
+ BOOL containerIsRootOfViewController = NO;
79
86
  if (isLayoutAnimationEnabled) {
80
87
  container = registry[containerTag];
81
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
+ }
95
+
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) {
100
+ NSArray<id<RCTComponent>> *permanentlyRemovedChildren = [self _childrenToRemoveFromContainer:container
101
+ atIndices:removeAtIndices];
102
+ for (UIView *view in permanentlyRemovedChildren) {
103
+ [_animationsManager endAnimationsRecursive:view];
104
+ }
105
+ [_animationsManager removeAnimationsFromSubtree:(UIView *)container];
106
+ }
82
107
  }
83
108
 
84
109
  [super _manageChildren:containerTag
@@ -89,21 +114,27 @@
89
114
  removeAtIndices:removeAtIndices
90
115
  registry:registry];
91
116
 
92
- if (isLayoutAnimationEnabled) {
93
- // we sort the (index, view) pairs to make sure we insert views back in order
94
- NSMutableArray<NSArray<id> *> *removedViewsWithIndices = [NSMutableArray new];
95
- for (int i = 0; i < removeAtIndices.count; i++) {
96
- removedViewsWithIndices[i] = @[ removeAtIndices[i], permanentlyRemovedChildren[i] ];
97
- }
98
- [removedViewsWithIndices
99
- sortUsingComparator:^NSComparisonResult(NSArray<id> *_Nonnull obj1, NSArray<id> *_Nonnull obj2) {
100
- return [(NSNumber *)obj1[0] compare:(NSNumber *)obj2[0]];
101
- }];
102
-
103
- [_animationsManager reattachAnimatedChildren:permanentlyRemovedChildren
104
- toContainer:container
105
- atIndices:removeAtIndices];
117
+ if (!isLayoutAnimationEnabled) {
118
+ return;
106
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];
107
138
  }
108
139
 
109
140
  - (void)callAnimationForTree:(UIView *)view parentTag:(NSNumber *)parentTag
@@ -198,6 +229,8 @@
198
229
 
199
230
  __block NSUInteger completionsCalled = 0;
200
231
 
232
+ NSMutableDictionary<NSNumber *, REASnapshot *> *snapshotsBefore = [NSMutableDictionary dictionary];
233
+
201
234
  NSInteger index = 0;
202
235
  for (NSNumber *reactTag in reactTags) {
203
236
  RCTFrameData frameData = frameDataArray[index++];
@@ -234,6 +267,7 @@
234
267
 
235
268
  // Reanimated changes /start
236
269
  REASnapshot *snapshotBefore = isNew ? nil : [self->_animationsManager prepareSnapshotBeforeMountForView:view];
270
+ snapshotsBefore[reactTag] = snapshotBefore;
237
271
  // Reanimated changes /end
238
272
 
239
273
  if (creatingLayoutAnimation) {
@@ -280,17 +314,30 @@
280
314
  [view reactSetFrame:frame];
281
315
  completion(YES);
282
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];
283
328
 
284
- // Reanimated changes /start
285
329
  if (isNew || snapshotBefore != nil) {
286
- [self->_animationsManager viewDidMount:view withBeforeSnapshot:snapshotBefore];
330
+ [self->_animationsManager viewDidMount:view withBeforeSnapshot:snapshotBefore withNewFrame:frame];
287
331
  }
288
- // Reanimated changes /end
289
332
  }
333
+
290
334
  // Clean up
291
335
  // below line serves as this one uiManager->_layoutAnimationGroup = nil;, because we don't have access to the
292
336
  // private field
293
337
  [uiManager setNextLayoutAnimationGroup:nil];
338
+
339
+ [self->_animationsManager viewsDidLayout];
340
+ // Reanimated changes /end
294
341
  };
295
342
  }
296
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