Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

How to refresh Webview on $pull

Camilo edited this page May 22, 2022 · 3 revisions

This is a sample code that demostrates how you can use the $pull event to refresh a webview.

web.html

A simple website that shows the current timestamp. Put this file inside the file directory.

<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
    Refreshed at: <span id="time"></span>
    <script type="text/javascript">
        document.getElementById("time").innerHTML = (new Date()).toString()
    </script>
</body>
</html>

app.json

Note the addition of an empty sections ("sections": [{"items": [{}]}],) . Without it the $pull will not trigger properly. Also you must check that SWTableViewCell.m line 94 contains the fix of if (self.subviews.count > 0 …​ or it will crash. Update your pods :).

{
    "$jason": {
        "head": {
            "title": "Reload webpage on pull",
            "actions": {
                "$pull": {
                    "type": "$agent.request",
                    "options": {
                        "id": "$webcontainer",
                        "method": "(() => { window.location.reload(); $agent.response(); })",
                        "params": []
                    }
                }
            }
        },
        "body": {
            "sections": [{"items": [{}]}],
            "style": {
                 "border": "rgba(0,0,0,0)"
            },
            "background": {
                "type": "html",
                "url": "file://web.html",
                "action": {
                      "type": "$default"
                }
            }
        }
    }
}

On newer version of Jasonette iOS you can use the pull option to achieve the same

{
    "$jason": {
        "head": {
            "title": "Reload webpage on pull",
            "actions": {
                "$pull": {
                    "type": "$agent.request",
                    "options": {
                        "id": "$webcontainer",
                        "method": "(() => window.location.reload())",
                        "params": []
                    }
                }
            }
        },
        "body": {
            "style": {
                 "border": "rgba(0,0,0,0)"
            },
            "background": {
                "type": "html",
                "url": "file://web.html",
                "options": {
                   "pull": true
                },
                "action": {
                      "type": "$default"
                }
            }
        }
    }
}
Clone this wiki locally