Fear and Loathing All The Way Down

Hybrid Mobile Development

Alexander Tchitchigin

Positive Technologies

Background

  • C/C++
  • Java/C#/Python
  • Haskell/Coq
  • KFU & Innopolis University
  • Static Analysis

MixDress

MixDress

The First Rule of Hybrid Mobile App Development

Don't

Apache Cordova

  • Just Works
  • Signing and Everything
  • Plugins
  • Crosswalk is Closed

Apache Cordova

  • Java 8 - Really?
  • Paths to Assets?

Web Platform

My Ass!

Reading Files

const files = this.refs.fileInput.files;
if (!files.length) return;

for (let i = 0; i < files.length; i++) {
  const reader = new FileReader(),
        image  = new Image();
  
  image.onload = () => resizeAndStore(image);
  
  reader.onloadend = () => image.src = reader.result;
  reader.readAsDataURL(files[i]);
}

Which Reminds Me...

var xhr    = new XMLHttpRequest(),
    method = "GET",
    url    = "https://developer.mozilla.org/";

xhr.open(method, url, true);
xhr.onreadystatechange = function () {
  if(xhr.readyState === 4 && xhr.status === 200) {
    console.log(xhr.responseText);
  }
};
xhr.send();

Speaking of Promises

Cancellation, anyone?

And Images

Browsers handle images, right?

A-ha...

const canvas1 = document.createElement('canvas'),
      canvas2 = document.createElement('canvas'),
      ctx1    = canvas1.getContext('2d');
let ratio = 1;

if (bitmap.width > bitmap.height) {
  if (bitmap.width > lib.maxImgWidth)
    ratio = lib.maxImgWidth / bitmap.width;
} else {
  if (bitmap.height > lib.maxImgHeight)
    ratio = lib.maxImgHeight / bitmap.height;
}

canvas1.height = bitmap.height;
canvas1.width  = bitmap.width;
ctx1.drawImage(bitmap, 0, 0);
  
canvas2.height = bitmap.height * ratio;
canvas2.width  = bitmap.width * ratio;
  
pica.resize(canvas1, canvas2)
  .then(result => pica.toBlob(result, 'image/jpeg', 90))

Performance

You're gonna need it

PWA?

Other Real-World Concerns

  • Advertisements
  • Analytics
  • Crash Analytics
  • Localization?

Libraries

  • PReact + PReact Router
  • Unistore + Immer
  • PouchDB
  • Keen.io -> Mixpanel -> Amplitude

Hurdles

  • Webpack

  • LESS/SASS

  • NPM/Bower

Thanks for Listening!

Questions?

Hybrid Mobile App Development

By Alexander Letov

Hybrid Mobile App Development

Problems and (some) solutions developing hybrid mobile apps with Apache Cordova.

  • 94