From f85a6d797b5b8050e2f39edf74efacb7eef78453 Mon Sep 17 00:00:00 2001 From: Krzysztof Piaskowy Date: Fri, 10 Jan 2025 11:28:56 +0100 Subject: [PATCH] Compatibility with 0.77 for findHostInstance (#6883) ## Summary The method findHostInstance in react-native@0.77 has been moved from a named export to the default export. This PR fix compatibility issue. ## Test plan Run application with `react-native@0.77` --- .../src/platform-specific/findHostInstance.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/react-native-reanimated/src/platform-specific/findHostInstance.ts b/packages/react-native-reanimated/src/platform-specific/findHostInstance.ts index 00d56154e40..b61cb93b6b0 100644 --- a/packages/react-native-reanimated/src/platform-specific/findHostInstance.ts +++ b/packages/react-native-reanimated/src/platform-specific/findHostInstance.ts @@ -42,16 +42,24 @@ function resolveFindHostInstance_DEPRECATED() { } if (isFabric()) { try { + const ReactFabric = require('react-native/Libraries/Renderer/shims/ReactFabric'); + // Since RN 0.77 ReactFabric exports findHostInstance_DEPRECATED in default object so we're trying to + // access it first, then fallback on named export findHostInstance_DEPRECATED = - require('react-native/Libraries/Renderer/shims/ReactFabric').findHostInstance_DEPRECATED; + ReactFabric?.default?.findHostInstance_DEPRECATED ?? + ReactFabric?.findHostInstance_DEPRECATED; } catch (e) { throw new ReanimatedError( 'Failed to resolve findHostInstance_DEPRECATED' ); } } else { + const ReactNative = require('react-native/Libraries/Renderer/shims/ReactNative'); + // Since RN 0.77 ReactFabric exports findHostInstance_DEPRECATED in default object so we're trying to + // access it first, then fallback on named export findHostInstance_DEPRECATED = - require('react-native/Libraries/Renderer/shims/ReactNative').findHostInstance_DEPRECATED; + ReactNative?.default?.findHostInstance_DEPRECATED ?? + ReactNative?.findHostInstance_DEPRECATED; } }