mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Codemod: Migrate from bridge.eventDispatcher to RCTModuleRegistry
Summary: All NativeModules that use the bridge to require the eventDispatcher are now instead using the RCTModuleRegistry I introduced in D25412847 (https://github.com/facebook/react-native/commit/0ed81b28d3d786ea3b1cf0b932a008ef1f806ec4). ## What does this codemod do? For all ObjC files that contain `synthesize bridge = _bridge`, migrate calls that access the React Native bridge from `self`, and use it to load the event dispatcher. **Thoughts on Codemod Safety:** If we can access the bridge from self, then that means that if we synthesize the module registry, we can access the module registry from self. Therefore, this codemod is safe. Changelog: [Internal] Reviewed By: PeteTheHeat Differential Revision: D25449795 fbshipit-source-id: 2f7235d14659e73d673ae08763dc2cccdde55a19
This commit is contained in:
committed by
Facebook GitHub Bot
parent
e1d7dd3105
commit
74fd6fb1da
@@ -25,6 +25,7 @@
|
||||
}
|
||||
|
||||
@synthesize bridge = _bridge;
|
||||
@synthesize moduleRegistry = _moduleRegistry;
|
||||
|
||||
RCT_EXPORT_MODULE()
|
||||
|
||||
@@ -72,7 +73,7 @@ RCT_EXPORT_MODULE()
|
||||
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
[_bridge.eventDispatcher
|
||||
[[_moduleRegistry moduleForName:"EventDispatcher"]
|
||||
sendDeviceEventWithName:@"settingsUpdated"
|
||||
body:RCTJSONClean([_defaults dictionaryRepresentation])];
|
||||
#pragma clang diagnostic pop
|
||||
|
||||
@@ -29,6 +29,7 @@ NSString *const RCTAccessibilityManagerDidUpdateMultiplierNotification =
|
||||
@implementation RCTAccessibilityManager
|
||||
|
||||
@synthesize bridge = _bridge;
|
||||
@synthesize moduleRegistry = _moduleRegistry;
|
||||
@synthesize multipliers = _multipliers;
|
||||
|
||||
RCT_EXPORT_MODULE()
|
||||
@@ -111,7 +112,7 @@ RCT_EXPORT_MODULE()
|
||||
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
[_bridge.eventDispatcher sendDeviceEventWithName:@"announcementFinished" body:response];
|
||||
[[_moduleRegistry moduleForName:"EventDispatcher"] sendDeviceEventWithName:@"announcementFinished" body:response];
|
||||
#pragma clang diagnostic pop
|
||||
}
|
||||
|
||||
@@ -122,7 +123,8 @@ RCT_EXPORT_MODULE()
|
||||
_isBoldTextEnabled = newBoldTextEnabled;
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
[_bridge.eventDispatcher sendDeviceEventWithName:@"boldTextChanged" body:@(_isBoldTextEnabled)];
|
||||
[[_moduleRegistry moduleForName:"EventDispatcher"] sendDeviceEventWithName:@"boldTextChanged"
|
||||
body:@(_isBoldTextEnabled)];
|
||||
#pragma clang diagnostic pop
|
||||
}
|
||||
}
|
||||
@@ -134,7 +136,8 @@ RCT_EXPORT_MODULE()
|
||||
_isGrayscaleEnabled = newGrayscaleEnabled;
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
[_bridge.eventDispatcher sendDeviceEventWithName:@"grayscaleChanged" body:@(_isGrayscaleEnabled)];
|
||||
[[_moduleRegistry moduleForName:"EventDispatcher"] sendDeviceEventWithName:@"grayscaleChanged"
|
||||
body:@(_isGrayscaleEnabled)];
|
||||
#pragma clang diagnostic pop
|
||||
}
|
||||
}
|
||||
@@ -146,7 +149,8 @@ RCT_EXPORT_MODULE()
|
||||
_isInvertColorsEnabled = newInvertColorsEnabled;
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
[_bridge.eventDispatcher sendDeviceEventWithName:@"invertColorsChanged" body:@(_isInvertColorsEnabled)];
|
||||
[[_moduleRegistry moduleForName:"EventDispatcher"] sendDeviceEventWithName:@"invertColorsChanged"
|
||||
body:@(_isInvertColorsEnabled)];
|
||||
#pragma clang diagnostic pop
|
||||
}
|
||||
}
|
||||
@@ -158,7 +162,8 @@ RCT_EXPORT_MODULE()
|
||||
_isReduceMotionEnabled = newReduceMotionEnabled;
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
[_bridge.eventDispatcher sendDeviceEventWithName:@"reduceMotionChanged" body:@(_isReduceMotionEnabled)];
|
||||
[[_moduleRegistry moduleForName:"EventDispatcher"] sendDeviceEventWithName:@"reduceMotionChanged"
|
||||
body:@(_isReduceMotionEnabled)];
|
||||
#pragma clang diagnostic pop
|
||||
}
|
||||
}
|
||||
@@ -170,7 +175,8 @@ RCT_EXPORT_MODULE()
|
||||
_isReduceTransparencyEnabled = newReduceTransparencyEnabled;
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
[_bridge.eventDispatcher sendDeviceEventWithName:@"reduceTransparencyChanged" body:@(_isReduceTransparencyEnabled)];
|
||||
[[_moduleRegistry moduleForName:"EventDispatcher"] sendDeviceEventWithName:@"reduceTransparencyChanged"
|
||||
body:@(_isReduceTransparencyEnabled)];
|
||||
#pragma clang diagnostic pop
|
||||
}
|
||||
}
|
||||
@@ -182,7 +188,8 @@ RCT_EXPORT_MODULE()
|
||||
_isVoiceOverEnabled = newIsVoiceOverEnabled;
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
[_bridge.eventDispatcher sendDeviceEventWithName:@"screenReaderChanged" body:@(_isVoiceOverEnabled)];
|
||||
[[_moduleRegistry moduleForName:"EventDispatcher"] sendDeviceEventWithName:@"screenReaderChanged"
|
||||
body:@(_isVoiceOverEnabled)];
|
||||
#pragma clang diagnostic pop
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ using namespace facebook::react;
|
||||
}
|
||||
|
||||
@synthesize bridge = _bridge;
|
||||
@synthesize moduleRegistry = _moduleRegistry;
|
||||
@synthesize turboModuleRegistry = _turboModuleRegistry;
|
||||
|
||||
RCT_EXPORT_MODULE()
|
||||
@@ -180,8 +181,9 @@ static NSDictionary *RCTExportedDimensions(RCTBridge *bridge, id<RCTTurboModuleR
|
||||
!UIInterfaceOrientationIsLandscape(nextOrientation))) {
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
[_bridge.eventDispatcher sendDeviceEventWithName:@"didUpdateDimensions"
|
||||
body:RCTExportedDimensions(_bridge, _turboModuleRegistry)];
|
||||
[[_moduleRegistry moduleForName:"EventDispatcher"]
|
||||
sendDeviceEventWithName:@"didUpdateDimensions"
|
||||
body:RCTExportedDimensions(_bridge, _turboModuleRegistry)];
|
||||
#pragma clang diagnostic pop
|
||||
}
|
||||
|
||||
@@ -203,7 +205,8 @@ static NSDictionary *RCTExportedDimensions(RCTBridge *bridge, id<RCTTurboModuleR
|
||||
if (!([nextInterfaceDimensions isEqual:_currentInterfaceDimensions])) {
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
[_bridge.eventDispatcher sendDeviceEventWithName:@"didUpdateDimensions" body:nextInterfaceDimensions];
|
||||
[[_moduleRegistry moduleForName:"EventDispatcher"] sendDeviceEventWithName:@"didUpdateDimensions"
|
||||
body:nextInterfaceDimensions];
|
||||
#pragma clang diagnostic pop
|
||||
}
|
||||
|
||||
|
||||
@@ -455,6 +455,7 @@ RCT_NOT_IMPLEMENTED(-(instancetype)initWithCoder : (NSCoder *)aDecoder)
|
||||
}
|
||||
|
||||
@synthesize bridge = _bridge;
|
||||
@synthesize moduleRegistry = _moduleRegistry;
|
||||
|
||||
RCT_EXPORT_MODULE()
|
||||
|
||||
@@ -590,7 +591,8 @@ RCT_EXPORT_MODULE()
|
||||
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
[self->_bridge.eventDispatcher sendDeviceEventWithName:@"collectRedBoxExtraData" body:nil];
|
||||
[[self->_moduleRegistry moduleForName:"EventDispatcher"] sendDeviceEventWithName:@"collectRedBoxExtraData"
|
||||
body:nil];
|
||||
#pragma clang diagnostic pop
|
||||
|
||||
if (!self->_window) {
|
||||
|
||||
@@ -81,6 +81,7 @@ NSString *const RCTUIManagerWillUpdateViewsDueToContentSizeMultiplierChangeNotif
|
||||
}
|
||||
|
||||
@synthesize bridge = _bridge;
|
||||
@synthesize moduleRegistry = _moduleRegistry;
|
||||
|
||||
RCT_EXPORT_MODULE()
|
||||
|
||||
@@ -196,7 +197,8 @@ RCT_EXPORT_MODULE()
|
||||
id multiplier = [[self->_bridge moduleForName:@"AccessibilityManager"
|
||||
lazilyLoadIfNecessary:YES] valueForKey:@"multiplier"];
|
||||
if (multiplier) {
|
||||
[_bridge.eventDispatcher sendDeviceEventWithName:@"didUpdateContentSizeMultiplier" body:multiplier];
|
||||
[[_moduleRegistry moduleForName:"EventDispatcher"] sendDeviceEventWithName:@"didUpdateContentSizeMultiplier"
|
||||
body:multiplier];
|
||||
}
|
||||
#pragma clang diagnostic pop
|
||||
|
||||
@@ -256,7 +258,8 @@ static NSDictionary *deviceOrientationEventBody(UIDeviceOrientation orientation)
|
||||
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
[_bridge.eventDispatcher sendDeviceEventWithName:@"namedOrientationDidChange" body:orientationEvent];
|
||||
[[_moduleRegistry moduleForName:"EventDispatcher"] sendDeviceEventWithName:@"namedOrientationDidChange"
|
||||
body:orientationEvent];
|
||||
#pragma clang diagnostic pop
|
||||
}
|
||||
|
||||
|
||||
@@ -79,6 +79,7 @@ namespace facebook {
|
||||
}
|
||||
|
||||
@synthesize bridge = _bridge;
|
||||
@synthesize moduleRegistry = _moduleRegistry;
|
||||
|
||||
RCT_EXPORT_MODULE()
|
||||
|
||||
@@ -120,7 +121,7 @@ RCT_EXPORT_METHOD(sendAppEvent:(NSString *)name body:(nullable id)body)
|
||||
{
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
[_bridge.eventDispatcher sendAppEventWithName:name body:body];
|
||||
[[_moduleRegistry moduleForName:"EventDispatcher"] sendAppEventWithName:name body:body];
|
||||
#pragma clang diagnostic pop
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user