mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-01-13 09:20:50 +08:00
Summary: This makes the RCTEvent protocol more generic to make it easier to use the event coalescing feature for type of events other than components. This does a few other improvements that will be useful in follow up PRs. - Add `RCTComponentEvent` which is used instead of deprecated `[sendInputEventWithName:body:]` and remove that method completely (was only used at 2 places). - Make `coalescingKey` optional for events that return NO from `canCoalesce`. - Make `viewTag` optional for events that are not related to views. - Fast path for events that return NO from `canCoalesce`. - Add a missing test for event coalescing with different view tags. Ended up making only one PR for all this since the changes are related and hard to separate. **Migration** Use a custom RCTEvent subclass with `[sendEvent:]` (preferred way to allow type safe events) or `RCTComponentEvent`. **Test plan** - Ran RCTEventDispatcher unit tests - Tested manually in RNTester Changelog: [iOS] [Changed] - Remove deprecated RCTEvent method, sendInputEventWithName:body: Pull Request resolved: https://github.com/facebook/react-native/pull/15894 Reviewed By: shergin Differential Revision: D13726194 Pulled By: hramos fbshipit-source-id: 11f63a99e08f46ec6b4f16f8d9949cdbf5c3fe13
51 lines
1001 B
Objective-C
51 lines
1001 B
Objective-C
/**
|
|
* Copyright (c) Facebook, Inc. and its affilities.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
#import "RCTComponentEvent.h"
|
|
|
|
#import "RCTAssert.h"
|
|
|
|
@implementation RCTComponentEvent
|
|
{
|
|
NSArray *_arguments;
|
|
}
|
|
|
|
@synthesize eventName = _eventName;
|
|
@synthesize viewTag = _viewTag;
|
|
|
|
- (instancetype)initWithName:(NSString *)name viewTag:(NSNumber *)viewTag body:(NSDictionary *)body
|
|
{
|
|
if (self = [super init]) {
|
|
NSMutableDictionary *mutableBody = [NSMutableDictionary dictionaryWithDictionary:body];
|
|
mutableBody[@"target"] = viewTag;
|
|
|
|
_eventName = RCTNormalizeInputEventName(name);
|
|
_viewTag = viewTag;
|
|
_arguments = @[_viewTag, _eventName, mutableBody];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
RCT_NOT_IMPLEMENTED(- (instancetype)init)
|
|
|
|
- (NSArray *)arguments
|
|
{
|
|
return _arguments;
|
|
}
|
|
|
|
- (BOOL)canCoalesce
|
|
{
|
|
return NO;
|
|
}
|
|
|
|
+ (NSString *)moduleDotMethod
|
|
{
|
|
return @"RCTEventEmitter.receiveEvent";
|
|
}
|
|
|
|
@end
|