在native - script中访问android视图



我试图使用一个加载器插件的原生脚本,并运行到一个错误,说:

Error creating Loading Indicator Pop Over: Cannot read property 'drawable' of undefined

这个错误似乎是由于在加载器的选项中使用了android.view.View

关于这个错误没有太多额外的信息,但是从我使用移动应用的经验来看,我想说这个错误的发生是因为视图还没有加载。

我尝试应用超时,移动调用周围(从onNavigatingTo到onPageLoad),没有任何帮助。

下面是我使用的代码:
const options = {
message: "Daten werden geladen…",
details: "Bitte warten",
progress: 0.65,
margin: 10,
dimBackground: true,
color: "#fff", // color of indicator and labels
// background box around indicator
// hideBezel will override this if true
backgroundColor: "black",
userInteractionEnabled: false, // default true. Set false so that the touches will fall through it.
hideBezel: true, // default false, can hide the surrounding bezel
mode: Mode.AnnularDeterminate, // see options below
android: {
view: android.view.View, // Target view to show on top of (Defaults to entire window)
cancelable: true,
cancelListener: function (dialog) {
console.log("Loading cancelled");
}
},
ios: {
view: UIView, // Target view to show on top of (Defaults to entire window)
}
};
loader.show(options);

Nativescript 7。

任何想法?

首先,我不喜欢在没有适当的isIOS/isAndroid包装的情况下使用android.view.ViewUIView之类的平台特定代码。所以我建议使用this.page.nativeViewthis.page.getViewById('someIdHere').nativeView代替。

添加零毫秒超时也是一个很好的做法。只是为了确保页面内容可用。

如果你能给我提供一些小的例子,这样我就可以检查一下了

最新更新