// Helper file to import native PortalMobileMpc Module // Handles both TurboModule (New Architecture) and legacy NativeModules (Old Architecture) // Also provides helpful error messages for linking issues import { NativeModules, Platform, TurboModuleRegistry } from 'react-native' const LINKING_ERROR = "The package '@portal-hq/gdrive-storage' doesn't seem to be linked. Make sure: \n\n" + Platform.select({ ios: "- You have run 'pod install'\n", default: '', }) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo managed workflow\n' const getNewProxy = () => new Proxy( {}, { get() { throw new Error(LINKING_ERROR) }, }, ) const createPortalMobileMpcModule = () => { try { // Try to get the TurboModule first (New Architecture) // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-return, @typescript-eslint/no-var-requires return require('@portal-hq/core/src/NativePortalMobileMpc').default } catch { // Fall back to legacy module (Old Architecture) // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment const nativeModule = NativeModules.PortalMobileMpc if (!nativeModule) { return getNewProxy() } // eslint-disable-next-line @typescript-eslint/no-unsafe-return return nativeModule } } const createPortalGoogleSignInModule = () => { try { // Try to get the TurboModule first (New Architecture) // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-return, @typescript-eslint/no-var-requires return require('./NativePortalGoogleSignIn').default } catch { // Fall back to legacy module (Old Architecture) // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment const nativeModule = NativeModules.PortalGoogleSignIn if (!nativeModule) { return getNewProxy() } // eslint-disable-next-line @typescript-eslint/no-unsafe-return return nativeModule } } // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment export const PortalMobileMpcModule = createPortalMobileMpcModule() // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment export const PortalGoogleSignInModule = createPortalGoogleSignInModule() // Legacy export for backward compatibility export const isTurboModuleEnabled = TurboModuleRegistry.get('PortalMobileMpc') != null