diff --git a/packages/react-native/React/CoreModules/RCTEventDispatcher.mm b/packages/react-native/React/CoreModules/RCTEventDispatcher.mm index 3669e2e7d64b58..36082d18200f78 100644 --- a/packages/react-native/React/CoreModules/RCTEventDispatcher.mm +++ b/packages/react-native/React/CoreModules/RCTEventDispatcher.mm @@ -54,6 +54,12 @@ - (void)initialize _eventsDispatchScheduled = NO; _observers = [NSHashTable weakObjectsHashTable]; _observersLock = [NSRecursiveLock new]; + + NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter]; + [defaultCenter addObserver:self + selector:@selector(_notifyEventDispatcherObserversOfEvent_DEPRECATED:) + name:@"RCTNotifyEventDispatcherObserversOfEvent_DEPRECATED" + object:nil]; } - (void)sendViewEventWithName:(NSString *)name reactTag:(NSNumber *)reactTag @@ -225,6 +231,15 @@ - (void)flushEventsQueue } } +- (void)_notifyEventDispatcherObserversOfEvent_DEPRECATED:(NSNotification *)notification +{ + NSDictionary *userInfo = notification.userInfo; + id event = [userInfo objectForKey:@"event"]; + if (event) { + [self notifyObserversOfEvent:event]; + } +} + - (std::shared_ptr)getTurboModule: (const facebook::react::ObjCTurboModule::InitParams &)params { diff --git a/packages/react-native/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm b/packages/react-native/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm index c1a2eeb1e00d28..98cf04959323cd 100644 --- a/packages/react-native/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm +++ b/packages/react-native/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm @@ -68,15 +68,10 @@ static void RCTSendScrollEventForNativeAnimations_DEPRECATED(UIScrollView *scrol scrollViewZoomScale:scrollView.zoomScale userData:nil coalescingKey:coalescingKey]; - RCTBridge *bridge = [RCTBridge currentBridge]; - if (bridge) { - [bridge.eventDispatcher sendEvent:scrollEvent]; - } else { - NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:scrollEvent, @"event", nil]; - [[NSNotificationCenter defaultCenter] postNotificationName:@"RCTNotifyEventDispatcherObserversOfEvent_DEPRECATED" - object:nil - userInfo:userInfo]; - } + NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:scrollEvent, @"event", nil]; + [[NSNotificationCenter defaultCenter] postNotificationName:@"RCTNotifyEventDispatcherObserversOfEvent_DEPRECATED" + object:nil + userInfo:userInfo]; } @interface RCTScrollViewComponentView () < diff --git a/packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTInstance.mm b/packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTInstance.mm index 957ab73cceb656..1de5cff31d3800 100644 --- a/packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTInstance.mm +++ b/packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTInstance.mm @@ -128,13 +128,6 @@ - (instancetype)initWithDelegate:(id)delegate } _launchOptions = launchOptions; - NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter]; - - [defaultCenter addObserver:self - selector:@selector(_notifyEventDispatcherObserversOfEvent_DEPRECATED:) - name:@"RCTNotifyEventDispatcherObserversOfEvent_DEPRECATED" - object:nil]; - [self _start]; } return self; @@ -481,19 +474,6 @@ - (void)_loadScriptFromSource:(RCTSource *)source } } -- (void)_notifyEventDispatcherObserversOfEvent_DEPRECATED:(NSNotification *)notification -{ - NSDictionary *userInfo = notification.userInfo; - id event = [userInfo objectForKey:@"event"]; - - RCTModuleRegistry *moduleRegistry = _bridgeModuleDecorator.moduleRegistry; - if (event && moduleRegistry) { - id legacyEventDispatcher = [moduleRegistry moduleForName:"EventDispatcher" - lazilyLoadIfNecessary:YES]; - [legacyEventDispatcher notifyObserversOfEvent:event]; - } -} - - (void)_handleJSError:(const JsErrorHandler::ParsedError &)error { NSString *message = [NSString stringWithCString:error.message.c_str() encoding:[NSString defaultCStringEncoding]];