react-native-reanimated 2.3.0-beta.1 → 2.3.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 (174) hide show
  1. package/Common/cpp/NativeModules/NativeReanimatedModule.cpp +12 -3
  2. package/Common/cpp/NativeModules/NativeReanimatedModuleSpec.cpp +13 -0
  3. package/Common/cpp/Registries/EventHandlerRegistry.cpp +2 -2
  4. package/Common/cpp/Registries/MapperRegistry.cpp +5 -5
  5. package/Common/cpp/SharedItems/FrozenObject.cpp +1 -3
  6. package/Common/cpp/SharedItems/ShareableValue.cpp +8 -10
  7. package/Common/cpp/Tools/FeaturesConfig.cpp +5 -0
  8. package/Common/cpp/Tools/JSIStoreValueUser.cpp +8 -8
  9. package/Common/cpp/Tools/Mapper.cpp +1 -1
  10. package/Common/cpp/Tools/RuntimeDecorator.cpp +40 -4
  11. package/Common/cpp/Tools/WorkletEventHandler.cpp +3 -1
  12. package/Common/cpp/headers/NativeModules/NativeReanimatedModule.h +5 -0
  13. package/Common/cpp/headers/NativeModules/NativeReanimatedModuleSpec.h +6 -1
  14. package/Common/cpp/headers/Registries/EventHandlerRegistry.h +1 -0
  15. package/Common/cpp/headers/Registries/MapperRegistry.h +1 -0
  16. package/Common/cpp/headers/SharedItems/FrozenObject.h +4 -0
  17. package/Common/cpp/headers/SharedItems/HostFunctionHandler.h +2 -0
  18. package/Common/cpp/headers/SharedItems/MutableValue.h +2 -0
  19. package/Common/cpp/headers/SharedItems/MutableValueSetterProxy.h +3 -1
  20. package/Common/cpp/headers/SharedItems/RemoteObject.h +4 -1
  21. package/Common/cpp/headers/SharedItems/ShareableValue.h +2 -0
  22. package/Common/cpp/headers/SharedItems/SharedParent.h +9 -9
  23. package/Common/cpp/headers/SharedItems/ValueWrapper.h +32 -28
  24. package/Common/cpp/headers/SpecTools/ErrorHandler.h +1 -0
  25. package/Common/cpp/headers/Tools/FeaturesConfig.h +19 -0
  26. package/Common/cpp/headers/Tools/JSIStoreValueUser.h +2 -5
  27. package/Common/cpp/headers/Tools/Mapper.h +2 -0
  28. package/Common/cpp/headers/Tools/PlatformDepMethodsHolder.h +5 -0
  29. package/Common/cpp/headers/Tools/ReanimatedHiddenHeaders.h +1 -5
  30. package/Common/cpp/headers/Tools/RuntimeDecorator.h +10 -7
  31. package/Common/cpp/headers/Tools/Scheduler.h +2 -0
  32. package/Common/cpp/headers/Tools/WorkletEventHandler.h +2 -1
  33. package/Common/cpp/hidden_headers/Logger.h +2 -2
  34. package/Common/cpp/hidden_headers/LoggerInterface.h +1 -1
  35. package/RNReanimated.podspec +24 -6
  36. package/android/build.gradle +33 -13
  37. package/android/expo/linking.gradle +34 -0
  38. package/android/expo/src/main/java/com/swmansion/reanimated/EXReanimatedAdapter.java +12 -0
  39. package/android/expo/src/main/java/expo/modules/adapters/reanimated/EXReanimatedPackage.java +26 -0
  40. package/android/react-native-reanimated-63-hermes.aar +0 -0
  41. package/android/react-native-reanimated-63-jsc.aar +0 -0
  42. package/android/react-native-reanimated-64-hermes.aar +0 -0
  43. package/android/react-native-reanimated-64-jsc.aar +0 -0
  44. package/android/react-native-reanimated-65-hermes.aar +0 -0
  45. package/android/react-native-reanimated-65-jsc.aar +0 -0
  46. package/android/react-native-reanimated-66-hermes.aar +0 -0
  47. package/android/react-native-reanimated-66-jsc.aar +0 -0
  48. package/android/react-native-reanimated-67-hermes.aar +0 -0
  49. package/android/react-native-reanimated-67-jsc.aar +0 -0
  50. package/expo-module.config.json +3 -0
  51. package/ios/LayoutReanimation/REAAnimationsManager.m +65 -19
  52. package/ios/LayoutReanimation/REAUIManager.mm +114 -70
  53. package/ios/REAEventDispatcher.m +1 -1
  54. package/ios/REAModule.h +0 -2
  55. package/ios/REAModule.m +0 -3
  56. package/ios/REANodesManager.m +1 -0
  57. package/ios/RNGestureHandlerStateManager.h +5 -0
  58. package/ios/native/NativeMethods.h +5 -0
  59. package/ios/native/NativeMethods.mm +14 -6
  60. package/ios/native/NativeProxy.h +1 -0
  61. package/ios/native/NativeProxy.mm +84 -63
  62. package/ios/native/REAIOSErrorHandler.mm +19 -15
  63. package/ios/native/REAIOSLogger.mm +10 -6
  64. package/ios/native/REAIOSScheduler.mm +17 -10
  65. package/ios/native/REAInitializer.mm +42 -31
  66. package/ios/native/UIResponder+Reanimated.mm +2 -2
  67. package/lib/Animated.js +11 -5
  68. package/lib/ConfigHelper.js +121 -138
  69. package/lib/ReanimatedEventEmitter.js +0 -1
  70. package/lib/ReanimatedModule.js +0 -1
  71. package/lib/ReanimatedModule.macos.js +0 -1
  72. package/lib/ReanimatedModule.native.js +5 -6
  73. package/lib/ReanimatedModule.windows.js +0 -1
  74. package/lib/ReanimatedModuleCompat.js +64 -35
  75. package/lib/createAnimatedComponent.js +469 -499
  76. package/lib/index.js +11 -5
  77. package/lib/reanimated1/core/Core.test.js +1 -1
  78. package/lib/reanimated2/NativeMethods.js +7 -0
  79. package/lib/reanimated2/NativeReanimated/NativeReanimated.js +3 -0
  80. package/lib/reanimated2/PropAdapters.js +0 -1
  81. package/lib/reanimated2/UpdateProps.js +1 -1
  82. package/lib/reanimated2/ViewDescriptorsSet.js +4 -2
  83. package/lib/reanimated2/animation/spring.js +2 -0
  84. package/lib/reanimated2/animation/styleAnimation.js +5 -1
  85. package/lib/reanimated2/animation/util.js +23 -0
  86. package/lib/reanimated2/component/FlatList.js +30 -0
  87. package/lib/reanimated2/component/WrappedComponents.js +9 -0
  88. package/lib/reanimated2/component/index.js +4 -0
  89. package/lib/reanimated2/core.js +30 -3
  90. package/lib/reanimated2/globals.d.ts +8 -0
  91. package/lib/reanimated2/index.js +1 -0
  92. package/lib/reanimated2/js-reanimated/JSReanimated.js +4 -0
  93. package/lib/reanimated2/js-reanimated/Mapper.js +4 -3
  94. package/lib/reanimated2/js-reanimated/MapperRegistry.js +3 -6
  95. package/lib/reanimated2/js-reanimated/MutableValue.js +0 -2
  96. package/lib/reanimated2/js-reanimated/index.js +10 -8
  97. package/lib/reanimated2/layoutReanimation/LayoutAnimationRepository.js +14 -5
  98. package/lib/reanimated2/layoutReanimation/defaultAnimations/Default.js +14 -14
  99. package/lib/reanimated2/layoutReanimation/defaultAnimations/Flip.js +8 -8
  100. package/lib/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.js +4 -2
  101. package/lib/reanimated2/layoutReanimation/defaultAnimations/Rotate.js +16 -16
  102. package/lib/reanimated2/layoutReanimation/defaultAnimations/Slide.js +16 -16
  103. package/lib/reanimated2/layoutReanimation/defaultAnimations/Zoom.js +4 -4
  104. package/lib/reanimated2/layoutReanimation/defaultTransitions/CurvedTransition.js +20 -8
  105. package/lib/reanimated2/layoutReanimation/defaultTransitions/EntryExitTransition.js +3 -3
  106. package/lib/reanimated2/layoutReanimation/defaultTransitions/FadingTransition.js +8 -8
  107. package/lib/reanimated2/layoutReanimation/defaultTransitions/JumpingTransition.js +10 -10
  108. package/lib/reanimated2/layoutReanimation/defaultTransitions/LinearTransition.js +8 -8
  109. package/lib/reanimated2/layoutReanimation/defaultTransitions/SequencedTransition.js +8 -8
  110. package/lib/reanimated2/mock.js +3 -1
  111. package/lib/reanimated2/utils.js +9 -0
  112. package/lib/setAndForwardRef.js +14 -48
  113. package/mock.js +1 -1
  114. package/package.json +27 -23
  115. package/plugin.js +111 -110
  116. package/react-native-reanimated.d.ts +63 -25
  117. package/src/Animated.js +11 -5
  118. package/src/{ConfigHelper.js → ConfigHelper.ts} +15 -7
  119. package/src/{ReanimatedEventEmitter.js → ReanimatedEventEmitter.ts} +0 -0
  120. package/src/{ReanimatedModule.js → ReanimatedModule.macos.ts} +0 -0
  121. package/src/{ReanimatedModule.native.js → ReanimatedModule.native.ts} +0 -0
  122. package/src/{ReanimatedModule.macos.js → ReanimatedModule.ts} +0 -0
  123. package/src/{ReanimatedModule.windows.js → ReanimatedModule.windows.ts} +0 -0
  124. package/src/ReanimatedModuleCompat.ts +51 -0
  125. package/src/{createAnimatedComponent.js → createAnimatedComponent.tsx} +278 -124
  126. package/src/reanimated1/core/Core.test.js +1 -1
  127. package/src/reanimated2/NativeMethods.ts +13 -1
  128. package/src/reanimated2/NativeReanimated/NativeReanimated.ts +5 -11
  129. package/src/reanimated2/PropAdapters.ts +0 -1
  130. package/src/reanimated2/UpdateProps.ts +1 -1
  131. package/src/reanimated2/ViewDescriptorsSet.ts +6 -2
  132. package/src/reanimated2/animation/commonTypes.ts +4 -4
  133. package/src/reanimated2/animation/decay.ts +2 -2
  134. package/src/reanimated2/animation/delay.ts +3 -3
  135. package/src/reanimated2/animation/index.ts +7 -7
  136. package/src/reanimated2/animation/repeat.ts +4 -4
  137. package/src/reanimated2/animation/sequence.ts +2 -2
  138. package/src/reanimated2/animation/spring.ts +6 -5
  139. package/src/reanimated2/animation/styleAnimation.ts +24 -12
  140. package/src/reanimated2/animation/timing.ts +5 -5
  141. package/src/reanimated2/animation/util.ts +45 -6
  142. package/src/reanimated2/component/FlatList.tsx +44 -0
  143. package/src/reanimated2/component/WrappedComponents.ts +11 -0
  144. package/src/reanimated2/component/index.ts +9 -0
  145. package/src/reanimated2/core.ts +58 -14
  146. package/src/reanimated2/globals.d.ts +8 -0
  147. package/src/reanimated2/hook/useAnimatedStyle.ts +2 -2
  148. package/src/reanimated2/index.ts +1 -0
  149. package/src/reanimated2/js-reanimated/JSReanimated.ts +15 -26
  150. package/src/reanimated2/js-reanimated/Mapper.ts +22 -9
  151. package/src/reanimated2/js-reanimated/MapperRegistry.ts +22 -19
  152. package/src/reanimated2/js-reanimated/MutableValue.ts +11 -11
  153. package/src/reanimated2/js-reanimated/index.ts +31 -14
  154. package/src/reanimated2/layoutReanimation/{LayoutAnimationRepository.tsx → LayoutAnimationRepository.ts} +18 -5
  155. package/src/reanimated2/layoutReanimation/animationBuilder/commonTypes.ts +39 -20
  156. package/src/reanimated2/layoutReanimation/animationBuilder/index.ts +5 -1
  157. package/src/reanimated2/layoutReanimation/defaultAnimations/Default.ts +21 -15
  158. package/src/reanimated2/layoutReanimation/defaultAnimations/Flip.ts +29 -24
  159. package/src/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.ts +10 -2
  160. package/src/reanimated2/layoutReanimation/defaultAnimations/Rotate.ts +61 -34
  161. package/src/reanimated2/layoutReanimation/defaultAnimations/Slide.ts +49 -34
  162. package/src/reanimated2/layoutReanimation/defaultAnimations/Zoom.ts +17 -12
  163. package/src/reanimated2/layoutReanimation/defaultTransitions/CurvedTransition.ts +20 -8
  164. package/src/reanimated2/layoutReanimation/defaultTransitions/EntryExitTransition.ts +9 -9
  165. package/src/reanimated2/layoutReanimation/defaultTransitions/FadingTransition.ts +8 -8
  166. package/src/reanimated2/layoutReanimation/defaultTransitions/JumpingTransition.ts +20 -14
  167. package/src/reanimated2/layoutReanimation/defaultTransitions/LinearTransition.ts +14 -8
  168. package/src/reanimated2/layoutReanimation/defaultTransitions/SequencedTransition.ts +24 -12
  169. package/src/reanimated2/mock.ts +3 -1
  170. package/src/reanimated2/utils.ts +21 -0
  171. package/src/{setAndForwardRef.js → setAndForwardRef.ts} +12 -2
  172. package/android/react-native-reanimated-62-hermes.aar +0 -0
  173. package/android/react-native-reanimated-62-jsc.aar +0 -0
  174. package/src/ReanimatedModuleCompat.js +0 -37
@@ -7,6 +7,8 @@
7
7
 
8
8
  @interface REAAnimationsManager ()
9
9
 
10
+ typedef NS_ENUM(NSInteger, FrameConfigType) { EnteringFrame, ExitingFrame };
11
+
10
12
  @property (atomic, nullable) void (^startAnimationForTag)(NSNumber *, NSString *, NSDictionary *, NSNumber *);
11
13
  @property (atomic, nullable) void (^removeConfigForTag)(NSNumber *);
12
14
 
@@ -21,6 +23,8 @@
21
23
  NSMutableDictionary<NSNumber *, NSNumber *> *_states;
22
24
  NSMutableDictionary<NSNumber *, UIView *> *_viewForTag;
23
25
  NSMutableSet<NSNumber *> *_toRemove;
26
+ NSMutableArray<NSString *> *_targetKeys;
27
+ NSMutableArray<NSString *> *_currentKeys;
24
28
  BOOL _cleaningScheduled;
25
29
  }
26
30
 
@@ -43,6 +47,13 @@
43
47
  _viewForTag = [NSMutableDictionary new];
44
48
  _toRemove = [NSMutableSet new];
45
49
  _cleaningScheduled = false;
50
+
51
+ _targetKeys = [NSMutableArray new];
52
+ _currentKeys = [NSMutableArray new];
53
+ for (NSString *key in [[self class] layoutKeys]) {
54
+ [_targetKeys addObject:[NSString stringWithFormat:@"target%@", [key capitalizedString]]];
55
+ [_currentKeys addObject:[NSString stringWithFormat:@"current%@", [key capitalizedString]]];
56
+ }
46
57
  }
47
58
  return self;
48
59
  }
@@ -56,6 +67,8 @@
56
67
  _viewForTag = nil;
57
68
  _toRemove = nil;
58
69
  _cleaningScheduled = false;
70
+ _targetKeys = nil;
71
+ _currentKeys = nil;
59
72
  }
60
73
 
61
74
  - (void)setAnimationStartingBlock:
@@ -208,16 +221,53 @@
208
221
  [componentData setProps:newProps forView:view];
209
222
  }
210
223
 
211
- - (NSDictionary *)prepareDataForAnimatingWorklet:(NSMutableDictionary *)values
224
+ - (NSDictionary *)prepareDataForAnimatingWorklet:(NSMutableDictionary *)values frameConfig:(FrameConfigType)frameConfig
225
+ {
226
+ UIView *windowView = UIApplication.sharedApplication.keyWindow;
227
+ if (frameConfig == EnteringFrame) {
228
+ NSDictionary *preparedData = @{
229
+ @"targetWidth" : values[@"width"],
230
+ @"targetHeight" : values[@"height"],
231
+ @"targetOriginX" : values[@"originX"],
232
+ @"targetOriginY" : values[@"originY"],
233
+ @"targetGlobalOriginX" : values[@"globalOriginX"],
234
+ @"targetGlobalOriginY" : values[@"globalOriginY"],
235
+ @"windowWidth" : [NSNumber numberWithDouble:windowView.bounds.size.width],
236
+ @"windowHeight" : [NSNumber numberWithDouble:windowView.bounds.size.height]
237
+ };
238
+ return preparedData;
239
+ } else {
240
+ NSDictionary *preparedData = @{
241
+ @"currentWidth" : values[@"width"],
242
+ @"currentHeight" : values[@"height"],
243
+ @"currentOriginX" : values[@"originX"],
244
+ @"currentOriginY" : values[@"originY"],
245
+ @"currentGlobalOriginX" : values[@"globalOriginX"],
246
+ @"currentGlobalOriginY" : values[@"globalOriginY"],
247
+ @"windowWidth" : [NSNumber numberWithDouble:windowView.bounds.size.width],
248
+ @"windowHeight" : [NSNumber numberWithDouble:windowView.bounds.size.height]
249
+ };
250
+ return preparedData;
251
+ }
252
+ }
253
+
254
+ - (NSDictionary *)prepareDataForLayoutAnimatingWorklet:(NSMutableDictionary *)currentValues
255
+ targetValues:(NSMutableDictionary *)targetValues
212
256
  {
213
257
  UIView *windowView = UIApplication.sharedApplication.keyWindow;
214
258
  NSDictionary *preparedData = @{
215
- @"width" : values[@"width"],
216
- @"height" : values[@"height"],
217
- @"originX" : values[@"originX"],
218
- @"originY" : values[@"originY"],
219
- @"globalOriginX" : values[@"globalOriginX"],
220
- @"globalOriginY" : values[@"globalOriginY"],
259
+ @"currentWidth" : currentValues[@"width"],
260
+ @"currentHeight" : currentValues[@"height"],
261
+ @"currentOriginX" : currentValues[@"originX"],
262
+ @"currentOriginY" : currentValues[@"originY"],
263
+ @"currentGlobalOriginX" : currentValues[@"globalOriginX"],
264
+ @"currentGlobalOriginY" : currentValues[@"globalOriginY"],
265
+ @"targetWidth" : targetValues[@"width"],
266
+ @"targetHeight" : targetValues[@"height"],
267
+ @"targetOriginX" : targetValues[@"originX"],
268
+ @"targetOriginY" : targetValues[@"originY"],
269
+ @"targetGlobalOriginX" : targetValues[@"globalOriginX"],
270
+ @"targetGlobalOriginY" : targetValues[@"globalOriginY"],
221
271
  @"windowWidth" : [NSNumber numberWithDouble:windowView.bounds.size.width],
222
272
  @"windowHeight" : [NSNumber numberWithDouble:windowView.bounds.size.height]
223
273
  };
@@ -241,12 +291,13 @@
241
291
  return;
242
292
  }
243
293
  _states[tag] = [NSNumber numberWithInt:Disappearing];
244
- NSDictionary *preparedValues = [self prepareDataForAnimatingWorklet:startValues];
294
+ NSDictionary *preparedValues = [self prepareDataForAnimatingWorklet:startValues frameConfig:ExitingFrame];
245
295
  _startAnimationForTag(tag, @"exiting", preparedValues, @(0));
246
296
  }
247
297
 
248
298
  - (void)onViewCreate:(UIView *)view after:(REASnapshot *)after
249
299
  {
300
+ _reaUiManager.flushUiOperations();
250
301
  NSNumber *tag = view.reactTag;
251
302
  if (_states[tag] == nil) {
252
303
  _states[tag] = [NSNumber numberWithInt:Inactive];
@@ -256,7 +307,7 @@
256
307
  ViewState state = [_states[tag] intValue];
257
308
  if (state == Inactive) {
258
309
  if (targetValues != nil) {
259
- NSDictionary *preparedValues = [self prepareDataForAnimatingWorklet:targetValues];
310
+ NSDictionary *preparedValues = [self prepareDataForAnimatingWorklet:targetValues frameConfig:EnteringFrame];
260
311
  _startAnimationForTag(tag, @"entering", preparedValues, @(0));
261
312
  }
262
313
  return;
@@ -267,7 +318,7 @@
267
318
  {
268
319
  NSNumber *tag = view.reactTag;
269
320
  NSMutableDictionary *targetValues = after.values;
270
- NSMutableDictionary *startValues = before.values;
321
+ NSMutableDictionary *currentValues = before.values;
271
322
  if (_states[tag] == nil) {
272
323
  return;
273
324
  }
@@ -277,8 +328,9 @@
277
328
  }
278
329
  if (state == Appearing) {
279
330
  BOOL doNotStartLayout = true;
280
- for (NSString *key in [[self class] layoutKeys]) {
281
- if ([((NSNumber *)startValues[key]) doubleValue] != [((NSNumber *)targetValues[key]) doubleValue]) {
331
+ for (int i = 0; i < [[self class] layoutKeys].count; ++i) {
332
+ if ([((NSNumber *)currentValues[_currentKeys[i]]) doubleValue] !=
333
+ [((NSNumber *)targetValues[_targetKeys[i]]) doubleValue]) {
282
334
  doNotStartLayout = false;
283
335
  }
284
336
  }
@@ -287,13 +339,7 @@
287
339
  }
288
340
  }
289
341
  _states[view.reactTag] = [NSNumber numberWithInt:Layout];
290
- NSDictionary *preparedStartValues = [self prepareDataForAnimatingWorklet:startValues];
291
- NSDictionary *preparedTargetValues = [self prepareDataForAnimatingWorklet:targetValues];
292
- NSMutableDictionary *preparedValues = [NSMutableDictionary new];
293
- [preparedValues addEntriesFromDictionary:preparedTargetValues];
294
- for (NSString *key in preparedStartValues.allKeys) {
295
- preparedValues[[NSString stringWithFormat:@"%@%@", @"b", key]] = preparedStartValues[key];
296
- }
342
+ NSDictionary *preparedValues = [self prepareDataForLayoutAnimatingWorklet:currentValues targetValues:targetValues];
297
343
  _startAnimationForTag(view.reactTag, @"layout", preparedValues, @(0));
298
344
  }
299
345
 
@@ -1,16 +1,21 @@
1
1
  #import "REAUIManager.h"
2
2
  #import <Foundation/Foundation.h>
3
+ #include "FeaturesConfig.h"
3
4
  #import "RCTComponentData.h"
4
- #import "RCTUIManagerObserverCoordinator.h"
5
- #import "RCTRootShadowView.h"
6
- #import "RCTRootViewInternal.h"
7
5
  #import "RCTLayoutAnimation.h"
8
6
  #import "RCTLayoutAnimationGroup.h"
7
+ #import "RCTModalHostView.h"
8
+ #import "RCTRootShadowView.h"
9
+ #import "RCTRootViewInternal.h"
10
+ #import "RCTUIManagerObserverCoordinator.h"
9
11
  #import "REAIOSScheduler.h"
10
12
  #include "Scheduler.h"
13
+
14
+ #if __has_include(<RNScreens/RNSScreen.h>)
11
15
  #import <RNScreens/RNSScreen.h>
16
+ #endif
12
17
 
13
- @interface RCTUIManager(REA)
18
+ @interface RCTUIManager (REA)
14
19
  - (void)_manageChildren:(NSNumber *)containerTag
15
20
  moveFromIndices:(NSArray<NSNumber *> *)moveFromIndices
16
21
  moveToIndices:(NSArray<NSNumber *> *)moveToIndices
@@ -26,33 +31,35 @@
26
31
  @implementation REAUIManager
27
32
 
28
33
  BOOL blockSetter = false;
29
- NSMutableDictionary<NSNumber*, NSMutableSet<id<RCTComponent>>*>* _toBeRemovedRegister;
30
- NSMutableDictionary<NSNumber*, NSNumber*>* _parentMapper;
31
- REAAnimationsManager* _animationsManager;
34
+ NSMutableDictionary<NSNumber *, NSMutableSet<id<RCTComponent>> *> *_toBeRemovedRegister;
35
+ NSMutableDictionary<NSNumber *, NSNumber *> *_parentMapper;
36
+ REAAnimationsManager *_animationsManager;
32
37
  std::weak_ptr<reanimated::Scheduler> _scheduler;
33
38
 
34
- + (NSString*)moduleName
39
+ + (NSString *)moduleName
35
40
  {
36
41
  return NSStringFromClass([RCTUIManager class]);
37
42
  }
38
43
 
39
44
  - (void)setBridge:(RCTBridge *)bridge
40
45
  {
41
- if(!_blockSetter) {
46
+ if (!_blockSetter) {
42
47
  _blockSetter = true;
43
-
48
+
44
49
  self.bridge = bridge;
45
50
  [super setValue:bridge forKey:@"_bridge"];
46
51
  [self setValue:[bridge.uiManager valueForKey:@"_shadowViewRegistry"] forKey:@"_shadowViewRegistry"];
47
52
  [self setValue:[bridge.uiManager valueForKey:@"_viewRegistry"] forKey:@"_viewRegistry"];
48
53
  [self setValue:[bridge.uiManager valueForKey:@"_nativeIDRegistry"] forKey:@"_nativeIDRegistry"];
49
- [self setValue:[bridge.uiManager valueForKey:@"_shadowViewsWithUpdatedProps"] forKey:@"_shadowViewsWithUpdatedProps"];
50
- [self setValue:[bridge.uiManager valueForKey:@"_shadowViewsWithUpdatedChildren"] forKey:@"_shadowViewsWithUpdatedChildren"];
54
+ [self setValue:[bridge.uiManager valueForKey:@"_shadowViewsWithUpdatedProps"]
55
+ forKey:@"_shadowViewsWithUpdatedProps"];
56
+ [self setValue:[bridge.uiManager valueForKey:@"_shadowViewsWithUpdatedChildren"]
57
+ forKey:@"_shadowViewsWithUpdatedChildren"];
51
58
  [self setValue:[bridge.uiManager valueForKey:@"_pendingUIBlocks"] forKey:@"_pendingUIBlocks"];
52
59
  [self setValue:[bridge.uiManager valueForKey:@"_rootViewTags"] forKey:@"_rootViewTags"];
53
60
  [self setValue:[bridge.uiManager valueForKey:@"_observerCoordinator"] forKey:@"_observerCoordinator"];
54
61
  [self setValue:[bridge.uiManager valueForKey:@"_componentDataByName"] forKey:@"_componentDataByName"];
55
-
62
+
56
63
  _blockSetter = false;
57
64
  }
58
65
  }
@@ -65,26 +72,40 @@ std::weak_ptr<reanimated::Scheduler> _scheduler;
65
72
  removeAtIndices:(NSArray<NSNumber *> *)removeAtIndices
66
73
  registry:(NSMutableDictionary<NSNumber *, id<RCTComponent>> *)registry
67
74
  {
75
+ if (!reanimated::FeaturesConfig::isLayoutAnimationEnabled()) {
76
+ [super _manageChildren:containerTag
77
+ moveFromIndices:moveFromIndices
78
+ moveToIndices:moveToIndices
79
+ addChildReactTags:addChildReactTags
80
+ addAtIndices:addAtIndices
81
+ removeAtIndices:removeAtIndices
82
+ registry:registry];
83
+ return;
84
+ }
85
+
86
+ // Reanimated changes /start
68
87
  BOOL isUIViewRegistry = ((id)registry == (id)[self valueForKey:@"_viewRegistry"]);
69
88
  id<RCTComponent> container;
70
- NSArray<id<RCTComponent>> *permanentlyRemovedChildren;
71
- if(isUIViewRegistry) {
72
- container = registry[containerTag];
73
- for(id<RCTComponent> toRemoveChild in _toBeRemovedRegister[containerTag]) {
89
+ NSMutableArray<id<RCTComponent>> *permanentlyRemovedChildren;
90
+ if (isUIViewRegistry) {
91
+ container = registry[containerTag];
92
+ for (id<RCTComponent> toRemoveChild in _toBeRemovedRegister[containerTag]) {
74
93
  [container removeReactSubview:toRemoveChild];
75
94
  }
76
-
77
- permanentlyRemovedChildren = [super _childrenToRemoveFromContainer:container atIndices:removeAtIndices];
78
- if(permanentlyRemovedChildren != nil) {
79
- for(id<RCTComponent> permanentlyRemovedChild in permanentlyRemovedChildren) {
80
- if(_toBeRemovedRegister[containerTag] == nil) {
95
+
96
+ permanentlyRemovedChildren = (NSMutableArray *)[super _childrenToRemoveFromContainer:container
97
+ atIndices:removeAtIndices];
98
+ if (permanentlyRemovedChildren != nil) {
99
+ for (id<RCTComponent> permanentlyRemovedChild in permanentlyRemovedChildren) {
100
+ if (_toBeRemovedRegister[containerTag] == nil) {
81
101
  _toBeRemovedRegister[containerTag] = [[NSMutableSet<id<RCTComponent>> alloc] init];
82
102
  }
83
103
  [_toBeRemovedRegister[containerTag] addObject:permanentlyRemovedChild];
84
104
  }
85
105
  }
86
106
  }
87
-
107
+ // Reanimated changes /end
108
+
88
109
  [super _manageChildren:containerTag
89
110
  moveFromIndices:moveFromIndices
90
111
  moveToIndices:moveToIndices
@@ -92,38 +113,52 @@ std::weak_ptr<reanimated::Scheduler> _scheduler;
92
113
  addAtIndices:addAtIndices
93
114
  removeAtIndices:removeAtIndices
94
115
  registry:registry];
95
-
96
- if(isUIViewRegistry) {
116
+
117
+ // Reanimated changes /start
118
+ if (isUIViewRegistry) {
97
119
  NSMutableDictionary<NSNumber *, id<RCTComponent>> *viewRegistry = [self valueForKey:@"_viewRegistry"];
98
- for(id<RCTComponent> toRemoveChild in _toBeRemovedRegister[containerTag]) {
120
+ for (id<RCTComponent> toRemoveChild in _toBeRemovedRegister[containerTag]) {
99
121
  NSInteger lastIndex = [container reactSubviews].count - 1;
100
- if(lastIndex < 0) {
122
+ if (lastIndex < 0) {
101
123
  lastIndex = 0;
102
124
  }
103
- [container insertReactSubview:toRemoveChild atIndex:lastIndex];
104
- viewRegistry[toRemoveChild.reactTag] = toRemoveChild;
125
+ if ([toRemoveChild isKindOfClass:[RCTModalHostView class]]
126
+ #if __has_include(<RNScreens/RNSScreen.h>)
127
+ || ([toRemoveChild isKindOfClass:[RNSScreenView class]])
128
+ #endif
129
+ ) {
130
+ // we don't want layout animations when removing modals or Screens of native-stack since it brings buggy
131
+ // behavior
132
+ [_toBeRemovedRegister[container.reactTag] removeObject:toRemoveChild];
133
+ [permanentlyRemovedChildren removeObject:toRemoveChild];
134
+
135
+ } else {
136
+ [container insertReactSubview:toRemoveChild atIndex:lastIndex];
137
+ viewRegistry[toRemoveChild.reactTag] = toRemoveChild;
138
+ }
105
139
  }
106
-
140
+
107
141
  for (UIView *removedChild in permanentlyRemovedChildren) {
108
- [self callAnimationForTree: removedChild parentTag:containerTag];
142
+ [self callAnimationForTree:removedChild parentTag:containerTag];
109
143
  }
110
144
  }
145
+ // Reanimated changes /end
111
146
  }
112
147
 
113
- - (void) callAnimationForTree:(UIView*) view parentTag:(NSNumber*) parentTag
148
+ - (void)callAnimationForTree:(UIView *)view parentTag:(NSNumber *)parentTag
114
149
  {
115
- REASnapshot* snapshot = [[REASnapshot alloc] init:view];
150
+ REASnapshot *snapshot = [[REASnapshot alloc] init:view];
116
151
  _parentMapper[view.reactTag] = parentTag;
117
152
  [_animationsManager onViewRemoval:view before:snapshot];
118
-
119
- for(UIView* subView in view.reactSubviews) {
153
+
154
+ for (UIView *subView in view.reactSubviews) {
120
155
  [self callAnimationForTree:subView parentTag:view.reactTag];
121
156
  }
122
157
  }
123
158
 
124
159
  // Overrided https://github.com/facebook/react-native/blob/v0.65.0/React/Modules/RCTUIManager.m#L530
125
160
  - (RCTViewManagerUIBlock)uiBlockWithLayoutUpdateForRootView:(RCTRootShadowView *)rootShadowView
126
- {
161
+ {
127
162
  NSHashTable<RCTShadowView *> *affectedShadowViews = [NSHashTable weakObjectsHashTable];
128
163
  [rootShadowView layoutWithAffectedShadowViews:affectedShadowViews];
129
164
 
@@ -150,11 +185,12 @@ std::weak_ptr<reanimated::Scheduler> _scheduler;
150
185
  for (RCTShadowView *shadowView in affectedShadowViews) {
151
186
  reactTags[index] = shadowView.reactTag;
152
187
  RCTLayoutMetrics layoutMetrics = shadowView.layoutMetrics;
153
- frameDataArray[index++] = (RCTFrameData){layoutMetrics.frame,
154
- layoutMetrics.layoutDirection,
155
- shadowView.isNewView,
156
- shadowView.superview.isNewView,
157
- layoutMetrics.displayType};
188
+ frameDataArray[index++] = (RCTFrameData){
189
+ layoutMetrics.frame,
190
+ layoutMetrics.layoutDirection,
191
+ shadowView.isNewView,
192
+ shadowView.superview.isNewView,
193
+ layoutMetrics.displayType};
158
194
  }
159
195
  }
160
196
 
@@ -180,7 +216,7 @@ std::weak_ptr<reanimated::Scheduler> _scheduler;
180
216
  CGSize contentSize = shadowView.layoutMetrics.frame.size;
181
217
 
182
218
  RCTExecuteOnMainQueue(^{
183
- NSMutableDictionary<NSNumber *, UIView *>* viewRegistry = [self valueForKey:@"_viewRegistry"];
219
+ NSMutableDictionary<NSNumber *, UIView *> *viewRegistry = [self valueForKey:@"_viewRegistry"];
184
220
  UIView *view = viewRegistry[reactTag];
185
221
  RCTAssert(view != nil, @"view (for ID %@) not found", reactTag);
186
222
 
@@ -232,8 +268,14 @@ std::weak_ptr<reanimated::Scheduler> _scheduler;
232
268
  if (view.isHidden != isHidden) {
233
269
  view.hidden = isHidden;
234
270
  }
235
-
236
- REASnapshot* snapshotBefore = [[REASnapshot alloc] init:view];
271
+
272
+ // Reanimated changes /start
273
+ REASnapshot *snapshotBefore;
274
+ if (reanimated::FeaturesConfig::isLayoutAnimationEnabled()) {
275
+ snapshotBefore = [[REASnapshot alloc] init:view];
276
+ }
277
+ // Reanimated changes /end
278
+
237
279
  if (creatingLayoutAnimation) {
238
280
  // Animate view creation
239
281
  [view reactSetFrame:frame];
@@ -278,66 +320,68 @@ std::weak_ptr<reanimated::Scheduler> _scheduler;
278
320
  [view reactSetFrame:frame];
279
321
  completion(YES);
280
322
  }
281
-
282
- if(isNew) {
283
- REASnapshot* snapshot = [[REASnapshot alloc] init:view];
284
- [_animationsManager onViewCreate:view after:snapshot];
285
- }
286
- else {
287
- REASnapshot* snapshotAfter = [[REASnapshot alloc] init:view];
288
- [_animationsManager onViewUpdate:view before:snapshotBefore after:snapshotAfter];
323
+
324
+ // Reanimated changes /start
325
+ if (reanimated::FeaturesConfig::isLayoutAnimationEnabled()) {
326
+ if (isNew) {
327
+ REASnapshot *snapshot = [[REASnapshot alloc] init:view];
328
+ [_animationsManager onViewCreate:view after:snapshot];
329
+ } else {
330
+ REASnapshot *snapshotAfter = [[REASnapshot alloc] init:view];
331
+ [_animationsManager onViewUpdate:view before:snapshotBefore after:snapshotAfter];
332
+ }
289
333
  }
290
-
291
334
  }
292
335
 
293
336
  [_animationsManager removeLeftovers];
294
337
  // Clean up
338
+ // uiManager->_layoutAnimationGroup = nil;
295
339
  [uiManager setValue:nil forKey:@"_layoutAnimationGroup"];
340
+ // Reanimated changes /end
296
341
  };
297
342
  }
298
343
 
299
344
  - (Class)class
300
345
  {
301
- return [RCTUIManager class];
346
+ return [RCTUIManager class];
302
347
  }
303
348
 
304
349
  + (Class)class
305
350
  {
306
- return [RCTUIManager class];
351
+ return [RCTUIManager class];
307
352
  }
308
353
 
309
- - (void)setUp:(REAAnimationsManager*) animationsManager
354
+ - (void)setUp:(REAAnimationsManager *)animationsManager
310
355
  {
311
356
  _animationsManager = animationsManager;
312
- _toBeRemovedRegister = [[NSMutableDictionary<NSNumber*, NSMutableSet<id<RCTComponent>>*> alloc] init];
313
- _parentMapper = [[NSMutableDictionary<NSNumber*, NSNumber*> alloc] init];
357
+ _toBeRemovedRegister = [[NSMutableDictionary<NSNumber *, NSMutableSet<id<RCTComponent>> *> alloc] init];
358
+ _parentMapper = [[NSMutableDictionary<NSNumber *, NSNumber *> alloc] init];
314
359
  }
315
360
 
316
- - (void)unregisterView:(id<RCTComponent>) view
361
+ - (void)unregisterView:(id<RCTComponent>)view
317
362
  {
318
- NSNumber* tag = _parentMapper[view.reactTag];
319
- if(tag == nil) {
363
+ NSNumber *tag = _parentMapper[view.reactTag];
364
+ if (tag == nil) {
320
365
  return;
321
366
  }
322
-
367
+
323
368
  [_toBeRemovedRegister[tag] removeObject:view];
324
- if(_toBeRemovedRegister[tag].count == 0) {
369
+ if (_toBeRemovedRegister[tag].count == 0) {
325
370
  [_toBeRemovedRegister removeObjectForKey:tag];
326
371
  }
327
372
  NSMutableDictionary<NSNumber *, id<RCTComponent>> *viewRegistry = [self valueForKey:@"_viewRegistry"];
328
373
  [view.reactSuperview removeReactSubview:view];
329
374
  id<RCTComponent> parentView = viewRegistry[tag];
330
- [parentView removeReactSubview:view];
375
+ @try {
376
+ [parentView removeReactSubview:view];
377
+ } @catch (id anException) {
378
+ }
379
+ #if __has_include(<RNScreens/RNSScreen.h>)
331
380
  if ([view isKindOfClass:[RNSScreenView class]]) {
332
381
  [parentView didUpdateReactSubviews];
333
382
  }
383
+ #endif
334
384
  [viewRegistry removeObjectForKey:view.reactTag];
335
385
  }
336
386
 
337
- - (void)batchDidComplete
338
- {
339
- self.flushUiOperations();
340
- [super batchDidComplete];
341
- }
342
-
343
387
  @end
@@ -7,7 +7,7 @@
7
7
 
8
8
  - (void)sendEvent:(id<RCTEvent>)event
9
9
  {
10
- [[_bridge_reanimated moduleForName:@"ReanimatedModule"] eventDispatcherWillDispatchEvent:event];
10
+ [[[self bridge] moduleForName:@"ReanimatedModule"] eventDispatcherWillDispatchEvent:event];
11
11
  [super sendEvent:event];
12
12
  }
13
13
 
package/ios/REAModule.h CHANGED
@@ -7,8 +7,6 @@
7
7
 
8
8
  #import "REAValueNode.h"
9
9
 
10
- extern RCTBridge *_bridge_reanimated;
11
-
12
10
  @interface REAModule : RCTEventEmitter <RCTBridgeModule, RCTEventDispatcherObserver, RCTUIManagerObserver>
13
11
 
14
12
  @property (nonatomic, readonly) REANodesManager *nodesManager;
package/ios/REAModule.m CHANGED
@@ -6,8 +6,6 @@
6
6
 
7
7
  typedef void (^AnimatedOperation)(REANodesManager *nodesManager);
8
8
 
9
- RCTBridge *_bridge_reanimated = nil;
10
-
11
9
  @implementation REAModule {
12
10
  NSMutableArray<AnimatedOperation> *_operations;
13
11
  REATransitionManager *_transitionManager;
@@ -17,7 +15,6 @@ RCT_EXPORT_MODULE(ReanimatedModule);
17
15
 
18
16
  - (void)invalidate
19
17
  {
20
- _bridge_reanimated = nil;
21
18
  _transitionManager = nil;
22
19
  [_nodesManager invalidate];
23
20
  [self.bridge.uiManager.observerCoordinator removeObserver:self];
@@ -116,6 +116,7 @@
116
116
  }
117
117
 
118
118
  _displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(onAnimationFrame:)];
119
+ _displayLink.preferredFramesPerSecond = 120; // will fallback to 60 fps for devices without Pro Motion display
119
120
  [_displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];
120
121
  [_displayLink setPaused:true];
121
122
  return self;
@@ -0,0 +1,5 @@
1
+ @protocol RNGestureHandlerStateManager
2
+
3
+ - (void)setGestureState:(int)state forHandler:(int)handlerTag;
4
+
5
+ @end
@@ -5,6 +5,7 @@
5
5
  #include <utility>
6
6
  #include <vector>
7
7
  #import <vector>
8
+ #import "RNGestureHandlerStateManager.h"
8
9
 
9
10
  namespace reanimated {
10
11
 
@@ -17,5 +18,9 @@ void scrollTo(
17
18
  double x,
18
19
  double y,
19
20
  bool animated);
21
+ void setGestureState(
22
+ id<RNGestureHandlerStateManager> gestureHandlerStateManager,
23
+ int handlerTag,
24
+ int newState);
20
25
 
21
26
  } // namespace reanimated
@@ -1,10 +1,11 @@
1
1
  #import "NativeMethods.h"
2
- #import <React/RCTScrollView.h>
3
2
  #import <React/RCTEventDispatcher.h>
3
+ #import <React/RCTScrollView.h>
4
4
 
5
5
  namespace reanimated {
6
6
 
7
- std::vector<std::pair<std::string,double>> measure(int viewTag, RCTUIManager *uiManager) {
7
+ std::vector<std::pair<std::string, double>> measure(int viewTag, RCTUIManager *uiManager)
8
+ {
8
9
  UIView *view = [uiManager viewForReactTag:@(viewTag)];
9
10
 
10
11
  UIView *rootView = view;
@@ -17,7 +18,7 @@ std::vector<std::pair<std::string,double>> measure(int viewTag, RCTUIManager *ui
17
18
  rootView = rootView.superview;
18
19
  }
19
20
 
20
- if (rootView == nil || (![rootView isReactRootView])) {
21
+ if (rootView == nil) {
21
22
  return std::vector<std::pair<std::string, double>>(1, std::make_pair("x", -1234567.0));
22
23
  }
23
24
 
@@ -36,11 +37,18 @@ std::vector<std::pair<std::string,double>> measure(int viewTag, RCTUIManager *ui
36
37
  return result;
37
38
  }
38
39
 
39
-
40
- void scrollTo(int scrollViewTag, RCTUIManager *uiManager, double x, double y, bool animated) {
40
+ void scrollTo(int scrollViewTag, RCTUIManager *uiManager, double x, double y, bool animated)
41
+ {
41
42
  UIView *view = [uiManager viewForReactTag:@(scrollViewTag)];
42
- RCTScrollView *scrollView = (RCTScrollView *) view;
43
+ RCTScrollView *scrollView = (RCTScrollView *)view;
43
44
  [scrollView scrollToOffset:(CGPoint){(CGFloat)x, (CGFloat)y} animated:animated];
44
45
  }
45
46
 
47
+ void setGestureState(id<RNGestureHandlerStateManager> gestureHandlerStateManager, int handlerTag, int newState)
48
+ {
49
+ if (gestureHandlerStateManager != nil) {
50
+ [gestureHandlerStateManager setGestureState:newState forHandler:handlerTag];
51
+ }
52
+ }
53
+
46
54
  }
@@ -7,6 +7,7 @@
7
7
  namespace reanimated {
8
8
 
9
9
  std::shared_ptr<reanimated::NativeReanimatedModule> createReanimatedModule(
10
+ RCTBridge *bridge,
10
11
  std::shared_ptr<facebook::react::CallInvoker> jsInvoker);
11
12
 
12
13
  }