Remove deprecated InteractionManager (#57026)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/57026

`InteractionManager` has been marked as deprecated and has emitted a runtime warning on first access for several releases. Remove it from the public API.

Accessing `InteractionManager` from `react-native` now throws a `__DEV__` invariant with a migration message pointing at `requestIdleCallback`, mirroring the pattern already used for other previously-removed legacy modules.

The recommended migration is to refactor long tasks into smaller chunks and use `requestIdleCallback` / `cancelIdleCallback` instead of `runAfterInteractions` / `handle.cancel()`.

Changes:
- Remove the lazy getter from `index.js` and replace it with a `__DEV__` invariant stub.
- Remove the `Handle`, `PromiseTask`, `SimpleTask` type re-exports and the `InteractionManager` default re-export from `index.js.flow`.
- Delete `Libraries/Interaction/InteractionManager.js` and its `.d.ts`. The parent `Libraries/Interaction/` directory is kept — `PanResponder`, `TouchHistoryMath`, and `FrameRateLogger` continue to live there.

Changelog:
[General][Removed] - Remove deprecated `InteractionManager` (use `requestIdleCallback` instead)

Reviewed By: huntie

Differential Revision: D106640958

fbshipit-source-id: 01a15fa46b9c840473d96ae9d4ab8b4da4699352
This commit is contained in:
Rubén Norte authored and meta-codesync[bot] committed 2026-06-01 13:07:54 -07:00
1 parent dc9043e940
commit ed893f7d98
8 files changed
+20 -345

No files matched your search

@@ -297,10 +297,6 @@ const publicAPIMapping = {
default: 'I18nManager',
types: null,
},
'Libraries/Interaction/InteractionManager': {
default: 'InteractionManager',
types: ['Handle', 'PromiseTask', 'SimpleTask'],
},
'Libraries/Components/Keyboard/Keyboard': {
default: 'Keyboard',
types: [
@@ -1,87 +0,0 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
import {EmitterSubscription} from '../vendor/emitter/EventEmitter';
export type Handle = number;
export type SimpleTask = {
name: string;
gen: () => void;
};
export type PromiseTask = {
name: string;
gen: () => Promise<any>;
};
/**
* @deprecated
*/
export interface InteractionManagerStatic {
Events: {
interactionStart: string;
interactionComplete: string;
};
/**
* Adds a listener to be invoked when events of the specified type are
* emitted. An optional calling context may be provided. The data arguments
* emitted will be passed to the listener function.
*
* @param eventType - Name of the event to listen to
* @param listener - Function to invoke when the specified event is
* emitted
* @param context - Optional context object to use when invoking the
* listener
*
* @deprecated
*/
addListener(
eventType: string,
listener: (...args: any[]) => any,
context?: any,
): EmitterSubscription;
/**
* Schedule a function to run after all interactions have completed.
* Returns a cancellable
*
* @deprecated
*/
runAfterInteractions(task?: (() => any) | SimpleTask | PromiseTask): {
then: (onfulfilled?: () => any, onrejected?: () => any) => Promise<any>;
done: (...args: any[]) => any;
cancel: () => void;
};
/**
* Notify manager that an interaction has started.
*
* @deprecated
*/
createInteractionHandle(): Handle;
/**
* Notify manager that an interaction has completed.
*
* @deprecated
*/
clearInteractionHandle(handle: Handle): void;
/**
* A positive number will use setTimeout to schedule any tasks after
* the eventLoopRunningTime hits the deadline value, otherwise all
* tasks will be executed in one setImmediate batch (default).
*
* @deprecated
*/
setDeadline(deadline: number): void;
}
export const InteractionManager: InteractionManagerStatic;
@@ -1,189 +0,0 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict
* @format
*/
import type {EventSubscription} from '../vendor/emitter/EventEmitter';
const toError = require('../../src/private/utilities/toError').default;
const invariant = require('invariant');
export type SimpleTask = {
name: string,
run: () => void,
};
export type PromiseTask = {
name: string,
gen: () => Promise<void>,
};
export type Task = SimpleTask | PromiseTask | (() => void);
export type Handle = number;
// NOTE: The original implementation of `InteractionManager` never rejected
// the returned promise. This preserves that behavior in the stub.
function reject(error: Error): void {
setTimeout(() => {
throw error;
}, 0);
}
/**
* InteractionManager allows long-running work to be scheduled after any
* interactions/animations have completed. In particular, this allows JavaScript
* animations to run smoothly.
*
* Applications can schedule tasks to run after interactions with the following:
*
* ```
* InteractionManager.runAfterInteractions(() => {
* // ...long-running synchronous task...
* });
* ```
*
* Compare this to other scheduling alternatives:
*
* - requestAnimationFrame(): for code that animates a view over time.
* - setImmediate/setTimeout(): run code later, note this may delay animations.
* - runAfterInteractions(): run code later, without delaying active animations.
*
* The touch handling system considers one or more active touches to be an
* 'interaction' and will delay `runAfterInteractions()` callbacks until all
* touches have ended or been cancelled.
*
* InteractionManager also allows applications to register animations by
* creating an interaction 'handle' on animation start, and clearing it upon
* completion:
*
* ```
* var handle = InteractionManager.createInteractionHandle();
* // run animation... (`runAfterInteractions` tasks are queued)
* // later, on animation completion:
* InteractionManager.clearInteractionHandle(handle);
* // queued tasks run if all handles were cleared
* ```
*
* `runAfterInteractions` takes either a plain callback function, or a
* `PromiseTask` object with a `gen` method that returns a `Promise`. If a
* `PromiseTask` is supplied, then it is fully resolved (including asynchronous
* dependencies that also schedule more tasks via `runAfterInteractions`) before
* starting on the next task that might have been queued up synchronously
* earlier.
*
* By default, queued tasks are executed together in a loop in one
* `setImmediate` batch. If `setDeadline` is called with a positive number, then
* tasks will only be executed until the deadline (in terms of js event loop run
* time) approaches, at which point execution will yield via setTimeout,
* allowing events such as touches to start interactions and block queued tasks
* from executing, making apps more responsive.
*
* @deprecated
*/
const InteractionManagerStub = {
Events: {
interactionStart: 'interactionStart',
interactionComplete: 'interactionComplete',
},
/**
* Schedule a function to run after all interactions have completed. Returns a cancellable
* "promise".
*
* @deprecated
*/
runAfterInteractions(task: ?Task): {
then: <U>(
onFulfill?: ?(void) => ?(Promise<U> | U),
onReject?: ?(error: unknown) => ?(Promise<U> | U),
) => Promise<U>,
cancel: () => void,
...
} {
let immediateID: ?$FlowFixMe;
const promise = new Promise(resolve => {
immediateID = setImmediate(() => {
if (typeof task === 'object' && task !== null) {
if (typeof task.gen === 'function') {
task.gen().then(resolve, reject);
} else if (typeof task.run === 'function') {
try {
task.run();
resolve();
} catch (error: unknown) {
reject(toError(error));
}
} else {
reject(new TypeError(`Task "${task.name}" missing gen or run.`));
}
} else if (typeof task === 'function') {
try {
task();
resolve();
} catch (error: unknown) {
reject(toError(error));
}
} else {
reject(new TypeError('Invalid task of type: ' + typeof task));
}
});
});
return {
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
then: promise.then.bind(promise),
cancel() {
clearImmediate(immediateID);
},
};
},
/**
* Notify manager that an interaction has started.
*
* @deprecated
*/
createInteractionHandle(): Handle {
return -1;
},
/**
* Notify manager that an interaction has completed.
*
* @deprecated
*/
clearInteractionHandle(handle: Handle) {
invariant(!!handle, 'InteractionManager: Must provide a handle to clear.');
},
/**
* @deprecated
*/
addListener(
eventType: string,
// $FlowFixMe[unclear-type]
listener: (...args: any) => unknown,
context: unknown,
): EventSubscription {
return {
remove() {},
};
},
/**
* A positive number will use setTimeout to schedule any tasks after the
* eventLoopRunningTime hits the deadline value, otherwise all tasks will be
* executed in one setImmediate batch (default).
*
* @deprecated
*/
setDeadline(deadline: number) {
// Do nothing.
},
};
export default InteractionManagerStub;
+1 -40
View File
@@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<a438af540f18c77572f05cef9481b7a6>>
* @generated SignedSource<<6996c96aed9284cd96a6fa1c64d7df71>>
*
* This file was generated by scripts/js-api/build-types/index.js.
*/
@@ -249,30 +249,6 @@ declare const I18nManager: {
declare const Image: ImageType
declare const InputAccessoryView: typeof InputAccessoryView_default
declare const InputAccessoryView_default: React.ComponentType<InputAccessoryViewProps>
declare const InteractionManager: typeof InteractionManagerStub_default
declare const InteractionManagerStub_default: {
Events: {
interactionComplete: "interactionComplete"
interactionStart: "interactionStart"
}
addListener(
eventType: string,
listener: (...args: any) => unknown,
context: unknown,
): EventSubscription
clearInteractionHandle(handle: Handle): void
createInteractionHandle(): Handle
runAfterInteractions(task: null | Task | undefined): {
cancel: () => void
then: <U>(
onFulfill?:
| (($$PARAM_0$$: void) => (Promise<U> | U) | undefined)
| undefined,
onReject?: ((error: unknown) => (Promise<U> | U) | undefined) | undefined,
) => Promise<U>
}
setDeadline(deadline: number): void
}
declare const Keyboard: typeof Keyboard_default
declare const Keyboard_default: KeyboardImpl
declare const LayoutAnimation: typeof LayoutAnimation_default
@@ -2476,7 +2452,6 @@ declare function getWithFallback_DEPRECATED<Config extends {}>(
viewConfigProvider: () => PartialViewConfig,
): React.ComponentType<Config>
declare type hairlineWidth = typeof hairlineWidth
declare type Handle = number
declare interface HardwareBackPressEvent {
readonly timeStamp: number
readonly type: string
@@ -2757,7 +2732,6 @@ declare type InstanceHandle =
| ReactNativeDocumentElementInstanceHandle
| ReactNativeDocumentInstanceHandle
declare type Int32 = number
declare type InteractionManager = typeof InteractionManager
declare type InternalInstanceHandle = symbol & {
__InternalInstanceHandle__: string
}
@@ -3876,10 +3850,6 @@ declare type ProgressBarAndroidProps =
ProgressBarAndroidBaseProps &
IndeterminateProgressBarAndroidStyleAttrProp
>
declare type PromiseTask = {
name: string
gen: () => Promise<void>
}
declare type PublicModalInstance = HostInstance
declare type PublicRootInstance = symbol & {
__PublicRootInstance__: string
@@ -4715,10 +4685,6 @@ declare type ShareOptions = {
subject?: string
tintColor?: ColorValue
}
declare type SimpleTask = {
name: string
run: () => void
}
declare interface Spec extends TurboModule {
readonly getConstants: () => {
readonly buttonClicked: DialogAction
@@ -5056,7 +5022,6 @@ declare type TargetedEvent = {
declare type TargetEvent = {
readonly target: number
}
declare type Task = (() => void) | PromiseTask | SimpleTask
declare type TaskCanceller = () => void
declare type TaskCancelProvider = () => TaskCanceller
declare type TaskProvider = () => HeadlessTask
@@ -6061,7 +6026,6 @@ export {
FontVariant, // 7c7558bb
GestureResponderEvent, // f693e9a5
GestureResponderHandlers, // cc70e4cb
Handle, // 2d65285d
HostComponent, // 16fccab5
HostInstance, // 9b5a9ec2
I18nManager, // f9870e00
@@ -6089,7 +6053,6 @@ export {
InputAccessoryViewProps, // ac36060b
InputModeOptions, // 4e8581b9
Insets, // e7fe432a
InteractionManager, // c324d6e3
KeyDownEvent, // d4971b72
KeyEvent, // 20fa4267
KeyUpEvent, // bc6bd87b
@@ -6167,7 +6130,6 @@ export {
ProcessedColorValue, // 33f74304
ProgressBarAndroid, // 00fcd180
ProgressBarAndroidProps, // f59f8f03
PromiseTask, // 5102c862
PublicRootInstance, // 8040afd7
PublicTextInstance, // cd0d8f8d
PushNotificationEventName, // 84e7e150
@@ -6213,7 +6175,6 @@ export {
ShareActionSheetIOSOptions, // eff574f5
ShareContent, // 7c627896
ShareOptions, // 800c3a4e
SimpleTask, // 0e619d11
StatusBar, // 875b4eca
StatusBarAnimation, // 7fd047e6
StatusBarProps, // b72a9127
+19 -12
View File
@@ -27,6 +27,7 @@
import typeof * as ReactNativePublicAPI from './index.js.flow';
const warnOnce = require('./Libraries/Utilities/warnOnce').default;
const invariant = require('invariant');
module.exports = {
// #region Components
@@ -256,18 +257,6 @@ module.exports = {
get I18nManager() {
return require('./Libraries/ReactNative/I18nManager').default;
},
/**
* @deprecated
*/
get InteractionManager() {
warnOnce(
'interaction-manager-deprecated',
'InteractionManager has been deprecated and will be removed in a ' +
'future release. Please refactor long tasks into smaller ones, and ' +
" use 'requestIdleCallback' instead.",
);
return require('./Libraries/Interaction/InteractionManager').default;
},
get Keyboard() {
return require('./Libraries/Components/Keyboard/Keyboard').default;
},
@@ -394,3 +383,21 @@ module.exports = {
},
// #endregion
} as ReactNativePublicAPI;
if (__DEV__) {
/* $FlowFixMe[prop-missing] This is intentional: Flow will error when
* attempting to access InteractionManager. */
/* $FlowFixMe[invalid-export] This is intentional: Flow will error when
* attempting to access InteractionManager. */
Object.defineProperty(module.exports, 'InteractionManager', {
configurable: true,
get() {
invariant(
false,
'InteractionManager has been removed from react-native core. ' +
'Please refactor long tasks into smaller ones, and use ' +
"'requestIdleCallback' instead.",
);
},
});
}
-7
View File
@@ -277,13 +277,6 @@ export {findNodeHandle} from './Libraries/ReactNative/RendererProxy';
export {default as I18nManager} from './Libraries/ReactNative/I18nManager';
export type {
Handle,
PromiseTask,
SimpleTask,
} from './Libraries/Interaction/InteractionManager';
export {default as InteractionManager} from './Libraries/Interaction/InteractionManager';
export type {
AndroidKeyboardEvent,
IOSKeyboardEvent,
@@ -57,7 +57,6 @@ import {
ImageResolvedAssetSource,
ImageStyle,
InputAccessoryView,
InteractionManager,
Keyboard,
KeyboardAvoidingView,
LayoutChangeEvent,
@@ -782,10 +781,6 @@ if (Systrace.isEnabled()) {
Systrace.counterEvent('counter', 123);
}
InteractionManager.runAfterInteractions(() => {
// ...
}).then(() => 'done');
export class FlatListTest extends React.Component<FlatListProps<number>, {}> {
list: FlatList<any> | null = null;
-1
View File
@@ -113,7 +113,6 @@ export * from '../Libraries/EventEmitter/RCTNativeAppEventEmitter';
export * from '../Libraries/Image/Image';
export * from '../Libraries/Image/ImageResizeMode';
export * from '../Libraries/Image/ImageSource';
export * from '../Libraries/Interaction/InteractionManager';
export * from '../Libraries/Interaction/PanResponder';
export * from '../Libraries/LayoutAnimation/LayoutAnimation';
export * from '../Libraries/Linking/Linking';