[Shims] Properly shim React
This commit is contained in:
parent
48138c5b7c
commit
fee7f345fa
8 changed files with 18 additions and 10 deletions
|
@ -2,7 +2,6 @@ import { MetroModules, PropsFinder, PropsFinderAll } from "@types";
|
|||
|
||||
// Metro require
|
||||
declare const __r: (moduleId: number) => any;
|
||||
let moment: any;
|
||||
|
||||
// Function to blacklist a module, preventing it from being searched again
|
||||
function blacklist(id: number) {
|
||||
|
@ -14,19 +13,23 @@ function blacklist(id: number) {
|
|||
})
|
||||
}
|
||||
|
||||
// Blacklist any "bad-actor" modules
|
||||
// Blacklist any "bad-actor" modules, e.g. the dreaded null proxy, the window itself, or undefined modules
|
||||
for (const key in window.modules) {
|
||||
const id = Number(key);
|
||||
const module = window.modules[id].publicModule.exports;
|
||||
|
||||
if (!moment && module && module.isMoment) moment = module;
|
||||
|
||||
if (!module || module === window || module["proxygone"] === null) {
|
||||
blacklist(id);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Hoist React
|
||||
window.React = Object.values(window.modules).find(m => m.publicModule.exports.createElement).publicModule.exports;
|
||||
|
||||
// Find moment
|
||||
let moment = Object.values(window.modules).find(m => m.publicModule.exports.isMoment).publicModule.exports;
|
||||
|
||||
// Function to filter through modules
|
||||
export const filterModules = (modules: MetroModules, single = false) => (filter: (m: any) => boolean) => {
|
||||
const found = [];
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { Asset } from "@types";
|
||||
import { React, ReactNative as RN } from "@metro/common";
|
||||
import { ReactNative as RN } from "@metro/common";
|
||||
import { showToast } from "@ui/toasts";
|
||||
import { getAssetIDByName } from "@ui/assets";
|
||||
import { Forms } from "@ui/components";
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import { React } from "@metro/common";
|
||||
import { Forms } from "@ui/components";
|
||||
import { getAssetIDByName } from "@ui/assets";
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import { React } from "@metro/common";
|
||||
import { getAssetIDByName } from "@ui/assets";
|
||||
import { showToast } from "@ui/toasts";
|
||||
import { Forms } from "@ui/components";
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
import { React, i18n } from "@metro/common";
|
||||
import { i18n } from "@metro/common";
|
||||
import { findByDisplayName } from "@metro/filters";
|
||||
import { after } from "@lib/patcher";
|
||||
import findInReactTree from "@utils/findInReactTree";
|
||||
import SettingsSection from "@ui/settings/components/SettingsSection";
|
||||
import General from "@ui/settings/pages/General";
|
||||
import Plugins from "@ui/settings/pages/Plugins";
|
||||
import AssetBrowser from "@ui/settings/pages/AssetBrowser";
|
||||
|
||||
const screensModule = findByDisplayName("getScreens", false);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { React, ReactNative as RN } from "@metro/common";
|
||||
import { ReactNative as RN } from "@metro/common";
|
||||
import { Forms } from "@ui/components";
|
||||
import { all } from "@ui/assets";
|
||||
import AssetDisplay from "@ui/settings/components/AssetDisplay";
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { React, ReactNative as RN, url } from "@metro/common";
|
||||
import { ReactNative as RN, url } from "@metro/common";
|
||||
import { DISCORD_SERVER, GITHUB } from "@lib/constants";
|
||||
import { connectToDebugger } from "@lib/debug";
|
||||
import { getAssetIDByName } from "@ui/assets";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue