Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gotchas/bugs in development for WebKit on iOS or Android

I'm about to develop a major touch-enabled mobile WebKit application.

I'm looking for any hints or advices about things that differ from a standard desktop-based browser(s).

For example:

  • on iOS click events do not propagate upward to the body element over elements, except for some cases (links, inputs, elements with attached events, etc.).

  • Android WebKit does not emit events for multi-touch.

I know about these. Are there some other problems? Do you know about some list of known problems?

like image 373
tillda Avatar asked Jan 12 '11 14:01

tillda


3 Answers

I've found a few things out in my recent endeavors with the iPad.

1: Version 4.2 iOS has a bug where running too many document.getElementById('foo'); will cause the browser to lag, and thus not execute commands correctly. To remedy this you need to create variables to hold this information and only make the selection commands when needed. Version 4.3 of the iOS does fix this though, as I've tested it on my iPad.

2: When working with positioning, I have found that when creating your own video controller (for html5), if you try and resize the video container by using position: relative or position:absolute, you no longer will see a video, but a nice black screen (with sound!). In order to remedy this, simply target the parent frame and you're good to go.

3: If you're using iScroll be sure to put a timeout on having it load; especially if you have a few other javascripts on the page as even though the document has it loading when 'the page is loaded' via:

// Load iScroll when DOM content is ready.
document.addEventListener('DOMContentLoaded', loaded, false);

I've had this fail, and couldn't figure out for the life of me why my div wasn't sizing correctly showing me all elements but the last two and not scrolling. Instead I simply did a

$(function(){
   //other page loaded items to do
   //the iScroller init
   setTimeout('iScrollerInit();',200);
});

and it fixed the problem very quickly.

4: If you find your clicks aren't quite working correctly, I've found that many of the mobile SDK's out there are binding items on everything, making it difficult to achieve clicks to things normally you want. So to fix this you can do something like:

$("#yourId").unbind("click").click(function(){ 
    //what to do when clicked
});

and I've found this to work most brilliantly.

**UPDATE - Nov 2012 **: It's been a few years, and there is so much more to add to this so wanted to update the list a bit.

5: Javascript is expensive on a handful of devices STILL (December 2012). Doing things that manipulate the DOM generate a good deal of lag on devices and you should be really careful when doing these things. You'll want to make sure to test your Mobile Web pages in both Android older devices and iPhone older devices as from our metrics these are still well used devices.

6: If you are passing HTML to load in a web-view on a device (iPhone App or Android App) there are times when you will see almost a height 0. What you need to do is have your iPhone or Android app make a Javascript call on the actual page targeting a div to check the page offsetHeight which will then allow the webview height to be accurately set.

**UPDATE - Dec 2012 **: Few more awesome findings

7: I've found that when you target your divs for click events that mobile browsers will wait 300ms before firing the event, effectively creating a lag. They do this to confirm the click wasn't a double tap. in order to avoid this you can bind touchend events instead which will fire instantly!

Here's a bit of code

$(document).ready(function() {
    $('#element').bind('touchstart', function(event) {
        event.stopPropagation();
        event.preventDefault();
        $(this).toggleClass('hover_heading');
    });

    $('#element').bind('touchend', function(event) {
        event.preventDefault();
        $(this).toggleClass('hover_heading');
    });
});

Then once you see blinking happening over your items use this to remove that.

body * {
    -webkit-tap-highlight-color: rgba(0,0,0,0);  
}

Also if you want to check out an outstanding article google wrote on this you can view it here: - Creating Fast Buttons for Mobile Web Applications

**UPDATE - Feb 2013 **: Few more awesome findings

8: When versioning your CSS files and caching them with urls such as: mydomain.com/css/styles.css?v=123 (or something else), be careful on android 2.2 devices and earlier as this forces extremely strange behavior.

From my findings android will render this completely wrong, and force the html to even be messed up. THe best way when working with these older devices is sadly to change the actual file name.

Hopefully these findings help others as I've struggled through each of these problems for multiple hours scratching my head :)

like image 95
7 revs, 2 users 99% Avatar answered Nov 11 '22 15:11

7 revs, 2 users 99%


I don't know of a compiled list, but I can list a few:

  • SVG is not supported (currently) in Android, as it's been turned off. Support is coming in Honeycomb. In contrast, iOS has left the SVG support enabled and it seems to work nicely.
  • While both browsers support CSS3 opacity, make sure you thoroughly test any animations as they can be quite choppy for more complex graphics (especially with multiple layers of opacity.)
  • In my javascript, I typically listen for the "touchstart", "touchmove", or "touchend" events for the sake of speed (the "click" event typically elicits a noticeable lag) and granularity.
  • HTML5 features such as localStorage and the new audio and video tags seem to work well. However, on the iphone you can't autoplay audio or video, as the play event (and corresponding download) must be directly triggered by the user.
  • Transitions involving movement (changing x and y coordinates) are quite smooth. In contrast, transitions involving opacity can be quite choppy depending on the resources involved (sometimes you might have to use a sprite to get a smoother feel.)

Just some quick observations.

like image 6
AdamJonR Avatar answered Nov 11 '22 15:11

AdamJonR


I recently wrote a blog post about some of the cotchas with using an html5 framework - in my case Sencha Touch to build a native app wrapped in PhoneGap.

http://www.moneytoolkit.com/2011/05/the-problem-with-sencha-touch-and-phonegap/

like image 1
danmux Avatar answered Nov 11 '22 16:11

danmux