Fake It ‘ti
You Make
creating mobile apps th
feel like native apps
Fake It ‘ti
You Make
creating mobile apps th
feel like native apps
@snookca
“increíble”
What I won’t be
talking about.
Q3 Smartphone
     Smartphone             Featurephone




                               43%
    57%




          Q3 2011 Source: Nielsen
Q3 OS Market
  iOS   Android      BlackBerry          Windows   Other




                  7% 4%
                                   28%
          18%




                     43%


                      Source: Nielsen
US Mobile Browser
           iOS          Android             Opera            BlackBerry               Other




                                       5%

                         26%
                                                              39%

                           2%


                                     28%

 Q3 2011 Mobile Browser Stats http://www.quirksmode.org/blog/archives/2011/10/q3_2011_mobile_1.html
Brazil Mobile
    iOS           Opera             Nokia            Android             BlackBerry               Other


                                             3%


                          34%                             25%



                             1%
                                                  29%
                         8%

  Q3 2011 Mobile Browser Stats http://www.quirksmode.org/blog/archives/2011/10/q3_2011_mobile_1.html
What are people
                        iPhone                iPad                Android
                        RIM                   Other




                              14%
                                                       30%
                    12%



                          23%
                                                 21%


   State of the Apps Industry 2010 and 2009 Surveys; DIGIDAY, Stifel Nicolaus, Millenial Media
75% developing for
 iOS and Android
Mobile Safari
Mobile Safari
Local Storage
Mobile Safari
Local Storage
CSS3 features like transforms, transitions and
animations
Mobile Safari
Local Storage
CSS3 features like transforms, transitions and
animations
Geolocation
Mobile Safari
Local Storage
CSS3 features like transforms, transitions and
animations
Geolocation
HTML5 forms support for search, number and
email field types.
Mobile Safari
Local Storage
CSS3 features like transforms, transitions and
animations
Geolocation
HTML5 forms support for search, number and
email field types.
Access to some hardware acceleration
Mobile Safari
Local Storage
CSS3 features like transforms, transitions and
animations
Geolocation
HTML5 forms support for search, number and
email field types.
Access to some hardware acceleration
SVG
Mobile Safari
Local Storage
CSS3 features like transforms, transitions and
animations
Geolocation
HTML5 forms support for search, number and
email field types.
Access to some hardware acceleration
SVG
  older versions of Android don’t support it
http://snk.ms/1o
Why Web over
Why Web over
don’t need access to device APIs
Why Web over
don’t need access to device APIs
 most apps don’t
Why Web over
don’t need access to device APIs
 most apps don’t
need quick iteration without app store approval
process
Code
http://www.flickr.com/photos/bike/4299152140/
Detecting within
if(window.navigator.standalone) {
    // run code in “app” mode
} else {
    // run code in mobile safari mode
}
Home Screen Icon
<link rel="apple-touch-icon" href="images/icon.png">
<link rel="apple-touch-icon" sizes="72x72"
href="touch-icon-ipad.png">
<link rel="apple-touch-icon" sizes="114x114"
href="touch-icon-iphone4.png">


rel="apple-touch-icon-precomposed"
Start-up Image
<link rel="apple-touch-startup-image" href="/
startup.png">
Start-up Image
No apparent support for horizontal image
When loading in landscape, the status bar
creates a gap to one edge of the loading screen.
Going “Full screen”
<meta name="apple-mobile-web-app-capable"
content="yes">
Status Bar
<meta name="apple-mobile-web-app-status-
bar-style" content="black">


default
black-translucent
Viewport
<meta name="viewport" content="width=device-
width">
<meta name="viewport" content="width=590">
<meta name="viewport" content="initial-scale=
1.0">
<meta name="viewport" content="initial-scale=
2.3, user-scalable=no">
You don’t need a
  framework!
HTML Prototypes
HTMLElement.prototype.__defineSetter__("ontap",
function(func){ });


document.getElementById('keypad').ontap =
function(){
     alert('just the keypad');
};
HTML Prototypes
HTMLElement.prototype.switchClass =
function(fromClass, toClass){
  if(this.className == fromClass) {
       this.className = toClass;
  } else {
       this.className = fromClass;
  }
 
}


document.getElementById('spinner-
shell').switchClass('collapsed', 'expanded');
querySelector(All)
document.querySelector('.active'); // one el
document.querySelectorAll('.active'); // all
BUT I WANT
function $(selector){
    return document.querySelectorAll(selector);
}


$('#myelement p');
Looping
[3,2,1].forEach(function(itm, idx){
     console.log(itm, idx); // 3,0 | 2,1 | 1,2
})
Local Storage
JSON.parse(localStorage.getItem('pdata'));
localStorage.setItem('pdata', JSON.stringify(items));
Geolocation
if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(success, error);
} else {
  error('not supported');
}
function success(pos) {
    console.log( pos.coords.longitude, pos.coords.latitude );
}
Use CSS for UI
#units div:nth-child(2) { -webkit-transform:rotate(45deg); }
#units div:nth-child(3) { -webkit-transform:rotate(90deg); }
#units div:nth-child(4) { -webkit-transform:rotate(135deg); }
#units div:nth-child(5) { -webkit-transform:rotate(180deg); }
#units div:nth-child(6) { -webkit-transform:rotate(225deg); }
#units div:nth-child(7) { -webkit-transform:rotate(270deg); }
#units div:nth-child(8) { -webkit-transform:rotate(315deg); }
Use Transitions
-webkit-transition-property: -webkit-transform;
-webkit-transition-duration: .5s;


el.style.webkitTransform = 'rotate('+pos+'deg)';
Webkit Animations
@-webkit-keyframes {
    0% { background-position-y: 0; }
    100% { background-position-y: -100%; }
}


body {
    background-image:url("canvas-crumpled.jpeg");
    -webkit-animation: bg 3s linear infinite;
}
Touch vs Click
Using touch events can make the app feel faster
than click events.
You can customize tap hightlight colour
Touch vs Click
-webkit-tap-highlight-color:rgba(200,0,0,0.4);
Input Features
<input autocorrect="on"> <!-- or “off” -->
<input placeholder="Example Text">
<input type="email">
<input type="url">
<input type="number">
<input type="search">
Locking
window.addEventListener('orientationchange', function(){
 if(window.orientation == -90) {
   document.getElementById('orient').className = 'orientright';
 }
 if(window.orientation == 90) {
   document.getElementById('orient').className = 'orientleft';
 }
 if(window.orientation == 0) {
   document.getElementById('orient').className = '';
 }
}, true);
Locking
.orientleft #shell {
 -webkit-transform: rotate(-90deg);
 -webkit-transform-origin:160px 160px;
}


.orientright #shell {
 -webkit-transform: rotate(90deg);
 -webkit-transform-origin:230px 230px;
}
Locking
Performance
Use CSS instead of JavaScript for Animations
 use CSS Transitions
 use CSS Animations
 use 2D and 3D transforms to force hardware
 acceleration
Hardware
2D and 3D transforms may be hardware
accelerated
use translateX/Y instead of top/left
use rotateX(0) to push items with heavy CSS to
use hardware acceleration
  (it’s like IE’s zoom:1 to force hasLayout)
Testing
Testing
iOS Simulator is fast but not entirely accurate
Testing
iOS Simulator is fast but not entirely accurate
Android emulator is slow but accurate
Testing
iOS Simulator is fast but not entirely accurate
Android emulator is slow but accurate
Emulators handy for testing multiple OS versions
Testing
iOS Simulator is fast but not entirely accurate
Android emulator is slow but accurate
Emulators handy for testing multiple OS versions

Best to test on device
Testing
iOS Simulator is fast but not entirely accurate
Android emulator is slow but accurate
Emulators handy for testing multiple OS versions

Best to test on device
For multi-touch testing, must do on the device.
Testing
iOS Simulator is fast but not entirely accurate
Android emulator is slow but accurate
Emulators handy for testing multiple OS versions

Best to test on device
For multi-touch testing, must do on the device.
  pinch/zoom, rotate possible in iOS simulator
Framew
http://www.flickr.com/photos/nocallerid_man/3638360458/
Mobile Web
jQTouch
XUI.js
jQuery Mobile
Dojo Mobile
Sencha Touch
jQTouch
Targetted for iOS
Makes web app feel like native app with controls
and list views
http://jqtouch.com/
XUI.JS
x$('#btn').click( function (e) {
     x$('#msg').html('¡Hola!');
})
XUI.JS
clean, familiar, chaining syntax.
super tiny 10.4kb footprint (4.2kb gzipped).
targeted builds for webkit, ie mobile, and
blackberry
Dojo Mobile
Designed for iPhone, Android
Includes touch and gesture support
Support for native-style widgets
Can create webkit-only builds
http://dojotoolkit.org/features/mobile
jQuery Mobile
Designed for iPhone, Android, webOS
 plus bada, Meego, Windows Mobile and more
Includes touch and gesture support
http://jquerymobile.com/
Sencha Touch
Designed for iPhone and Android
Includes enhanced touch events
Allows for rapid development
http://www.sencha.com/products/touch/
Exampl
http://www.flickr.com/photos/mollymazilu/5827249387/
Could be a Web
Calculators (e.g. CalcBot)
Twitter
Productivity Apps (e.g. Things.app)
Recipe Databases (e.g. Epicurious)
Weather Apps
UI Sketcher
Could be a Web
Words With Friends/Scrabble
Angry Birds
 http://chrome.angrybirds.com/
Canabalt
Bejeweled
Ramp Champ
37Signals: Chalk
37Signals: Chalk
http://chalk.37signals.com/
Shkrubbel
https://github.com/kitt/shkrubbel
The Two Hour App
Frameworks allow for rapid development
Used jQTouch
Used localStorage
http://pushups.snook.ca/
ConvertBot
http://snook.ca/testing/convertbot/
Going
Why Native over
Access to native hardware and other applications
Camera, Address Book, Filesystem
Streamlined Revenue Process
Meet in the middle
Many apps take advantage of native WebView to
load application components from remote server
 allows for iteration of some app components
 without requiring complete approval process
 from app store
PhoneGap and
Titanium Mobile targets iPhone and Android
PhoneGap targets iPhone, Android, Palm,
Symbian and Blackberry.
http://www.appcelerator.com/
http://www.phonegap.com/
Have fun! /
http://www.flickr.com/photos/sbluerock/364123380/
@snookca
http://snook.ca

Jonathan snook - fake-it