Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove deprecated removeListener methods #33580

Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1164,12 +1164,15 @@ class DisplayOptionsStatusExample extends React.Component<{}> {
function DisplayOptionStatusExample({optionName, optionChecker, notification}) {
const [statusEnabled, setStatusEnabled] = React.useState(false);
React.useEffect(() => {
AccessibilityInfo.addEventListener(notification, setStatusEnabled);
let listener = AccessibilityInfo.addEventListener(
matinzd marked this conversation as resolved.
Show resolved Hide resolved
notification,
setStatusEnabled,
);
optionChecker().then(isEnabled => {
setStatusEnabled(isEnabled);
});
return function cleanup() {
AccessibilityInfo.removeEventListener(notification, setStatusEnabled);
listener.remove();
};
}, [optionChecker, notification]);
return (
Expand Down