简体   繁体   English

CodenameOne:Webview在iOS版本的应用程序中不可滚动

[英]CodenameOne: Webview not scrollable in iOS version of app

I have a legacy cn1 app (using the old GUI builder) with a web browser component in the center of the Form (centered in a BorderLayout Container which is the main Form component). 我有一个旧的cn1应用程序(使用旧的GUI构建器),该Web组件位于Form的中心(居中于BorderLayout容器,它是Form的主要组件),并且带有Web浏览器组件。 In the simulator as well as on an Android device the WebBrowser renders fine. 在模拟器以及Android设备上,WebBrowser均可正常显示。 In the iOS simulator the entire component shows up as a black rectangle, and on an iPhone (5s running iOS 9.1), the content of the WebBrowser is visible but doesn't scroll. 在iOS模拟器中,整个组件显示为黑色矩形,在iPhone(运行iOS 9.1的5s)上,WebBrowser的内容可见但不滚动。

Is there some particular setting that needs to be changed for it be scrollable? 是否需要更改某些特定设置才能使其滚动?

This is my code: 这是我的代码:

        WebBrowser web = new WebBrowser() {
            @Override
            public void onLoad(String url) {
                System.out.println("Article body webview loaded");
                Component c = getInternal();
                if (c instanceof BrowserComponent) {
                    BrowserComponent b = (BrowserComponent) c;
                    String text = ((String) m.currentArticleInfo.get("id"));
                    b.execute("loadArticle('" + text + "')");

                }

            }
        };

        ((BrowserComponent) web.getInternal()).setNativeScrollingEnabled(true);
        ((BrowserComponent) web.getInternal()).setScrollVisible(false);
        web.setScrollVisible(false);
        web.setURL("jar:///article_body.html");
        web.setScrollable(true);
        web.getAllStyles().setPaddingTop(10);
        form.addComponent(BorderLayout.CENTER, web); 

I don't see any errors in the console. 我在控制台中看不到任何错误。 The web page code looks like this: 网页代码如下所示:

<!DOCTYPE html>
<html>
    <head>
        <title></title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link rel="stylesheet" type="text/css" href="https://www.example.com/styles/style.css" />

        <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
        <style>
            body::-webkit-scrollbar{
                width: 0 !important;
            }
            #left_side_article #right #the_article #details_info{
                font-size: 3.5mm !important;
            }
            div#the_article{
                border: none !important;
            }
            div#the_article_header{
                padding: 0 !important;
            }
            </style>
    </head>
    <body style="min-height: 100px">
        <div id="left_side_article">
            <div id="right">
                <div id="the_article">
                    <div id="details_info" >

                    </div>
                </div>
            </div>
        </div>
         <script>
                function loadArticle(content) {
                    console.log('in load article function, article id: ' + content);
                    var url = "https://www.example.com/api/article_body_ajax.php";
                     $.post(url,{"app_code": "myappcode", "id" : content},function(data,status,jqxhr){
                         $("#details_info").html(data);
                         $("#details_info img").each(function(){
                           $(this).attr("src", "https://www.example.com/" + $(this).attr("src"));
                           $(this).css("height", "auto");
                         });
                     });
                };
        </script>
    </body>
</html>

Update 更新资料

I tried debugging the WebView by downloading the app sources and using Safari to inspect the page. 我尝试通过下载应用程序源并使用Safari来检查页面来调试WebView。 Safari recognized that there was a web page open in the app, and I was able to choose it from the Develop menu in Safari, but the inspect window was completely empty - no elements whatsoever. Safari意识到应用程序中有一个打开的网页,我可以从Safari的“开发”菜单中选择它,但是“检查”窗口完全是空的-没有任何元素。

That might be related to changes we made to getComponentAt see if this is still happening after the update this weekend. 这可能与我们对getComponentAt所做的更改有关,以查看在本周末更新之后是否仍在发生这种情况。 We discussed some of the regressions related to this here: https://www.codenameone.com/blog/dont-touch-that-code.html 我们在这里讨论了与此相关的一些回归: https : //www.codenameone.com/blog/dont-touch-that-c​​ode.html

I just committed a fix for the scrolling issue in iOS here . 我只是在这里针对iOS中的滚动问题提交了修复程序。 There was a bug that caused scrolling to be disabled if you call setNativeScrollingEnabled(true) . 如果调用setNativeScrollingEnabled(true) ,有一个错误会导致滚动被禁用。 This fix will be available in the next library update (next Friday). 下一个库更新(下星期五)将提供此修复程序。 In the mean time, you can work around this by just not calling setNativeScrollingEnabled(true) - as the default is true anyways. 同时,您可以通过不调用setNativeScrollingEnabled(true)来解决此问题-因为无论如何默认值都是true

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM