diff --git a/Libraries/AppState/AppState.js b/Libraries/AppState/AppState.js index 4c091c00e8d7e4..99e731bd43fb55 100644 --- a/Libraries/AppState/AppState.js +++ b/Libraries/AppState/AppState.js @@ -127,38 +127,6 @@ class AppState { } throw new Error('Trying to subscribe to unknown event: ' + type); } - - /** - * @deprecated Use `remove` on the EventSubscription from `addEventListener`. - */ - removeEventListener>( - type: K, - listener: (...$ElementType) => mixed, - ): void { - const emitter = this._emitter; - if (emitter == null) { - throw new Error('Cannot use AppState when `isAvailable` is false.'); - } - // NOTE: This will report a deprecation notice via `console.error`. - switch (type) { - case 'change': - // $FlowIssue[invalid-tuple-arity] Flow cannot refine handler based on the event type - // $FlowIssue[incompatible-call] - emitter.removeListener('appStateDidChange', listener); - return; - case 'memoryWarning': - // $FlowIssue[invalid-tuple-arity] Flow cannot refine handler based on the event type - emitter.removeListener('memoryWarning', listener); - return; - case 'blur': - case 'focus': - // $FlowIssue[invalid-tuple-arity] Flow cannot refine handler based on the event type - // $FlowIssue[incompatible-call] - emitter.removeListener('appStateFocusChange', listener); - return; - } - throw new Error('Trying to unsubscribe from unknown event: ' + type); - } } module.exports = (new AppState(): AppState); diff --git a/Libraries/Components/AccessibilityInfo/AccessibilityInfo.js b/Libraries/Components/AccessibilityInfo/AccessibilityInfo.js index 53b0db33f862b2..150635d8531aac 100644 --- a/Libraries/Components/AccessibilityInfo/AccessibilityInfo.js +++ b/Libraries/Components/AccessibilityInfo/AccessibilityInfo.js @@ -12,7 +12,6 @@ import RCTDeviceEventEmitter from '../../EventEmitter/RCTDeviceEventEmitter'; import {sendAccessibilityEvent} from '../../Renderer/shims/ReactNative'; import type {HostComponent} from '../../Renderer/shims/ReactNativeTypes'; import Platform from '../../Utilities/Platform'; -import type EventEmitter from '../../vendor/emitter/EventEmitter'; import type {EventSubscription} from '../../vendor/emitter/EventEmitter'; import NativeAccessibilityInfoAndroid from './NativeAccessibilityInfo'; import NativeAccessibilityManagerIOS from './NativeAccessibilityManager'; @@ -365,25 +364,6 @@ const AccessibilityInfo = { } }, - /** - * @deprecated Use `remove` on the EventSubscription from `addEventListener`. - */ - removeEventListener>( - eventName: K, - handler: (...$ElementType) => void, - ): void { - // NOTE: This will report a deprecation notice via `console.error`. - const deviceEventName = EventNames.get(eventName); - if (deviceEventName != null) { - // $FlowIgnore[incompatible-cast] - (RCTDeviceEventEmitter: EventEmitter<$FlowFixMe>).removeListener( - 'deviceEventName', - // $FlowFixMe[invalid-tuple-arity] - handler, - ); - } - }, - /** * Get the recommended timeout for changes to the UI needed by this user. * diff --git a/Libraries/Components/Keyboard/Keyboard.js b/Libraries/Components/Keyboard/Keyboard.js index 84d8a33513475d..e7a7881742aa89 100644 --- a/Libraries/Components/Keyboard/Keyboard.js +++ b/Libraries/Components/Keyboard/Keyboard.js @@ -141,17 +141,6 @@ class Keyboard { return this._emitter.addListener(eventType, listener); } - /** - * @deprecated Use `remove` on the EventSubscription from `addListener`. - */ - removeListener>( - eventType: K, - listener: (...$ElementType) => mixed, - ): void { - // NOTE: This will report a deprecation notice via `console.error`. - this._emitter.removeListener(eventType, listener); - } - /** * Removes all listeners for a specific event type. * diff --git a/Libraries/EventEmitter/NativeEventEmitter.js b/Libraries/EventEmitter/NativeEventEmitter.js index 1c1d5366da776e..402faec5282cc6 100644 --- a/Libraries/EventEmitter/NativeEventEmitter.js +++ b/Libraries/EventEmitter/NativeEventEmitter.js @@ -95,19 +95,6 @@ export default class NativeEventEmitter }; } - /** - * @deprecated Use `remove` on the EventSubscription from `addListener`. - */ - removeListener>( - eventType: TEvent, - listener: (...args: $ElementType) => mixed, - ): void { - this._nativeModule?.removeListeners(1); - // NOTE: This will report a deprecation notice via `console.error`. - // $FlowFixMe[prop-missing] - `removeListener` exists but is deprecated. - RCTDeviceEventEmitter.removeListener(eventType, listener); - } - emit>( eventType: TEvent, ...args: $ElementType diff --git a/Libraries/Linking/Linking.js b/Libraries/Linking/Linking.js index 66124e637e2e0b..63575220f57ca0 100644 --- a/Libraries/Linking/Linking.js +++ b/Libraries/Linking/Linking.js @@ -46,17 +46,6 @@ class Linking extends NativeEventEmitter { return this.addListener(eventType, listener); } - /** - * @deprecated Use `remove` on the EventSubscription from `addEventListener`. - */ - removeEventListener>( - eventType: K, - listener: (...$ElementType) => mixed, - ): void { - // NOTE: This will report a deprecation notice via `console.error`. - this.removeListener(eventType, listener); - } - /** * Try to open the given `url` with any of the installed apps. * diff --git a/Libraries/Utilities/Dimensions.js b/Libraries/Utilities/Dimensions.js index e0e0a427ba7b0d..6f499cc94f03bc 100644 --- a/Libraries/Utilities/Dimensions.js +++ b/Libraries/Utilities/Dimensions.js @@ -108,19 +108,6 @@ class Dimensions { ); return eventEmitter.addListener(type, handler); } - - /** - * @deprecated Use `remove` on the EventSubscription from `addEventListener`. - */ - static removeEventListener(type: 'change', handler: Function) { - invariant( - type === 'change', - 'Trying to remove listener for unknown event: "%s"', - type, - ); - // NOTE: This will report a deprecation notice via `console.error`. - eventEmitter.removeListener(type, handler); - } } let initialDims: ?$ReadOnly = diff --git a/Libraries/vendor/emitter/_EventEmitter.js b/Libraries/vendor/emitter/_EventEmitter.js index b5e5a05b753c15..38addf8b7b2111 100644 --- a/Libraries/vendor/emitter/_EventEmitter.js +++ b/Libraries/vendor/emitter/_EventEmitter.js @@ -152,33 +152,6 @@ class EventEmitter { } } } - - /** - * @deprecated Use `remove` on the EventSubscription from `addListener`. - */ - removeListener>( - eventType: K, - // FIXME: listeners should return void instead of mixed to prevent issues - listener: (...$ElementType) => mixed, - ): void { - console.warn( - `EventEmitter.removeListener('${eventType}', ...): Method has been ` + - 'deprecated. Please instead use `remove()` on the subscription ' + - 'returned by `EventEmitter.addListener`.', - ); - const subscriptions = this._subscriber.getSubscriptionsForType(eventType); - if (subscriptions) { - for (let i = 0, l = subscriptions.length; i < l; i++) { - const subscription = subscriptions[i]; - - // The subscription may have been removed during this event loop. - // its listener matches the listener in method parameters - if (subscription && subscription.listener === listener) { - subscription.remove(); - } - } - } - } } module.exports = EventEmitter; diff --git a/packages/rn-tester/js/examples/Accessibility/AccessibilityExample.js b/packages/rn-tester/js/examples/Accessibility/AccessibilityExample.js index 7c7e74c0d8bac3..ce8151ce8f76bd 100644 --- a/packages/rn-tester/js/examples/Accessibility/AccessibilityExample.js +++ b/packages/rn-tester/js/examples/Accessibility/AccessibilityExample.js @@ -1151,12 +1151,15 @@ class DisplayOptionsStatusExample extends React.Component<{}> { function DisplayOptionStatusExample({optionName, optionChecker, notification}) { const [statusEnabled, setStatusEnabled] = React.useState(false); React.useEffect(() => { - AccessibilityInfo.addEventListener(notification, setStatusEnabled); + const listener = AccessibilityInfo.addEventListener( + notification, + setStatusEnabled, + ); optionChecker().then(isEnabled => { setStatusEnabled(isEnabled); }); return function cleanup() { - AccessibilityInfo.removeEventListener(notification, setStatusEnabled); + listener.remove(); }; }, [optionChecker, notification]); return (