升级到NativeScript 6后,在iOS上点击谷歌地图上的一个标记来显示相关的信息窗口,会使应用程序崩溃。这是由于_layoutRootView被删除了-参见https://github.com/dapriett/nativescript-google-maps-sdk/issues/354上的nativescript-google-maps-sdk Issue354
问题是没有提供替代方案,而且google-maps sdk插件最近没有任何活动。
我把这篇文章贴到SO上,是为了通知更大的NativeScript社区,并了解是否有其他选择。
显示的错误消息是
JavaScript error:
file:///node_modules/nativescript-google-maps-sdk/map-view.js:164:30: JS ERROR TypeError: __webpack_require__("../node_modules/tns-core-modules/ui/utils.js").ios._layoutRootView is not a function. (In '__webpack_require__("../node_modules/tns-core-modules/ui/utils.js").ios._layoutRootView(content, CGRectMake(0, 0, width, height))', '__webpack_require__("../node_modules/tns-core-modules/ui/utils.js").ios._layoutRootView' is undefined)编辑
按照@manoj的指示,我使用{N} 5.3从另一个项目中手动复制了tns- _layoutRootView -modules/ui/utils.d.ts和tns-core-modules/ui/utils.ios.js中的核心代码。iOs上的信息窗口现在可以工作了!!
我完全明白在node-module中编辑代码不是一个好主意,但是我永远不能使用Manoj的方法来避免webpack的错误。有没有更好的方法从我自己的javascript项目中向NativeScript模块添加函数?
发布于 2019-09-12 03:44:57
尝尝这个,
import * as utils from 'tns-core-modules/utils/utils';
if (utils.ios) {
(<any>utils.ios)._layoutRootView = function(rootView, parentBounds) {
if (!rootView || !parentBounds) {
return;
}
const size = parentBounds.size;
const width = utils.layout.toDevicePixels(size.width);
const height = utils.layout.toDevicePixels(size.height);
const widthSpec = utils.layout.makeMeasureSpec(width, utils.layout.EXACTLY);
const heightSpec = utils.layout.makeMeasureSpec(height, utils.layout.EXACTLY);
rootView.measure(widthSpec, heightSpec);
const origin = parentBounds.origin;
const left = origin.x;
const top = origin.y;
rootView.layout(left, top, width, height);
}
}https://stackoverflow.com/questions/57812762
复制相似问题