diff --git a/packages/eslint-plugin-react-native/utils.js b/packages/eslint-plugin-react-native/utils.js index 3c9650e06e5..01c41d361b6 100644 --- a/packages/eslint-plugin-react-native/utils.js +++ b/packages/eslint-plugin-react-native/utils.js @@ -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: [ diff --git a/packages/react-native/Libraries/Interaction/InteractionManager.d.ts b/packages/react-native/Libraries/Interaction/InteractionManager.d.ts deleted file mode 100644 index d1d72b72341..00000000000 --- a/packages/react-native/Libraries/Interaction/InteractionManager.d.ts +++ /dev/null @@ -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; -}; - -/** - * @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; - 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; diff --git a/packages/react-native/Libraries/Interaction/InteractionManager.js b/packages/react-native/Libraries/Interaction/InteractionManager.js deleted file mode 100644 index 55c4c27e85b..00000000000 --- a/packages/react-native/Libraries/Interaction/InteractionManager.js +++ /dev/null @@ -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, -}; -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: ( - onFulfill?: ?(void) => ?(Promise | U), - onReject?: ?(error: unknown) => ?(Promise | U), - ) => Promise, - 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; diff --git a/packages/react-native/ReactNativeApi.d.ts b/packages/react-native/ReactNativeApi.d.ts index 6ffe826ecfd..67486c67cf0 100644 --- a/packages/react-native/ReactNativeApi.d.ts +++ b/packages/react-native/ReactNativeApi.d.ts @@ -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<> + * @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 -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: ( - onFulfill?: - | (($$PARAM_0$$: void) => (Promise | U) | undefined) - | undefined, - onReject?: ((error: unknown) => (Promise | U) | undefined) | undefined, - ) => Promise - } - 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( viewConfigProvider: () => PartialViewConfig, ): React.ComponentType 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 -} 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 diff --git a/packages/react-native/index.js b/packages/react-native/index.js index abe61b5a207..20f2c827680 100644 --- a/packages/react-native/index.js +++ b/packages/react-native/index.js @@ -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.", + ); + }, + }); +} diff --git a/packages/react-native/index.js.flow b/packages/react-native/index.js.flow index 9f2eac497d6..b0a636234c6 100644 --- a/packages/react-native/index.js.flow +++ b/packages/react-native/index.js.flow @@ -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, diff --git a/packages/react-native/types/__typetests__/index.tsx b/packages/react-native/types/__typetests__/index.tsx index a3bfdb5286b..7f372d745c1 100644 --- a/packages/react-native/types/__typetests__/index.tsx +++ b/packages/react-native/types/__typetests__/index.tsx @@ -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, {}> { list: FlatList | null = null; diff --git a/packages/react-native/types/index.d.ts b/packages/react-native/types/index.d.ts index b2f6f02d46b..f410d330458 100644 --- a/packages/react-native/types/index.d.ts +++ b/packages/react-native/types/index.d.ts @@ -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';