FITC events. For digital creators.
Save 10% off ANY FITC event with discount code 'slideshare'
See our upcoming events at www.fitc.ca
Web, Native iOS and Native Android with One Ember.js App
with Alexander Blom
OVERVIEW
Many companies maintain a separate repo for web and native mobile applications, and sometimes yet another for mobile web. Historically you may hear that ‘wrapped applications’ are slower and choppy. This is no longer the case – if your application is structured correctly.
By using Ember.js with Cordova, it is possible to have a single code base powering all four (desktop web, mobile web, native iOS and native Android). Outside of the immediate cost/programming time savings, this technique enables you to build future iterations faster and stop the out of sync issues plaguing many code bases (e.g. the Android app has different features to iOS).
OBJECTIVE
Learn how to write a single code base which works on all platforms without the presumed drawbacks.
TARGET AUDIENCE
Developers/managers working on one of the three mentioned platforms, and who wish to no longer maintain separate code bases for each platform.
ASSUMED AUDIENCE KNOWLEDGE
A general knowledge of how either backend, front-end or mobile applications are developed is helpful.
FIVE THINGS AUDIENCE MEMBERS WILL LEARN
How to build a single code base working on all platforms
What changes (if any) are required in the code base to achieve this
How to avoid common draw-backs of wrapped applications, such as perceived slowness
How to access native phone functions without muddling up the code base
How such applications are packaged and deployed
2. Who am I
• Programmer
• Started with Java/C;
• Mostly Ruby/Rails;
• Go;
• Ember for ~2.5 years;
3. Isle of Code
• Toronto based development;
• Focused on:
• Prototyping;
• Single sourcing mobile /w Ember.js & Cordova;
and
• A lot of beacon work.
4. Five things audience
members will learn
1. How to build a single code base working on all platforms
2. What changes (if any) are required in the code base to
achieve this
3. How to avoid common draw-backs of wrapped
applications, such as perceived slowness
4. How to access native phone functions without muddling
up the code base
5. How such applications are packaged and deployed
5. Contents
• 1: What are hybrid apps?;
• 2: Our tools (Cordova, Ember & Good
Programming);
• 3: Make it go zoom;
17. What is Cordova?
• Apache Cordova is a platform for building native
mobile applications using HTML, CSS and
JavaScript
• https://cordova.apache.org/
• "Cordova" refers to the street the office was on
when the PhoneGap project first began
38. Manage Reflows
• “Reflow is the process by which the geometry of the
layout engine's formatting objects are computed. The
HTML formatting objects are called frames: a frame
corresponds to the geometric information for (roughly) a
single element in the content model; the frames are
arranged into a hierarchy that parallels the containment
hierarchy in the content model. A frame is rectangular,
with width, height, and an offset from the parent frame
that contains it.”
• http://www-archive.mozilla.org/newlayout/doc/
reflow.html
39. What causes Reflow?
• Resizing the browser window;
• using JavaScript methods involving computed
styles;
• adding or removing elements from the DOM; and
• changing an element's classes.
• https://developers.google.com/speed/articles/
reflow
42. Best Practices for avoiding
Reflow
1. Avoid setting multiple inline styles; avoid setting styles individually.
2. Use class names of elements, and do so as low in the DOM tree as possible.
3. Batch your DOM changes and perform them offline;
4. Avoid computing styles too often. If you must then cache those values.
5. Apply animations with position: fixed or absolute so it doesn’t affect the layout of other elements.
6. Avoid table layouts, they trigger more reflows than block layouts because multiple passes must be made over
the elements.
7. Reduce unnecessary DOM depth. Changes at one level in the DOM tree can cause changes at every level of
the tree - all the way up to the root, and all the the way down into the children of the modified node. This leads
to more time being spent performing reflow.
8. Minimize CSS rules and remove unused CSS rules.
9. If you make complex rendering changes such as animations, do so out of the flow. Use position-absolute or
position-fixed to accomplish this.
10.Avoid unnecessary complex CSS selectors - descendant selectors in particular.
http://stage.docs.phonegap.com/tutorials/optimize/03-min-reflows/
53. Canvas
• Choppy and deal breaking. This is common when
working with DOM;
• Need to move to Canvas;
• ~16ms target for animations, DOM can’t do this;