diff --git a/ios/REAModule.m b/ios/REAModule.m index b1aa768010d8..3c3446cce26a 100644 --- a/ios/REAModule.m +++ b/ios/REAModule.m @@ -153,6 +153,7 @@ - (void)addOperationBlock:(AnimatedOperation)operation - (void)uiManagerWillPerformMounting:(RCTUIManager *)uiManager { + [_nodesManager maybeFlushUpdateBuffer]; if (_operations.count == 0) { return; } diff --git a/ios/REANodesManager.h b/ios/REANodesManager.h index 0a6a002c975f..16cc43fdee6c 100644 --- a/ios/REANodesManager.h +++ b/ios/REANodesManager.h @@ -78,4 +78,6 @@ typedef void (^REAEventHandler)(NSString *eventName, id event); - (void)setValueForNodeID:(nonnull NSNumber *)nodeID value:(nonnull NSNumber *)newValue; +- (void)maybeFlushUpdateBuffer; + @end diff --git a/ios/REANodesManager.m b/ios/REANodesManager.m index 7fe56e75578b..72c9765bb897 100644 --- a/ios/REANodesManager.m +++ b/ios/REANodesManager.m @@ -3,6 +3,7 @@ #import #import +#import #import "Nodes/REAAlwaysNode.h" #import "Nodes/REABezierNode.h" #import "Nodes/REABlockNode.h" @@ -46,6 +47,17 @@ - (void)runSyncUIUpdatesWithObserver:(id)observer; @end +@interface ComponentUpdate : NSObject + +@property (nonnull) NSMutableDictionary *props; +@property (nonnull) NSNumber *viewTag; +@property (nonnull) NSString *viewName; + +@end + +@implementation ComponentUpdate +@end + @implementation RCTUIManager (SyncUpdates) - (BOOL)hasEnqueuedUICommands @@ -99,6 +111,9 @@ @implementation REANodesManager { BOOL _tryRunBatchUpdatesSynchronously; REAEventHandler _eventHandler; volatile void (^_mounting)(void); + NSMutableDictionary *_componentUpdateBuffer; + volatile atomic_bool _shouldFlushUpdateBuffer; + NSMutableDictionary *_viewRegistry; } - (instancetype)initWithModule:(REAModule *)reanimatedModule uiManager:(RCTUIManager *)uiManager @@ -113,6 +128,9 @@ - (instancetype)initWithModule:(REAModule *)reanimatedModule uiManager:(RCTUIMan _wantRunUpdates = NO; _onAnimationCallbacks = [NSMutableArray new]; _operationsInBatch = [NSMutableArray new]; + _componentUpdateBuffer = [NSMutableDictionary new]; + _viewRegistry = [_uiManager valueForKey:@"_viewRegistry"]; + _shouldFlushUpdateBuffer = false; } _displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(onAnimationFrame:)]; @@ -492,6 +510,11 @@ - (void)configureProps:(NSSet *)nativeProps uiProps:(NSSet *viewRegistry) { + __typeof__(self) strongSelf = weakSelf; + if (strongSelf == nil) { + return; + } + atomic_store(&strongSelf->_shouldFlushUpdateBuffer, false); + NSMutableDictionary *componentUpdateBuffer = [strongSelf->_componentUpdateBuffer copy]; + strongSelf->_componentUpdateBuffer = [NSMutableDictionary new]; + for (NSNumber *tag in componentUpdateBuffer) { + ComponentUpdate *componentUpdate = componentUpdateBuffer[tag]; + if (componentUpdate == Nil) { + continue; + } + [strongSelf updateProps:componentUpdate.props + ofViewWithTag:componentUpdate.viewTag + withName:componentUpdate.viewName]; + } + [strongSelf performOperations]; + }]; +} + @end