web, native ios and native android with one ember.js app

58
Hybrid Apps with Ember @alexblom [email protected]

Upload: fitc

Post on 22-Jan-2017

6.135 views

Category:

Internet


2 download

TRANSCRIPT

Page 1: Web, Native iOS and Native Android with One Ember.js App

Hybrid Apps with Ember

@alexblom [email protected]

Page 2: Web, Native iOS and Native Android with One Ember.js App

Who am I

• Programmer

• Started with Java/C;

• Mostly Ruby/Rails;

• Go;

• Ember for ~2.5 years;

Page 3: Web, Native iOS and Native Android with One Ember.js App

Isle of Code• Toronto based development;

• Focused on:

• Prototyping;

• Single sourcing mobile /w Ember.js & Cordova; and

• A lot of beacon work.

Page 4: Web, Native iOS and Native Android with One Ember.js App

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

Page 5: Web, Native iOS and Native Android with One Ember.js App

Contents

• 1: What are hybrid apps?;

• 2: Our tools (Cordova, Ember & Good Programming);

• 3: Make it go zoom;

Page 6: Web, Native iOS and Native Android with One Ember.js App

1 - What are hybrid apps

Page 7: Web, Native iOS and Native Android with One Ember.js App

• Using one code base for multiple platforms;

• vs. building custom code bases for each platform;

Page 8: Web, Native iOS and Native Android with One Ember.js App

Wrapped Apps are everywhere

Page 9: Web, Native iOS and Native Android with One Ember.js App

Less cost of building

Page 10: Web, Native iOS and Native Android with One Ember.js App

Re-use app for web

Page 11: Web, Native iOS and Native Android with One Ember.js App

Less cost to add new features

Page 12: Web, Native iOS and Native Android with One Ember.js App

No out of sync experiences

Page 13: Web, Native iOS and Native Android with One Ember.js App

How important is complexity?

Page 14: Web, Native iOS and Native Android with One Ember.js App

How easy is it for you to find engineers?

Page 15: Web, Native iOS and Native Android with One Ember.js App

“The biggest mistake we’ve made as a company is betting on HTML5 over native”

Mark Zuckerberg, 2012

Page 16: Web, Native iOS and Native Android with One Ember.js App

2 - Our Tools

Page 17: Web, Native iOS and Native Android with One Ember.js App

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

Page 18: Web, Native iOS and Native Android with One Ember.js App

Cordova vs Phonegap

Page 19: Web, Native iOS and Native Android with One Ember.js App

UIWebView

Page 20: Web, Native iOS and Native Android with One Ember.js App

(mostly) consistent API’s

Page 21: Web, Native iOS and Native Android with One Ember.js App
Page 22: Web, Native iOS and Native Android with One Ember.js App

The Ember way is not about Ember

Page 23: Web, Native iOS and Native Android with One Ember.js App

ember-cli-cordova

Page 24: Web, Native iOS and Native Android with One Ember.js App

Cordova/Ember is easier now

• Process has come a long way

Page 25: Web, Native iOS and Native Android with One Ember.js App

Bind Cordova Service

https://github.com/isleofcode/ember-cli-cordova

Page 26: Web, Native iOS and Native Android with One Ember.js App

Livereload

Page 27: Web, Native iOS and Native Android with One Ember.js App

3 - Make it go Zoom

Page 28: Web, Native iOS and Native Android with One Ember.js App

Good Code == Good Hybrid

• Much of making effective mobile is simply writing good code.

• Desktops let us be lazier;

Page 29: Web, Native iOS and Native Android with One Ember.js App

Cordova is not native

Page 30: Web, Native iOS and Native Android with One Ember.js App

Cordova is not native

Page 31: Web, Native iOS and Native Android with One Ember.js App

<preference name="webviewbounce" value="false" />

Page 32: Web, Native iOS and Native Android with One Ember.js App

Touch Events http://hammerjs.github.io

Page 33: Web, Native iOS and Native Android with One Ember.js App

Hammer Example

Page 34: Web, Native iOS and Native Android with One Ember.js App

Ember Gestures

https://github.com/runspired/ember-gestures

Page 35: Web, Native iOS and Native Android with One Ember.js App

Ghost Clicks

Page 36: Web, Native iOS and Native Android with One Ember.js App

Ember Hack

Page 37: Web, Native iOS and Native Android with One Ember.js App

Manage Reflows

Page 38: Web, Native iOS and Native Android with One Ember.js App

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

Page 39: Web, Native iOS and Native Android with One Ember.js App

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

Page 40: Web, Native iOS and Native Android with One Ember.js App

Use CSS Transforms

Page 41: Web, Native iOS and Native Android with One Ember.js App

visibility:hidden

Page 42: Web, Native iOS and Native Android with One Ember.js App

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/

Page 43: Web, Native iOS and Native Android with One Ember.js App

-webkit-tap-highlight-color:rgba(0,0,0,0);

Page 44: Web, Native iOS and Native Android with One Ember.js App

Understand Viewport

Android ViewportiOS 7+ Viewport

Page 45: Web, Native iOS and Native Android with One Ember.js App

ionic Keyboard• cordova.plugins.Keyboard.isVisible

• cordova.plugins.Keyboard.hideKeyboardAccessoryBar

• cordova.plugins.Keyboard.close

• cordova.plugins.Keyboard.disableScroll

• cordova.plugins.Keyboard.show

• https://github.com/driftyco/ionic-plugin-keyboard

Page 46: Web, Native iOS and Native Android with One Ember.js App

Infinite Scrolling

• Smoke & Mirrors: https://github.com/runspired/smoke-and-mirrors

• Ember ListView: https://github.com/emberjs/list-view

• Ember Cloaking: https://github.com/eviltrout/ember-cloaking

Page 47: Web, Native iOS and Native Android with One Ember.js App

Occlusion

Page 48: Web, Native iOS and Native Android with One Ember.js App

http://runspired.github.io/smoke-and-mirrors/#/examples/dbmon

Page 49: Web, Native iOS and Native Android with One Ember.js App

Animations

Page 50: Web, Native iOS and Native Android with One Ember.js App
Page 51: Web, Native iOS and Native Android with One Ember.js App

Animations - Velocity

Page 52: Web, Native iOS and Native Android with One Ember.js App
Page 53: Web, Native iOS and Native Android with One Ember.js App

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;

Page 54: Web, Native iOS and Native Android with One Ember.js App
Page 55: Web, Native iOS and Native Android with One Ember.js App

Mirage https://github.com/samselikoff/ember-cli-mirage

Page 56: Web, Native iOS and Native Android with One Ember.js App

Liquid Fire

http://ef4.github.io/liquid-fire/

Page 57: Web, Native iOS and Native Android with One Ember.js App

Crosswalk https://crosswalk-project.org/

Page 58: Web, Native iOS and Native Android with One Ember.js App

Hybrid Apps with Ember

@alexblom [email protected]