InteractionManager has been removed from react-native core.
After upgrading to React Native 0.87 (or Expo SDK 58), code that waits for animations with InteractionManager stops working. A development build shows a red screen:
Invariant Violation: InteractionManager has been removed from react-native core. Please refactor long tasks into smaller ones, and use 'requestIdleCallback' instead.
A release build has no such message: the import is undefined, so the first call fails with TypeError: Cannot read property 'runAfterInteractions' of undefined and the screen (or the app) crashes.
Why. The React Native 0.87 release notes list it under API removals: "Removed InteractionManager — use requestIdleCallback instead." The development message comes from a getter React Native 0.87 keeps on the react-native export only in development builds.
Fix. requestIdleCallback is a global in React Native; there is nothing to import.
- import { InteractionManager } from 'react-native';
-
- const task = InteractionManager.runAfterInteractions(() => loadData());
- return () => task.cancel();
+ const id = requestIdleCallback(() => loadData());
+ return () => cancelIdleCallback(id);
runAfterInteractions also returned a promise-like task (.then(), .done()). If your code awaited it, wrap the callback: await new Promise((resolve) => requestIdleCallback(resolve)). createInteractionHandle and clearInteractionHandle are gone with it; split the long work into smaller steps instead, as the error message suggests.
If the call is inside a library rather than your code, update the library; patch it (patch-package) only if no release has the change yet.
Check your project. npx nativekeel lists the files that use InteractionManager: before the upgrade as work for 0.87, and after it as a crash with the file and line.
npx nativekeel