fix(metro/modules): patch registry instead
This commit is contained in:
parent
87913cecfc
commit
4b94b7fd9c
2 changed files with 7 additions and 6 deletions
|
|
@ -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");
|
||||
|
|
|
|||
|
|
@ -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, {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue