Skip to content

Commit

Permalink
fix: remove deprecated removeListener methods (#33580)
Browse files Browse the repository at this point in the history
Summary:
Remove old deprecated modules that cause annoying warnings. This can be a breaking change for some third-party modules.

## Changelog

[General] [Removed] - Remove deprecated removeListener methods

Pull Request resolved: #33580

Test Plan: See `flow-check` and `build-arvr-js-flow` succeed in Sandcastle.

Reviewed By: cortinico

Differential Revision: D35549719

Pulled By: yungsters

fbshipit-source-id: 0495e36de19db434362d5de56463d9c1ad6edd73
  • Loading branch information
matinzd authored and facebook-github-bot committed May 4, 2022
1 parent 7d037dd commit 2596b2f
Show file tree
Hide file tree
Showing 8 changed files with 5 additions and 129 deletions.
32 changes: 0 additions & 32 deletions Libraries/AppState/AppState.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<K: $Keys<AppStateEventDefinitions>>(
type: K,
listener: (...$ElementType<AppStateEventDefinitions, K>) => 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);
20 changes: 0 additions & 20 deletions Libraries/Components/AccessibilityInfo/AccessibilityInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -365,25 +364,6 @@ const AccessibilityInfo = {
}
},

/**
* @deprecated Use `remove` on the EventSubscription from `addEventListener`.
*/
removeEventListener<K: $Keys<AccessibilityEventDefinitions>>(
eventName: K,
handler: (...$ElementType<AccessibilityEventDefinitions, K>) => 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.
*
Expand Down
11 changes: 0 additions & 11 deletions Libraries/Components/Keyboard/Keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,17 +141,6 @@ class Keyboard {
return this._emitter.addListener(eventType, listener);
}

/**
* @deprecated Use `remove` on the EventSubscription from `addListener`.
*/
removeListener<K: $Keys<KeyboardEventDefinitions>>(
eventType: K,
listener: (...$ElementType<KeyboardEventDefinitions, K>) => 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.
*
Expand Down
13 changes: 0 additions & 13 deletions Libraries/EventEmitter/NativeEventEmitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,6 @@ export default class NativeEventEmitter<TEventToArgsMap: {...}>
};
}

/**
* @deprecated Use `remove` on the EventSubscription from `addListener`.
*/
removeListener<TEvent: $Keys<TEventToArgsMap>>(
eventType: TEvent,
listener: (...args: $ElementType<TEventToArgsMap, TEvent>) => 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<TEvent: $Keys<TEventToArgsMap>>(
eventType: TEvent,
...args: $ElementType<TEventToArgsMap, TEvent>
Expand Down
11 changes: 0 additions & 11 deletions Libraries/Linking/Linking.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,6 @@ class Linking extends NativeEventEmitter<LinkingEventDefinitions> {
return this.addListener(eventType, listener);
}

/**
* @deprecated Use `remove` on the EventSubscription from `addEventListener`.
*/
removeEventListener<K: $Keys<LinkingEventDefinitions>>(
eventType: K,
listener: (...$ElementType<LinkingEventDefinitions, K>) => 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.
*
Expand Down
13 changes: 0 additions & 13 deletions Libraries/Utilities/Dimensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<DimensionsPayload> =
Expand Down
27 changes: 0 additions & 27 deletions Libraries/vendor/emitter/_EventEmitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,33 +152,6 @@ class EventEmitter<EventDefinitions: {...}> {
}
}
}

/**
* @deprecated Use `remove` on the EventSubscription from `addListener`.
*/
removeListener<K: $Keys<EventDefinitions>>(
eventType: K,
// FIXME: listeners should return void instead of mixed to prevent issues
listener: (...$ElementType<EventDefinitions, K>) => 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;
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down

0 comments on commit 2596b2f

Please sign in to comment.