fix: remove deprecated removeListener methods (#33580)
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: https://github.com/facebook/react-native/pull/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
This commit is contained in:
Родитель
7d037ddd6a
Коммит
2596b2f695
|
@ -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);
|
||||
|
|
|
@ -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<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.
|
||||
*
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -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> =
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 (
|
||||
|
|
Загрузка…
Ссылка в новой задаче