@react-native-firebase/app
Version:
A well tested, feature rich Firebase implementation for React Native, supporting iOS & Android. Individual module support for Admob, Analytics, Auth, Crash Reporting, Cloud Firestore, Database, Dynamic Links, Functions, Messaging (FCM), Remote Config, Sto
46 lines (44 loc) • 1.62 kB
JavaScript
;
/* eslint-disable no-console */
import { NativeModules } from 'react-native';
/**
* This is used by Android and iOS to get a native module.
* We additionally add a Proxy to the module to intercept calls
* and log them to the console for debugging purposes, if enabled.
* @param moduleName
* @returns Raw native module from React Native (object with methods/properties or undefined)
*/
export function getReactNativeModule(moduleName) {
const nativeModule = NativeModules[moduleName];
if (!globalThis.RNFBDebug) {
return nativeModule;
}
return new Proxy(nativeModule, {
ownKeys(target) {
return Object.keys(target);
},
get: (_, name) => {
const prop = nativeModule[name];
if (typeof prop !== 'function') return prop;
return (...args) => {
console.debug(`[RNFB->Native][🔵] ${moduleName}.${String(name)} -> ${JSON.stringify(args)}`);
const result = prop(...args);
if (result && typeof result === 'object' && 'then' in result) {
return result.then(res => {
console.debug(`[RNFB<-Native][🟢] ${moduleName}.${String(name)} <- ${JSON.stringify(res)}`);
return res;
}, err => {
console.debug(`[RNFB<-Native][🔴] ${moduleName}.${String(name)} <- ${JSON.stringify(err)}`);
throw err;
});
}
console.debug(`[RNFB<-Native][🟢] ${moduleName}.${String(name)} <- ${JSON.stringify(result)}`);
return result;
};
}
});
}
export function setReactNativeModule() {
// No-op
}
//# sourceMappingURL=nativeModuleAndroidIos.js.map