diff --git a/Examples/UIExplorer/UIExplorerUnitTests/RCTEventDispatcherTests.m b/Examples/UIExplorer/UIExplorerUnitTests/RCTEventDispatcherTests.m index e34d9f29c..cc1a9def8 100644 --- a/Examples/UIExplorer/UIExplorerUnitTests/RCTEventDispatcherTests.m +++ b/Examples/UIExplorer/UIExplorerUnitTests/RCTEventDispatcherTests.m @@ -29,14 +29,19 @@ @synthesize viewTag = _viewTag; @synthesize eventName = _eventName; +@synthesize coalescingKey = _coalescingKey; -- (instancetype)initWithViewTag:(NSNumber *)viewTag eventName:(NSString *)eventName body:(NSDictionary *)body +- (instancetype)initWithViewTag:(NSNumber *)viewTag + eventName:(NSString *)eventName + body:(NSDictionary *)body + coalescingKey:(uint16_t)coalescingKey { if (self = [super init]) { _viewTag = viewTag; _eventName = eventName; _body = body; _canCoalesce = YES; + _coalescingKey = coalescingKey; } return self; } @@ -85,7 +90,8 @@ _body = @{ @"foo": @"bar" }; _testEvent = [[RCTTestEvent alloc] initWithViewTag:nil eventName:_eventName - body:_body]; + body:_body + coalescingKey:0]; _JSMethod = [[_testEvent class] moduleDotMethod]; } @@ -127,7 +133,8 @@ { RCTTestEvent *nonCoalescingEvent = [[RCTTestEvent alloc] initWithViewTag:nil eventName:_eventName - body:@{}]; + body:@{} + coalescingKey:0]; nonCoalescingEvent.canCoalesce = NO; [_eventDispatcher sendEvent:_testEvent]; @@ -144,7 +151,8 @@ { RCTTestEvent *ignoredEvent = [[RCTTestEvent alloc] initWithViewTag:nil eventName:_eventName - body:@{ @"other": @"body" }]; + body:@{ @"other": @"body" } + coalescingKey:0]; [_eventDispatcher sendEvent:ignoredEvent]; [_eventDispatcher sendEvent:_testEvent]; @@ -162,7 +170,8 @@ NSString *firstEventName = RCTNormalizeInputEventName(@"firstEvent"); RCTTestEvent *firstEvent = [[RCTTestEvent alloc] initWithViewTag:nil eventName:firstEventName - body:_body]; + body:_body + coalescingKey:0]; [_eventDispatcher sendEvent:firstEvent]; [_eventDispatcher sendEvent:_testEvent]; diff --git a/React/Base/RCTEventDispatcher.h b/React/Base/RCTEventDispatcher.h index 4b424b224..4957efcc8 100644 --- a/React/Base/RCTEventDispatcher.h +++ b/React/Base/RCTEventDispatcher.h @@ -48,6 +48,7 @@ RCT_EXTERN NSString *RCTNormalizeInputEventName(NSString *eventName); @property (nonatomic, strong, readonly) NSNumber *viewTag; @property (nonatomic, copy, readonly) NSString *eventName; +@property (nonatomic, assign, readonly) uint16_t coalescingKey; - (BOOL)canCoalesce; - (id)coalesceWithEvent:(id)newEvent; @@ -95,7 +96,7 @@ RCT_EXTERN NSString *RCTNormalizeInputEventName(NSString *eventName); /** * Send a pre-prepared event object. - * + * * If the event can be coalesced it is added to a pool of events that are sent at the beginning of the next js frame. * Otherwise if the event cannot be coalesced we first flush the pool of coalesced events and the new event after that. * diff --git a/React/Base/RCTEventDispatcher.m b/React/Base/RCTEventDispatcher.m index 2e8040e46..9796b8131 100644 --- a/React/Base/RCTEventDispatcher.m +++ b/React/Base/RCTEventDispatcher.m @@ -30,7 +30,9 @@ static NSNumber *RCTGetEventID(id event) { return @( event.viewTag.intValue | - (((uint64_t)event.eventName.hash & 0xFFFF) << 32)); + (((uint64_t)event.eventName.hash & 0xFFFF) << 32) | + (((uint64_t)event.coalescingKey) << 48) + ); } @interface RCTEventDispatcher() diff --git a/React/Base/RCTTouchEvent.m b/React/Base/RCTTouchEvent.m index a6a97c037..3fd95bdd7 100644 --- a/React/Base/RCTTouchEvent.m +++ b/React/Base/RCTTouchEvent.m @@ -18,6 +18,7 @@ @synthesize eventName = _eventName; @synthesize viewTag = _viewTag; +@synthesize coalescingKey = _coalescingKey; - (instancetype)initWithEventName:(NSString *)eventName reactTouches:(NSArray *)reactTouches diff --git a/React/Views/RCTScrollView.m b/React/Views/RCTScrollView.m index 773d9bcda..338e8fe43 100644 --- a/React/Views/RCTScrollView.m +++ b/React/Views/RCTScrollView.m @@ -59,6 +59,11 @@ CGFloat const ZINDEX_STICKY_HEADER = 50; RCT_NOT_IMPLEMENTED(- (instancetype)init) +- (uint16_t)coalescingKey +{ + return 0; +} + - (NSDictionary *)body { NSDictionary *body = @{