react-native-reanimated 2.3.0-beta.2 → 2.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (168) 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/README.md +1 -1
  36. package/RNReanimated.podspec +21 -3
  37. package/android/build.gradle +33 -13
  38. package/android/expo/linking.gradle +46 -0
  39. package/android/expo/src/main/java/com/swmansion/reanimated/EXReanimatedAdapter.java +12 -0
  40. package/android/expo/src/main/java/expo/modules/adapters/reanimated/EXReanimatedPackage.java +26 -0
  41. package/android/react-native-reanimated-63-hermes.aar +0 -0
  42. package/android/react-native-reanimated-63-jsc.aar +0 -0
  43. package/android/react-native-reanimated-64-hermes.aar +0 -0
  44. package/android/react-native-reanimated-64-jsc.aar +0 -0
  45. package/android/react-native-reanimated-65-hermes.aar +0 -0
  46. package/android/react-native-reanimated-65-jsc.aar +0 -0
  47. package/android/react-native-reanimated-66-hermes.aar +0 -0
  48. package/android/react-native-reanimated-66-jsc.aar +0 -0
  49. package/android/react-native-reanimated-67-hermes.aar +0 -0
  50. package/android/react-native-reanimated-67-jsc.aar +0 -0
  51. package/expo-module.config.json +3 -0
  52. package/ios/LayoutReanimation/REAAnimationsManager.m +65 -19
  53. package/ios/LayoutReanimation/REAUIManager.mm +101 -61
  54. package/ios/Nodes/REAPropsNode.m +1 -1
  55. package/ios/REAEventDispatcher.m +1 -1
  56. package/ios/REAModule.h +0 -2
  57. package/ios/REAModule.m +0 -3
  58. package/ios/REANodesManager.m +1 -0
  59. package/ios/RNGestureHandlerStateManager.h +5 -0
  60. package/ios/native/NativeMethods.h +5 -0
  61. package/ios/native/NativeMethods.mm +14 -6
  62. package/ios/native/NativeProxy.h +1 -0
  63. package/ios/native/NativeProxy.mm +84 -63
  64. package/ios/native/REAIOSErrorHandler.mm +19 -15
  65. package/ios/native/REAIOSLogger.mm +10 -6
  66. package/ios/native/REAIOSScheduler.mm +17 -10
  67. package/ios/native/REAInitializer.mm +39 -37
  68. package/ios/native/UIResponder+Reanimated.mm +2 -2
  69. package/lib/Animated.js +11 -5
  70. package/lib/ConfigHelper.js +121 -138
  71. package/lib/ReanimatedEventEmitter.js +0 -1
  72. package/lib/ReanimatedModule.js +0 -1
  73. package/lib/ReanimatedModule.macos.js +0 -1
  74. package/lib/ReanimatedModule.native.js +5 -6
  75. package/lib/ReanimatedModule.windows.js +0 -1
  76. package/lib/ReanimatedModuleCompat.js +64 -35
  77. package/lib/createAnimatedComponent.js +469 -499
  78. package/lib/index.js +11 -5
  79. package/lib/reanimated1/core/Core.test.js +1 -1
  80. package/lib/reanimated2/NativeMethods.js +7 -0
  81. package/lib/reanimated2/NativeReanimated/NativeReanimated.js +3 -0
  82. package/lib/reanimated2/PropAdapters.js +0 -1
  83. package/lib/reanimated2/UpdateProps.js +1 -1
  84. package/lib/reanimated2/ViewDescriptorsSet.js +4 -2
  85. package/lib/reanimated2/animation/spring.js +2 -0
  86. package/lib/reanimated2/animation/styleAnimation.js +5 -1
  87. package/lib/reanimated2/animation/util.js +23 -0
  88. package/lib/reanimated2/component/FlatList.js +30 -0
  89. package/lib/reanimated2/component/WrappedComponents.js +9 -0
  90. package/lib/reanimated2/component/index.js +4 -0
  91. package/lib/reanimated2/core.js +34 -6
  92. package/lib/reanimated2/globals.d.ts +8 -0
  93. package/lib/reanimated2/js-reanimated/JSReanimated.js +4 -0
  94. package/lib/reanimated2/js-reanimated/Mapper.js +4 -3
  95. package/lib/reanimated2/js-reanimated/MapperRegistry.js +3 -6
  96. package/lib/reanimated2/js-reanimated/MutableValue.js +0 -2
  97. package/lib/reanimated2/js-reanimated/index.js +10 -8
  98. package/lib/reanimated2/layoutReanimation/LayoutAnimationRepository.js +14 -5
  99. package/lib/reanimated2/layoutReanimation/defaultAnimations/Default.js +14 -14
  100. package/lib/reanimated2/layoutReanimation/defaultAnimations/Flip.js +8 -8
  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/setAndForwardRef.js +14 -48
  112. package/mock.js +1 -1
  113. package/package.json +27 -23
  114. package/plugin.js +111 -110
  115. package/react-native-reanimated.d.ts +56 -27
  116. package/src/Animated.js +11 -5
  117. package/src/{ConfigHelper.js → ConfigHelper.ts} +15 -7
  118. package/src/{ReanimatedEventEmitter.js → ReanimatedEventEmitter.ts} +0 -0
  119. package/src/{ReanimatedModule.js → ReanimatedModule.macos.ts} +0 -0
  120. package/src/{ReanimatedModule.native.js → ReanimatedModule.native.ts} +0 -0
  121. package/src/{ReanimatedModule.macos.js → ReanimatedModule.ts} +0 -0
  122. package/src/{ReanimatedModule.windows.js → ReanimatedModule.windows.ts} +0 -0
  123. package/src/ReanimatedModuleCompat.ts +51 -0
  124. package/src/{createAnimatedComponent.js → createAnimatedComponent.tsx} +278 -124
  125. package/src/reanimated1/core/Core.test.js +1 -1
  126. package/src/reanimated2/NativeMethods.ts +13 -1
  127. package/src/reanimated2/NativeReanimated/NativeReanimated.ts +5 -11
  128. package/src/reanimated2/PropAdapters.ts +0 -1
  129. package/src/reanimated2/UpdateProps.ts +1 -1
  130. package/src/reanimated2/ViewDescriptorsSet.ts +6 -2
  131. package/src/reanimated2/animation/commonTypes.ts +4 -4
  132. package/src/reanimated2/animation/decay.ts +2 -2
  133. package/src/reanimated2/animation/delay.ts +3 -3
  134. package/src/reanimated2/animation/index.ts +7 -7
  135. package/src/reanimated2/animation/repeat.ts +4 -4
  136. package/src/reanimated2/animation/sequence.ts +2 -2
  137. package/src/reanimated2/animation/spring.ts +6 -5
  138. package/src/reanimated2/animation/styleAnimation.ts +24 -12
  139. package/src/reanimated2/animation/timing.ts +5 -5
  140. package/src/reanimated2/animation/util.ts +45 -6
  141. package/src/reanimated2/component/FlatList.tsx +44 -0
  142. package/src/reanimated2/component/WrappedComponents.ts +11 -0
  143. package/src/reanimated2/component/index.ts +9 -0
  144. package/src/reanimated2/core.ts +62 -17
  145. package/src/reanimated2/globals.d.ts +8 -0
  146. package/src/reanimated2/hook/useAnimatedStyle.ts +2 -2
  147. package/src/reanimated2/js-reanimated/JSReanimated.ts +15 -26
  148. package/src/reanimated2/js-reanimated/Mapper.ts +22 -9
  149. package/src/reanimated2/js-reanimated/MapperRegistry.ts +22 -19
  150. package/src/reanimated2/js-reanimated/MutableValue.ts +11 -11
  151. package/src/reanimated2/js-reanimated/index.ts +31 -14
  152. package/src/reanimated2/layoutReanimation/{LayoutAnimationRepository.tsx → LayoutAnimationRepository.ts} +18 -5
  153. package/src/reanimated2/layoutReanimation/animationBuilder/commonTypes.ts +39 -20
  154. package/src/reanimated2/layoutReanimation/animationBuilder/index.ts +5 -1
  155. package/src/reanimated2/layoutReanimation/defaultAnimations/Default.ts +21 -15
  156. package/src/reanimated2/layoutReanimation/defaultAnimations/Flip.ts +29 -24
  157. package/src/reanimated2/layoutReanimation/defaultAnimations/Rotate.ts +61 -34
  158. package/src/reanimated2/layoutReanimation/defaultAnimations/Slide.ts +49 -34
  159. package/src/reanimated2/layoutReanimation/defaultAnimations/Zoom.ts +17 -12
  160. package/src/reanimated2/layoutReanimation/defaultTransitions/CurvedTransition.ts +20 -8
  161. package/src/reanimated2/layoutReanimation/defaultTransitions/EntryExitTransition.ts +9 -9
  162. package/src/reanimated2/layoutReanimation/defaultTransitions/FadingTransition.ts +8 -8
  163. package/src/reanimated2/layoutReanimation/defaultTransitions/JumpingTransition.ts +20 -14
  164. package/src/reanimated2/layoutReanimation/defaultTransitions/LinearTransition.ts +14 -8
  165. package/src/reanimated2/layoutReanimation/defaultTransitions/SequencedTransition.ts +24 -12
  166. package/src/reanimated2/mock.ts +3 -1
  167. package/src/{setAndForwardRef.js → setAndForwardRef.ts} +12 -2
  168. 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,19 +1,22 @@
1
1
  #import "REAUIManager.h"
2
2
  #import <Foundation/Foundation.h>
3
- #import "RCTComponentData.h"
4
- #import "RCTUIManagerObserverCoordinator.h"
5
- #import "RCTRootShadowView.h"
6
- #import "RCTRootViewInternal.h"
7
- #import "RCTLayoutAnimation.h"
8
- #import "RCTLayoutAnimationGroup.h"
3
+ #include "FeaturesConfig.h"
9
4
  #import "REAIOSScheduler.h"
10
5
  #include "Scheduler.h"
11
6
 
7
+ #import <React/RCTComponentData.h>
8
+ #import <React/RCTLayoutAnimation.h>
9
+ #import <React/RCTLayoutAnimationGroup.h>
10
+ #import <React/RCTModalHostView.h>
11
+ #import <React/RCTRootShadowView.h>
12
+ #import <React/RCTRootViewInternal.h>
13
+ #import <React/RCTUIManagerObserverCoordinator.h>
14
+
12
15
  #if __has_include(<RNScreens/RNSScreen.h>)
13
16
  #import <RNScreens/RNSScreen.h>
14
17
  #endif
15
18
 
16
- @interface RCTUIManager(REA)
19
+ @interface RCTUIManager (REA)
17
20
  - (void)_manageChildren:(NSNumber *)containerTag
18
21
  moveFromIndices:(NSArray<NSNumber *> *)moveFromIndices
19
22
  moveToIndices:(NSArray<NSNumber *> *)moveToIndices
@@ -29,19 +32,19 @@
29
32
  @implementation REAUIManager
30
33
 
31
34
  BOOL blockSetter = false;
32
- NSMutableDictionary<NSNumber*, NSMutableSet<id<RCTComponent>>*>* _toBeRemovedRegister;
33
- NSMutableDictionary<NSNumber*, NSNumber*>* _parentMapper;
34
- REAAnimationsManager* _animationsManager;
35
+ NSMutableDictionary<NSNumber *, NSMutableSet<id<RCTComponent>> *> *_toBeRemovedRegister;
36
+ NSMutableDictionary<NSNumber *, NSNumber *> *_parentMapper;
37
+ REAAnimationsManager *_animationsManager;
35
38
  std::weak_ptr<reanimated::Scheduler> _scheduler;
36
39
 
37
- + (NSString*)moduleName
40
+ + (NSString *)moduleName
38
41
  {
39
42
  return NSStringFromClass([RCTUIManager class]);
40
43
  }
41
44
 
42
45
  - (void)setBridge:(RCTBridge *)bridge
43
46
  {
44
- if(!_blockSetter) {
47
+ if (!_blockSetter) {
45
48
  _blockSetter = true;
46
49
 
47
50
  self.bridge = bridge;
@@ -49,8 +52,10 @@ std::weak_ptr<reanimated::Scheduler> _scheduler;
49
52
  [self setValue:[bridge.uiManager valueForKey:@"_shadowViewRegistry"] forKey:@"_shadowViewRegistry"];
50
53
  [self setValue:[bridge.uiManager valueForKey:@"_viewRegistry"] forKey:@"_viewRegistry"];
51
54
  [self setValue:[bridge.uiManager valueForKey:@"_nativeIDRegistry"] forKey:@"_nativeIDRegistry"];
52
- [self setValue:[bridge.uiManager valueForKey:@"_shadowViewsWithUpdatedProps"] forKey:@"_shadowViewsWithUpdatedProps"];
53
- [self setValue:[bridge.uiManager valueForKey:@"_shadowViewsWithUpdatedChildren"] forKey:@"_shadowViewsWithUpdatedChildren"];
55
+ [self setValue:[bridge.uiManager valueForKey:@"_shadowViewsWithUpdatedProps"]
56
+ forKey:@"_shadowViewsWithUpdatedProps"];
57
+ [self setValue:[bridge.uiManager valueForKey:@"_shadowViewsWithUpdatedChildren"]
58
+ forKey:@"_shadowViewsWithUpdatedChildren"];
54
59
  [self setValue:[bridge.uiManager valueForKey:@"_pendingUIBlocks"] forKey:@"_pendingUIBlocks"];
55
60
  [self setValue:[bridge.uiManager valueForKey:@"_rootViewTags"] forKey:@"_rootViewTags"];
56
61
  [self setValue:[bridge.uiManager valueForKey:@"_observerCoordinator"] forKey:@"_observerCoordinator"];
@@ -68,25 +73,39 @@ std::weak_ptr<reanimated::Scheduler> _scheduler;
68
73
  removeAtIndices:(NSArray<NSNumber *> *)removeAtIndices
69
74
  registry:(NSMutableDictionary<NSNumber *, id<RCTComponent>> *)registry
70
75
  {
76
+ if (!reanimated::FeaturesConfig::isLayoutAnimationEnabled()) {
77
+ [super _manageChildren:containerTag
78
+ moveFromIndices:moveFromIndices
79
+ moveToIndices:moveToIndices
80
+ addChildReactTags:addChildReactTags
81
+ addAtIndices:addAtIndices
82
+ removeAtIndices:removeAtIndices
83
+ registry:registry];
84
+ return;
85
+ }
86
+
87
+ // Reanimated changes /start
71
88
  BOOL isUIViewRegistry = ((id)registry == (id)[self valueForKey:@"_viewRegistry"]);
72
89
  id<RCTComponent> container;
73
- NSArray<id<RCTComponent>> *permanentlyRemovedChildren;
74
- if(isUIViewRegistry) {
90
+ NSMutableArray<id<RCTComponent>> *permanentlyRemovedChildren;
91
+ if (isUIViewRegistry) {
75
92
  container = registry[containerTag];
76
- for(id<RCTComponent> toRemoveChild in _toBeRemovedRegister[containerTag]) {
93
+ for (id<RCTComponent> toRemoveChild in _toBeRemovedRegister[containerTag]) {
77
94
  [container removeReactSubview:toRemoveChild];
78
95
  }
79
96
 
80
- permanentlyRemovedChildren = [super _childrenToRemoveFromContainer:container atIndices:removeAtIndices];
81
- if(permanentlyRemovedChildren != nil) {
82
- for(id<RCTComponent> permanentlyRemovedChild in permanentlyRemovedChildren) {
83
- if(_toBeRemovedRegister[containerTag] == nil) {
97
+ permanentlyRemovedChildren = (NSMutableArray *)[super _childrenToRemoveFromContainer:container
98
+ atIndices:removeAtIndices];
99
+ if (permanentlyRemovedChildren != nil) {
100
+ for (id<RCTComponent> permanentlyRemovedChild in permanentlyRemovedChildren) {
101
+ if (_toBeRemovedRegister[containerTag] == nil) {
84
102
  _toBeRemovedRegister[containerTag] = [[NSMutableSet<id<RCTComponent>> alloc] init];
85
103
  }
86
104
  [_toBeRemovedRegister[containerTag] addObject:permanentlyRemovedChild];
87
105
  }
88
106
  }
89
107
  }
108
+ // Reanimated changes /end
90
109
 
91
110
  [super _manageChildren:containerTag
92
111
  moveFromIndices:moveFromIndices
@@ -96,30 +115,44 @@ std::weak_ptr<reanimated::Scheduler> _scheduler;
96
115
  removeAtIndices:removeAtIndices
97
116
  registry:registry];
98
117
 
99
- if(isUIViewRegistry) {
118
+ // Reanimated changes /start
119
+ if (isUIViewRegistry) {
100
120
  NSMutableDictionary<NSNumber *, id<RCTComponent>> *viewRegistry = [self valueForKey:@"_viewRegistry"];
101
- for(id<RCTComponent> toRemoveChild in _toBeRemovedRegister[containerTag]) {
121
+ for (id<RCTComponent> toRemoveChild in _toBeRemovedRegister[containerTag]) {
102
122
  NSInteger lastIndex = [container reactSubviews].count - 1;
103
- if(lastIndex < 0) {
123
+ if (lastIndex < 0) {
104
124
  lastIndex = 0;
105
125
  }
106
- [container insertReactSubview:toRemoveChild atIndex:lastIndex];
107
- viewRegistry[toRemoveChild.reactTag] = toRemoveChild;
126
+ if ([toRemoveChild isKindOfClass:[RCTModalHostView class]]
127
+ #if __has_include(<RNScreens/RNSScreen.h>)
128
+ || ([toRemoveChild isKindOfClass:[RNSScreenView class]])
129
+ #endif
130
+ ) {
131
+ // we don't want layout animations when removing modals or Screens of native-stack since it brings buggy
132
+ // behavior
133
+ [_toBeRemovedRegister[container.reactTag] removeObject:toRemoveChild];
134
+ [permanentlyRemovedChildren removeObject:toRemoveChild];
135
+
136
+ } else {
137
+ [container insertReactSubview:toRemoveChild atIndex:lastIndex];
138
+ viewRegistry[toRemoveChild.reactTag] = toRemoveChild;
139
+ }
108
140
  }
109
141
 
110
142
  for (UIView *removedChild in permanentlyRemovedChildren) {
111
- [self callAnimationForTree: removedChild parentTag:containerTag];
143
+ [self callAnimationForTree:removedChild parentTag:containerTag];
112
144
  }
113
145
  }
146
+ // Reanimated changes /end
114
147
  }
115
148
 
116
- - (void) callAnimationForTree:(UIView*) view parentTag:(NSNumber*) parentTag
149
+ - (void)callAnimationForTree:(UIView *)view parentTag:(NSNumber *)parentTag
117
150
  {
118
- REASnapshot* snapshot = [[REASnapshot alloc] init:view];
151
+ REASnapshot *snapshot = [[REASnapshot alloc] init:view];
119
152
  _parentMapper[view.reactTag] = parentTag;
120
153
  [_animationsManager onViewRemoval:view before:snapshot];
121
154
 
122
- for(UIView* subView in view.reactSubviews) {
155
+ for (UIView *subView in view.reactSubviews) {
123
156
  [self callAnimationForTree:subView parentTag:view.reactTag];
124
157
  }
125
158
  }
@@ -153,11 +186,12 @@ std::weak_ptr<reanimated::Scheduler> _scheduler;
153
186
  for (RCTShadowView *shadowView in affectedShadowViews) {
154
187
  reactTags[index] = shadowView.reactTag;
155
188
  RCTLayoutMetrics layoutMetrics = shadowView.layoutMetrics;
156
- frameDataArray[index++] = (RCTFrameData){layoutMetrics.frame,
157
- layoutMetrics.layoutDirection,
158
- shadowView.isNewView,
159
- shadowView.superview.isNewView,
160
- layoutMetrics.displayType};
189
+ frameDataArray[index++] = (RCTFrameData){
190
+ layoutMetrics.frame,
191
+ layoutMetrics.layoutDirection,
192
+ shadowView.isNewView,
193
+ shadowView.superview.isNewView,
194
+ layoutMetrics.displayType};
161
195
  }
162
196
  }
163
197
 
@@ -183,7 +217,7 @@ std::weak_ptr<reanimated::Scheduler> _scheduler;
183
217
  CGSize contentSize = shadowView.layoutMetrics.frame.size;
184
218
 
185
219
  RCTExecuteOnMainQueue(^{
186
- NSMutableDictionary<NSNumber *, UIView *>* viewRegistry = [self valueForKey:@"_viewRegistry"];
220
+ NSMutableDictionary<NSNumber *, UIView *> *viewRegistry = [self valueForKey:@"_viewRegistry"];
187
221
  UIView *view = viewRegistry[reactTag];
188
222
  RCTAssert(view != nil, @"view (for ID %@) not found", reactTag);
189
223
 
@@ -236,7 +270,13 @@ std::weak_ptr<reanimated::Scheduler> _scheduler;
236
270
  view.hidden = isHidden;
237
271
  }
238
272
 
239
- REASnapshot* snapshotBefore = [[REASnapshot alloc] init:view];
273
+ // Reanimated changes /start
274
+ REASnapshot *snapshotBefore;
275
+ if (reanimated::FeaturesConfig::isLayoutAnimationEnabled()) {
276
+ snapshotBefore = [[REASnapshot alloc] init:view];
277
+ }
278
+ // Reanimated changes /end
279
+
240
280
  if (creatingLayoutAnimation) {
241
281
  // Animate view creation
242
282
  [view reactSetFrame:frame];
@@ -282,55 +322,61 @@ std::weak_ptr<reanimated::Scheduler> _scheduler;
282
322
  completion(YES);
283
323
  }
284
324
 
285
- if(isNew) {
286
- REASnapshot* snapshot = [[REASnapshot alloc] init:view];
287
- [_animationsManager onViewCreate:view after:snapshot];
288
- }
289
- else {
290
- REASnapshot* snapshotAfter = [[REASnapshot alloc] init:view];
291
- [_animationsManager onViewUpdate:view before:snapshotBefore after:snapshotAfter];
325
+ // Reanimated changes /start
326
+ if (reanimated::FeaturesConfig::isLayoutAnimationEnabled()) {
327
+ if (isNew) {
328
+ REASnapshot *snapshot = [[REASnapshot alloc] init:view];
329
+ [_animationsManager onViewCreate:view after:snapshot];
330
+ } else {
331
+ REASnapshot *snapshotAfter = [[REASnapshot alloc] init:view];
332
+ [_animationsManager onViewUpdate:view before:snapshotBefore after:snapshotAfter];
333
+ }
292
334
  }
293
-
294
335
  }
295
336
 
296
337
  [_animationsManager removeLeftovers];
297
338
  // Clean up
339
+ // uiManager->_layoutAnimationGroup = nil;
298
340
  [uiManager setValue:nil forKey:@"_layoutAnimationGroup"];
341
+ // Reanimated changes /end
299
342
  };
300
343
  }
301
344
 
302
345
  - (Class)class
303
346
  {
304
- return [RCTUIManager class];
347
+ return [RCTUIManager class];
305
348
  }
306
349
 
307
350
  + (Class)class
308
351
  {
309
- return [RCTUIManager class];
352
+ return [RCTUIManager class];
310
353
  }
311
354
 
312
- - (void)setUp:(REAAnimationsManager*) animationsManager
355
+ - (void)setUp:(REAAnimationsManager *)animationsManager
313
356
  {
314
357
  _animationsManager = animationsManager;
315
- _toBeRemovedRegister = [[NSMutableDictionary<NSNumber*, NSMutableSet<id<RCTComponent>>*> alloc] init];
316
- _parentMapper = [[NSMutableDictionary<NSNumber*, NSNumber*> alloc] init];
358
+ _toBeRemovedRegister = [[NSMutableDictionary<NSNumber *, NSMutableSet<id<RCTComponent>> *> alloc] init];
359
+ _parentMapper = [[NSMutableDictionary<NSNumber *, NSNumber *> alloc] init];
317
360
  }
318
361
 
319
- - (void)unregisterView:(id<RCTComponent>) view
362
+ - (void)unregisterView:(id<RCTComponent>)view
320
363
  {
321
- NSNumber* tag = _parentMapper[view.reactTag];
322
- if(tag == nil) {
364
+ NSNumber *tag = _parentMapper[view.reactTag];
365
+ if (tag == nil) {
323
366
  return;
324
367
  }
325
368
 
326
369
  [_toBeRemovedRegister[tag] removeObject:view];
327
- if(_toBeRemovedRegister[tag].count == 0) {
370
+ if (_toBeRemovedRegister[tag].count == 0) {
328
371
  [_toBeRemovedRegister removeObjectForKey:tag];
329
372
  }
330
373
  NSMutableDictionary<NSNumber *, id<RCTComponent>> *viewRegistry = [self valueForKey:@"_viewRegistry"];
331
374
  [view.reactSuperview removeReactSubview:view];
332
375
  id<RCTComponent> parentView = viewRegistry[tag];
333
- [parentView removeReactSubview:view];
376
+ @try {
377
+ [parentView removeReactSubview:view];
378
+ } @catch (id anException) {
379
+ }
334
380
  #if __has_include(<RNScreens/RNSScreen.h>)
335
381
  if ([view isKindOfClass:[RNSScreenView class]]) {
336
382
  [parentView didUpdateReactSubviews];
@@ -339,10 +385,4 @@ std::weak_ptr<reanimated::Scheduler> _scheduler;
339
385
  [viewRegistry removeObjectForKey:view.reactTag];
340
386
  }
341
387
 
342
- - (void)batchDidComplete
343
- {
344
- self.flushUiOperations();
345
- [super batchDidComplete];
346
- }
347
-
348
388
  @end
@@ -4,9 +4,9 @@
4
4
  #import "REANodesManager.h"
5
5
  #import "REAStyleNode.h"
6
6
 
7
+ #import <React/RCTComponentData.h>
7
8
  #import <React/RCTLog.h>
8
9
  #import <React/RCTUIManager.h>
9
- #import "React/RCTComponentData.h"
10
10
 
11
11
  @implementation REAPropsNode {
12
12
  NSNumber *_connectedViewTag;
@@ -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
  }