Designing True Cross-Platform Apps
Transcript of Designing True Cross-Platform Apps
Isle of Code
• Toronto + Chicago based development;
• Focused on Ember/Cordova;
Our Goal
• After a preamble;
• Use a single Ember app, and render desktop + mobile;
• Re-use the same Ember App for native applications;
• Using one code base for multiple platforms;
• vs. building custom code bases for each platform;
• Also handle mobile desktop/web sizing;
Wrapped Apps are everywhere
ember-cordovahttps://github.com/isleofcode/ember-cordova
Good Code == Good Hybrid
• Much of making effective mobile is simply writing good code.
• Desktops let us be lazier;
WKWebView
A note on deviceready
• You probably need to use it for any custom initializers;
• Has special handling. Even if you register the handler after deviceready fires, it will still be triggered.
Smoke & Mirrorshttps://github.com/runspired/smoke-and-mirrors
Flexihttps://github.com/runspired/flexi
Responsive v Fluid
• Bootstrap's .col-md-push-* and .col-md-pull-* classes are classic examples of using reflow design. Reflow utilizes floats and positioning to re-arrange portions of your DOM (in this case columns) for different viewport sizes. Reflow includes the use of classes like .offset-xs-6 to adjust margins and spacing.
• Reorder design is similar to reflow, but it accomplished by using the CSS order property to alter the position of items displayed using flexbox for layout. Reorder is "cleaner" than reflow, but both suffer from significant browser layout and paint time performance issues
• http://blog.isleofcode.com/modern-responsive-design/
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
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
Use CSS Transforms
visibility:hidden
<link href="disabled.css" rel="stylesheet" disabled>
• often end up downloading 2-3 sets of assets;
TouchBase
Standard Ember Structure
Standard Ember Structure
Taps
• Tap targets should be ~48px;
Hammer Example
Our components are the same
• We can re-use the same logic, routes & components. The templates are only visually different;
Media Queries
media queries
Media Queries
• # of different css files matter?
• # of media-queries matter?
• Inline vs separate?
• http://aaronjensen.github.io/media_query_test/
Problems
• Expensive reflow;
• Code gets confusing & hard to follow quickly;
• Can’t do anything complex;
Same Problems
Problems• Still hard to maintain;
• Canonically don’t know where to find mobile vs desktop;
• Components either need classes, or containers need selective classes;
• We’re introducing a lot of complexity that is not needed;
• "fluid" only understands viewport boundaries, but often needs to know about the boundaries of some smaller container
• "reveal" slows down renders by weighing down the DOM tree
• "reflow" and "reorder" cause expensive layouts and paints.
• "reveal", "reflow", and "reorder" can be hard to see and reason about.
• "restructuring" is just as messy, and likely less performant.
• layout CSS you can't see makes maintenance hard and adds a taxing mental overhead to every project developer.
• layout CSS you can see (via layout classes) is overly verbose, and often difficult to wade through.
When looking at just the layout, it differs the most.
Layouts change. Components are fluid.
Flexi
desktop.hbs
mobile.hbs
• Ditches reflow & reorder patterns;
Already easier to follow
Elements• screen: 100% width, min-height of 100vh;
• page: 100vw & 100 vh;
• fill / fill block: fills parent;
• centered:
• box: grows to match other items, but not container;
• hbox/vbox: fills remaining space, align horizontal/vertical
For Emberists: sustain
Further Optimization
• In guaranteed mobile only environments, try not to download desktop assets;
• Images can be resized per platform;
• Use fingerprinting to expire older assets;