Issues using WebView for a remote web application

You must Login before you can answer or comment on any questions.

We are building a proof of concept using Titanium to wrap an existing web application but have two specific issues: 1. We are unable to use fireEvent within the web application to push events up to the Titanium application. Our web application has a number of external links so we obviously need to hijack these and route them through Ti.Platform.openURL(url); This does not seem to be possible as the remote web application does not seem to have scope to Ti to be able to execute a Ti.App.fireEvent(); 2. The WebView does not seem to be able to listen for 'swipe' events. If we add event listeners for 'touch start' or 'touch move' and these work but for some reason not swipe.

In both cases we are using the the 2.0.2 SDK and are testing on android targets (emulator and ASUS Transformer)

Thanks in advance

2 Answers

Only local HTML can call Ti.App.fireEvent(). We get around this by having our web application send JSON objects down to our app, and we then use that data to build HTML in the client.

In a quick test, I was able to get swipe events. It did have the unfortunate side effect of preventing scrolling in my webview, though.

— answered 11 months ago by Jason Priebe
answer permalink
1 Comment
  • Could you share your test code, I am interested to see what properties you were passing into the web view constructor. I am loading with the following which seems to fail with an external URL, using Google here by way of example:

    var self = Ti.UI.createWebView({
        url:"http://www.google.com?_nonce=" + Date.now(),
        showScrollbars: false,
        enableZoomControls: false,
        willHandleTouches: false,
        pluginState: Titanium.UI.Android.WEBVIEW_PLUGINS_ON
    });
    self.addEventListener('swipe', function(msg) {
        Ti.API.info("Swiped!!");
    });
    self.addEventListener('longpress', function(msg) {
        Ti.API.info("Long Press!!");
    });

    — commented 11 months ago by Andrew Rutter

Just whipped up a simple example:

var w = Ti.UI.createWindow ({});
 
var markup = '<html><head><title>test</title></head><body>test</body></html>';
 
var wv = Ti.UI.createWebView({
    html: markup, 
    scalesPagesToFit: true, 
    top: 0, left: 0, right: 0, bottom: 0,
    enableZoomControls: false,
    backgroundColor: '#fff'
});
 
wv.addEventListener ('swipe', function (e) {
    Ti.API.debug ('[swipe]');
});
 
w.add (wv);
 
w.open ();
I get swipe events. It also works with an external URL:
var w = Ti.UI.createWindow ({});
 
var markup = '<html><head><title>test</title></head><body>test</body></html>';
 
var wv = Ti.UI.createWebView({
    //html: markup,
    url: 'http://www.google.com/', 
    scalesPagesToFit: true, 
    top: 0, left: 0, right: 0, bottom: 0,
    enableZoomControls: false,
    backgroundColor: '#fff'
});
 
wv.addEventListener ('swipe', function (e) {
    Ti.API.debug ('[swipe]');
});
 
w.add (wv);
 
w.open ();
All this on iphone simulator. Haven't tried Android.

— answered 11 months ago by Jason Priebe
answer permalink
1 Comment
  • Note that I just grabbed my webview parameters from a larger app. I don't know that scalesPagesToFit or enableZoomControls are relevant.

    But if I had to guess, I would think that your use of willHandleTouches might have something to do with your problems.

    — commented 11 months ago by Jason Priebe

Your Answer

Think you can help? Login to answer this question!