我使用 react-native-create-library 创建了一个模块/库,用于处理自定义设备的特定 ble 程序,并为原生 ble 功能选择了 react-native-ble-manager。由于我没有在我的库中编写任何本机代码,我只是将我的模块导出到 index.js
import BleHandler from './src/BleHandler.js';
export default BleHandler;
然后我用 npm 打包了我的库,以便在测试应用程序中进行本地测试。直到这里一切都很好,我可以在测试应用程序中导入和使用我的模块。但是当我尝试初始化 ble 模块时,它失败了,因为它似乎不包含在 NativeModules 中:
[TypeError: null is not an object (evaluating 'bleManager.start')]
我在我的模块的 package.json 中包含了 ble 模块
"dependencies": {
"@react-native-community/async-storage": "^1.11.0",
"react": "16.13.1",
"react-native": "0.63.3",
"react-native-ble-manager": "^7.4.1",
"react-native-fs": "^2.16.6",
"react-native-windows": "^0.57.2"
}
但是当我签入时:
TestApplication/node_modules/my-module/node_modules
react-native-ble-manager 不存在。
我现在的问题是,是否甚至可以在模块内使用本机模块,如果可以,如何正确执行?