Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bypass animation queue for onScroll events #312

Merged
merged 4 commits into from
Jul 7, 2019
Merged
Changes from 3 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
41 changes: 37 additions & 4 deletions ios/REANodesManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ @implementation REANodesManager
CADisplayLink *_displayLink;
REAUpdateContext *_updateContext;
BOOL _wantRunUpdates;
BOOL _processingDirectEvent;
NSMutableArray<REAOnAnimationCallback> *_onAnimationCallbacks;
NSMutableArray<REANativeAnimationOp> *_operationsInBatch;
}
Expand Down Expand Up @@ -111,7 +112,9 @@ - (void)postOnAnimation:(REAOnAnimationCallback)clb
- (void)postRunUpdatesAfterAnimation
{
_wantRunUpdates = YES;
[self startUpdatingOnAnimationFrame];
if (!_processingDirectEvent) {
[self startUpdatingOnAnimationFrame];
}
}

- (void)startUpdatingOnAnimationFrame
Expand Down Expand Up @@ -335,15 +338,45 @@ - (void)processEvent:(id<RCTEvent>)event
[eventNode processEvent:event];
}

- (void)processDirectEvent:(id<RCTEvent>)event
{
_processingDirectEvent = YES;
[self processEvent:event];
[self performOperations];
_processingDirectEvent = NO;
}

- (BOOL)isDirectEvent:(id<RCTEvent>)event
{
static NSArray<NSString *> *directEventNames;
static dispatch_once_t directEventNamesToken;
dispatch_once(&directEventNamesToken, ^{
directEventNames = @[
@"onContentSizeChange",
@"onMomentumScrollBegin",
@"onMomentumScrollEnd",
@"onScroll",
@"onScrollBeginDrag",
@"onScrollEndDrag"
];
});

return [directEventNames containsObject:event.eventName];
}

- (void)dispatchEvent:(id<RCTEvent>)event
{
NSString *key = [NSString stringWithFormat:@"%@%@", event.viewTag, event.eventName];
REANode *eventNode = [_eventMapping objectForKey:key];

if (eventNode != nil) {
// enqueue node to be processed
[_eventQueue addObject:event];
[self startUpdatingOnAnimationFrame];
if ([self isDirectEvent:event]) {
[self processDirectEvent:event];
} else {
// enqueue node to be processed
[_eventQueue addObject:event];
[self startUpdatingOnAnimationFrame];
}
}
}

Expand Down