diff --git a/src/entry.ts b/src/entry.ts index c5612d6..fa9de16 100644 --- a/src/entry.ts +++ b/src/entry.ts @@ -10,7 +10,6 @@ async function initializeBunny() { Object.freeze = Object.seal = Object; await require("@metro/internals/caches").initMetroCache(); - require("@metro/internals/modules"); await require(".").default(); } catch (e) { const { ClientInfoManager } = require("@lib/api/native/modules"); diff --git a/src/metro/internals/modules.ts b/src/metro/internals/modules.ts index cbfc1a9..7bd65f0 100644 --- a/src/metro/internals/modules.ts +++ b/src/metro/internals/modules.ts @@ -16,6 +16,7 @@ const functionToString = Function.prototype.toString; let patchedInspectSource = false; let patchedImportTracker = false; +let patchedNativeComponentRegistry = false; let _importingModuleId: number = -1; for (const key in metroModules) { @@ -89,16 +90,17 @@ function onModuleRequire(moduleExports: any, id: Metro.ModuleID) { } // There are modules registering the same native component - if (moduleExports?.default?.name === "requireNativeComponent") { - instead("default", moduleExports, (args: any, origFunc: any) => { + if (!patchedNativeComponentRegistry && ["customBubblingEventTypes", "customDirectEventTypes", "register", "get"].every(x => moduleExports[x])) { + instead("register", moduleExports, (args: any, origFunc: any) => { try { return origFunc(...args); - } catch { - return args[0]; - } + } catch { } }); + + patchedNativeComponentRegistry = true; } + // Hook DeveloperExperimentStore if (moduleExports?.default?.constructor?.displayName === "DeveloperExperimentStore") { moduleExports.default = new Proxy(moduleExports.default, {