UNPKG

react-native-repro

Version:

Repro is a mobile analytics tool that lets you have much deeper understanding of mobile app users.

64 lines (53 loc) 1.96 kB
// Import example: // // import Repro from 'react-native-repro'; import { TurboModuleRegistry } from 'react-native'; import { newsFeedManager } from './src/NewsFeedManager.js'; import { eventManager } from './src/EventEmitterOpenUrl.js'; const isNewArchitecture = global.nativeFabricUIManager != null; const NativeReproReact = TurboModuleRegistry.get('ReproReactBridgeModule'); const NativeReproRemoteConfig = TurboModuleRegistry.get("ReproRemoteConfigBridge"); let reproConstants = {}; let remoteConfigConstants = {}; if (isNewArchitecture) { reproConstants = NativeReproReact.getConstants(); remoteConfigConstants = NativeReproRemoteConfig.getConstants(); } else { reproConstants = NativeReproReact; remoteConfigConstants = NativeReproRemoteConfig; } const mergedRemoteConfig = new Proxy(NativeReproRemoteConfig || {}, { get: function(target, prop) { if (remoteConfigConstants && remoteConfigConstants.hasOwnProperty(prop)) { return remoteConfigConstants[prop]; } return target[prop]; } }); const Repro = new Proxy({}, { get: function(_target, prop) { if (prop === 'setOpenUrlCallback') { return eventManager[prop].bind(eventManager); } if (prop === 'remoteConfig') { return mergedRemoteConfig; } if (prop === 'handleWebViewUrl') { return async function(...args) { await NativeReproReact._handleWebViewUrl(args[0]); return args[0].startsWith('repro://'); }; } if (!isNewArchitecture && newsFeedManager.hasOwnProperty(prop)) { return newsFeedManager[prop]; } if (reproConstants && reproConstants.hasOwnProperty(prop)) { return reproConstants[prop]; } if (NativeReproReact && prop in NativeReproReact) { return NativeReproReact[prop]; } return undefined; } }); export default Repro;