reintroduced coalescing key for events

Summary: This was previously removed in D2884587, but we will need it going forward. See D3092867 for reasons why it's necessary again.

Reviewed By: javache

Differential Revision: D3092848

fb-gh-sync-id: 0d10dbac4148fcc8e035d32d8eab50f876d99e88
fbshipit-source-id: 0d10dbac4148fcc8e035d32d8eab50f876d99e88
This commit is contained in:
Martin Kralik 2016-04-01 06:53:04 -07:00 committed by Facebook Github Bot 8
parent 8f07b01ac8
commit a496baa68c
5 changed files with 25 additions and 7 deletions

View File

@ -29,14 +29,19 @@
@synthesize viewTag = _viewTag;
@synthesize eventName = _eventName;
@synthesize coalescingKey = _coalescingKey;
- (instancetype)initWithViewTag:(NSNumber *)viewTag eventName:(NSString *)eventName body:(NSDictionary<NSString *, id> *)body
- (instancetype)initWithViewTag:(NSNumber *)viewTag
eventName:(NSString *)eventName
body:(NSDictionary<NSString *, id> *)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];

View File

@ -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<RCTEvent>)coalesceWithEvent:(id<RCTEvent>)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.
*

View File

@ -30,7 +30,9 @@ static NSNumber *RCTGetEventID(id<RCTEvent> 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() <RCTFrameUpdateObserver>

View File

@ -18,6 +18,7 @@
@synthesize eventName = _eventName;
@synthesize viewTag = _viewTag;
@synthesize coalescingKey = _coalescingKey;
- (instancetype)initWithEventName:(NSString *)eventName
reactTouches:(NSArray<NSDictionary *> *)reactTouches

View File

@ -59,6 +59,11 @@ CGFloat const ZINDEX_STICKY_HEADER = 50;
RCT_NOT_IMPLEMENTED(- (instancetype)init)
- (uint16_t)coalescingKey
{
return 0;
}
- (NSDictionary *)body
{
NSDictionary *body = @{