是否可以为使用 `document` 的现有库编写一个填充程序并仍然保持原始状态?

Is it possible to write a shim for a existing library that uses `document` and still keep it pristine?

我正在将一个库导入 ReactNative 项目,该项目使用 document 大约 50 次。因为 ReactNative 不使用 document,我将不得不重写这些行以使其在 ReactNative 环境中工作。问题是..

是否可以创建一个垫片以使原始库完好无损?

我将不得不重写 document.bodydocument.createElementdocument.appendElement 等行。我想 document.body 可能只是我的根容器 class,其他两种方法不言自明。

因为我以前从未见过这样的事情,所以我只是猜测。是否可以导入该库,然后将 document 绑定为 ReactNative component,以便该组件替换所有提及的文档?

The JS file in question.

虽然可以在全局范围内填充 document 对象,但我敢打赌,您无法让该组件在 React Native 中工作。它与本机浏览器 API 耦合太深,不可行。

相反,我会研究 运行 WebView 中的功能,或者找到您要实现的目标的替代解决方案。

您尝试使用的库 Kandy 似乎提供了 iOS 和 Android SDK。一种解决方案可能是将原生 SDK 桥接到 React Native。