Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ios/REAModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ - (void)addOperationBlock:(AnimatedOperation)operation

- (void)uiManagerWillPerformMounting:(RCTUIManager *)uiManager
{
[_nodesManager tryToFlushUpdateBuffer];
Comment thread
piaskowyk marked this conversation as resolved.
Outdated
if (_operations.count == 0) {
return;
}
Expand Down
2 changes: 2 additions & 0 deletions ios/REANodesManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,6 @@ typedef void (^REAEventHandler)(NSString *eventName, id<RCTEvent> event);

- (void)setValueForNodeID:(nonnull NSNumber *)nodeID value:(nonnull NSNumber *)newValue;

- (void)tryToFlushUpdateBuffer;

@end
60 changes: 60 additions & 0 deletions ios/REANodesManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ - (void)runSyncUIUpdatesWithObserver:(id<RCTUIManagerObserver>)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
Expand Down Expand Up @@ -99,6 +110,8 @@ @implementation REANodesManager {
BOOL _tryRunBatchUpdatesSynchronously;
REAEventHandler _eventHandler;
volatile void (^_mounting)(void);
NSMutableDictionary<NSNumber *, ComponentUpdate *> *_componentUpdateBuffer;
NSMutableDictionary<NSNumber *, UIView *> *_viewRegistry;
}

- (instancetype)initWithModule:(REAModule *)reanimatedModule uiManager:(RCTUIManager *)uiManager
Expand All @@ -113,6 +126,8 @@ - (instancetype)initWithModule:(REAModule *)reanimatedModule uiManager:(RCTUIMan
_wantRunUpdates = NO;
_onAnimationCallbacks = [NSMutableArray new];
_operationsInBatch = [NSMutableArray new];
_componentUpdateBuffer = [NSMutableDictionary new];
_viewRegistry = [_uiManager valueForKey:@"_viewRegistry"];
}

_displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(onAnimationFrame:)];
Expand Down Expand Up @@ -505,6 +520,24 @@ - (void)updateProps:(nonnull NSDictionary *)props
ofViewWithTag:(nonnull NSNumber *)viewTag
withName:(nonnull NSString *)viewName
{
ComponentUpdate *lastSnapshot = _componentUpdateBuffer[viewTag];
if (_viewRegistry[viewTag].superview == nil || lastSnapshot != nil) {
Comment thread
piaskowyk marked this conversation as resolved.
Outdated
if (lastSnapshot == nil) {
ComponentUpdate *propsSnapshot = [ComponentUpdate new];
propsSnapshot.props = [props mutableCopy];
propsSnapshot.viewTag = viewTag;
propsSnapshot.viewName = viewName;
_componentUpdateBuffer[viewTag] = propsSnapshot;
} else {
NSMutableDictionary *lastProps = lastSnapshot.props;
for (NSString *key in props) {
[lastProps setValue:props[key] forKey:key];
}
}

return;
}

// TODO: refactor PropsNode to also use this function
NSMutableDictionary *uiProps = [NSMutableDictionary new];
NSMutableDictionary *nativeProps = [NSMutableDictionary new];
Expand Down Expand Up @@ -552,4 +585,31 @@ - (NSString *)obtainProp:(nonnull NSNumber *)viewTag propName:(nonnull NSString
return result;
}

- (void)tryToFlushUpdateBuffer
Comment thread
piaskowyk marked this conversation as resolved.
Outdated
{
if (_componentUpdateBuffer.count == 0) {
Comment thread
piaskowyk marked this conversation as resolved.
Outdated
return;
}

__weak typeof(self) weakSelf = self;
RCTExecuteOnMainQueue(^void() {
Comment thread
piaskowyk marked this conversation as resolved.
Outdated
__typeof__(self) strongSelf = weakSelf;
if (strongSelf == nil) {
return;
}
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