-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BREAKING - RCTEvent improvements, remove deprecated [sendInputEventWi…
…thName:body:] (#15894) 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: #15894 Reviewed By: shergin Differential Revision: D13726194 Pulled By: hramos fbshipit-source-id: 11f63a99e08f46ec6b4f16f8d9949cdbf5c3fe13
- Loading branch information
1 parent
456c03a
commit 41343f6
Showing
7 changed files
with
169 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* 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 <React/RCTEventDispatcher.h> | ||
|
||
/** | ||
* Generic untyped event for Components. Used internally by RCTDirectEventBlock and | ||
* RCTBubblingEventBlock, for other use cases prefer using a class that implements | ||
* RCTEvent to have a type safe way to initialize it. | ||
*/ | ||
@interface RCTComponentEvent : NSObject<RCTEvent> | ||
|
||
- (instancetype)initWithName:(NSString *)name viewTag:(NSNumber *)viewTag body:(NSDictionary *)body; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters