1

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). In the simulator as well as on an Android device the WebBrowser renders fine. 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.

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 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.

ygesher
  • 1,133
  • 12
  • 26
  • I'm not sure, try invoking a revalidate after the on-load. When you say iOS simulator do you mean native OS simulator or the Codename One simulator? – Shai Almog Aug 27 '17 at 04:01
  • In the cn1 simulator, it works fine. In the iOS simulator, it just shows up black. Why would a revalidate change the scroll behavior? I can see the content already. – ygesher Aug 27 '17 at 06:45
  • It might impact sizing, I've asked Steve to look into it – Shai Almog Aug 28 '17 at 03:44
  • 1
    Try debugging the web view in Safari. https://webdesign.tutsplus.com/articles/quick-tip-using-web-inspector-to-debug-mobile-safari--webdesign-8787 That will allow you to rule out the two most obvious things: a javascript exception, and a CSS directive that is affecting sizing/scrolling. For CSS , you'll be able to look at the styles of every element , and adjust them live to see if you can get it to scroll. – steve hannah Aug 28 '17 at 17:53
  • I tried reinstalling all the cn1libs, like I saw suggested in another question, and now I have a build error: /var/folders/zh/kb_4hqhn4kg1h0r5dp_6htcm0000gn/T/build7851581202651036597xxx/dist/MyApplication-src/com_parse4cn1_encode_ParseDecoder.m:308:23: error: implicit declaration of function 'ca_weblite_codename1_json_JSONArray___INIT_____java_util_ArrayList' is invalid in C99 [-Werror,-Wimplicit-function-declaration] /* CustomInvoke */ca_weblite_codename1_json_JSONArray___INIT_____java_util_ArrayList(threadStateData, SP[-1].data.o, locals[0].data.o); SP -= 1; – ygesher Sep 07 '17 at 20:34
  • Sorry, I think I left out a stage earlier. When I tried adding a call to `revalidate()`, for whatever reason (I made some other minor changes to the project), I got the following error when trying to run the source code: `library not found for -lBolts`. Then, in order to solve that problem, I tried reinstalling all the cn1libs as mentioned above, and got the above error. – ygesher Sep 09 '17 at 19:15
  • @ShaiAlmog do you know where the new error I mentioned above is emanating from? `/var/folders/zh/kb_4hqhn4kg1h0r5dp_6htcm0000gn/T/build785158‌​1202651036597xxx/dis‌​t/MyApplication-src/‌​com_parse4cn1_encode‌​_ParseDecoder.m:308:‌​23: error: implicit declaration of function ` Is it an error in the parse4cn1 library, a missing dependency, a bug in the build process? – ygesher Sep 14 '17 at 10:54
  • Did you set the build hints mentioned in their web page? – Shai Almog Sep 15 '17 at 04:15
  • Yes. The app used to build fine, before I reinstalled the cn1libs. – ygesher Sep 15 '17 at 07:10
  • Can you provide a fresh link to a failed build log? We'll need to see the full log – Shai Almog Sep 17 '17 at 04:23
  • [https://s3.amazonaws.com/codenameone-build-response/e27a5ce1-5802-4761-9d55-55f3909e3bf2-1505653662931-error.txt](https://s3.amazonaws.com/codenameone-build-response/e27a5ce1-5802-4761-9d55-55f3909e3bf2-1505653662931-error.txt) – ygesher Sep 17 '17 at 13:12
  • The build error was solved [here](https://github.com/sidiabale/parse4cn1/issues/31). The `library not found for -lBolts.` error was solved by opening the `.xcworkspace` file instead of `.xcodeproj` file. [reference](https://stackoverflow.com/a/36947791/1857802) – ygesher Sep 25 '17 at 20:43
  • @ShaiAlmog I updated my question. I would appreciate if you could look into it again. – ygesher Oct 24 '17 at 18:21
  • @stevehannah I rebuilt the entire app with no GUI builder (previously it was based on the old GUI builder), and the webview still doesn't scroll. When I debug it in Safari I see nothing out of the ordinary - no js errors, no CSS that would prevent scrolling. I even tried adding `overflow: scroll` to the relevant `
    ` but still no dice. Do you have any other ideas?
    – ygesher Jan 13 '18 at 19:30

2 Answers2

0

That might be related to changes we made to getComponentAt see if this is still happening after the update this weekend. We discussed some of the regressions related to this here: https://www.codenameone.com/blog/dont-touch-that-code.html

Shai Almog
  • 51,749
  • 5
  • 35
  • 65
0

I just committed a fix for the scrolling issue in iOS here. There was a bug that caused scrolling to be disabled if you call 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.

steve hannah
  • 4,586
  • 11
  • 18