JavaFX WebView Progress总是从0.0到1.0。 (没有中间值) [英] JavaFX WebView Progress always goes from 0.0 to 1.0. (No intermediate values)

查看:233
本文介绍了JavaFX WebView Progress总是从0.0到1.0。 (没有中间值)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用GluonHQ(JavaFXPorts)开发一个应用程序,我正在使用WebView加载一些Internet页面。我注意到当我在桌面上使用以下代码时

I am currently developing an application with GluonHQ (JavaFXPorts) where I am using the WebView to load some Internet pages. I have noticed that when I am using the following code on Desktop

webEngine.getLoadWorker().progressProperty().addListener((a,b,progress) -> System.out.println(": " +progress.doubleValue()));

它打印出从0.0到1.0的加载。

it prints out the loading from 0.0 to 1.0.

Loading Page: 0.0
Loading Page: 0.22
Loading Page: 0.38
Loading Page: 0.81
Loading Page: 1.0

虽然在iOS上它总是返回0.0和1.0,而不是任何中间值。

Whilst on iOS it always returns 0.0 and 1.0, not any intermediate values.

Loading Page: 0.0
Loading Page: 1.0

有办法解决这个问题吗?

Any way to handle this?

推荐答案

使用JavaFXPorts,在移动设备(Android和iOS)上, WebView 控件不是JavaFX内置控件,而是本机控件。例如,在iOS上,使用 UIWebView 控件。顺便说一句,同样适用于 TextField TextArea 控件。

With JavaFXPorts, on mobile (both Android and iOS) the WebView control is not the JavaFX built-in control but the native control. For instance, on iOS, a UIWebView control is used. Same applies to TextField and TextArea controls, by the way.

为了保持与桌面相同的API,JavaFXWebView控件,但它只是一个外观,一个具有相同属性但没有webKit的节点。一切都传递给本机控件。

To keep the same API as in desktop, a JavaFX "WebView" control is used, but it is just a facade, a node with same properties, but without webKit. Everything is passed down to the native control.

虽然本机层和Java层之间存在双向通信,但不发送所有,因此没有1:1本机控件属性与桌面实现的JavaFX属性之间的关系。

And while there is communication in both ways between the native and the Java layers, not everything is sent, so there is no 1:1 relation between the native control properties and the JavaFX properties of the desktop implementation.

如果检查原生实现,你可以找到一些与加载状态和本机回调相关的方法:

If you check the native implementation in Objective-C for iOS, you can find some methods related to the loading status, and the native callbacks:

- (void)webViewDidStartLoad:(UIWebView *)webView {
    ...
    (*env)->CallVoidMethod(env, jObject, jmidLoadStarted);
}
- (void)webViewDidFinishLoad:(UIWebView *)wv {
    ...
    (*env)->CallVoidMethod(env, jObject, jmidLoadFinished, jUrl, jInner);
}

转到JavaFX control

// native callbacks
private void notifyLoadStarted() {
    engine.notifyLoadStarted();
}

private void notifyLoadFinished(String loc, String content) {
    engine.notifyLoadFinished(loc, content);
}

如您所见,没有与加载进度相关的方法,所以这就是你不会获得任何中间价值的原因。

As you can see, there is no method related to the loading progress, so that is the reason you won't get any intermediate value.

这篇关于JavaFX WebView Progress总是从0.0到1.0。 (没有中间值)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆