native-apps-on-steroids-slides



native-apps-on-steroids-slides

1 1


native-apps-on-steroids-slides

Native Apps on Steroids

On Github thedotmack / native-apps-on-steroids-slides

Native Apps on Steroids

Building super-polished native apps with HTML, CSS, JS, and Steroids

Download the AppGyver Scanner App

Going to show you guys a magic trick Search AppGyver Scanner in the App Store or Google Play store

About Me

  • Founder of Dem Internets
  • I've been coding like a boss since 1999
  • I have 2 cats that help me be good at the internets.
       
  • I work with awesome startups and agencies to help them build really cool stuff.

Native Apps Are The Future

- PERFORMANCE!

Native apps are hard.

Objectve C / Swift / Java Steep learning curve for web developers

HTML IS EASY!

Apache Cordova (PhoneGap)

<h1>INSERT APP HERE</h1>

- Apache Cordova (Formerly PhoneGap) - Build native mobile apps using HTML, CSS and JavaScript - Single page apps in a WebView

What is a WebView?

  • A WebView is a browser instance inside an app.
  • Apache Cordova gives you a single WebView and allows you to create your HTML, CSS, and JavaScript within that view.
  • Usually the user interface is simulated with HTML, CSS, and JavaScript (ionic, ratchet)

This feels wonky.

Well Billy, that's because it is.

Trying to replicate the performance and stability of native apps by just using HTML, CSS, and JavaScript, is an almost insurmountable task.

- Performance - Stability

What is Steroids?

  • Steroids is a mobile app development framework that allows you to build cross-platform mobile apps using HTML5, CSS, and JavaScript.
  • It's based on Apache Cordova (Phonegap) but with a few key differences.

Why is Steroids Cool?

Multiple WebViews with Native Transitions

Steroids handles all the hard stuff for you.

Cross-platform from the get go.

- Uses Multiples WebViews - Uses Native UI elements - Title Bar - Tabs Bar - Drawers- Is a much smoother app experience - Steroids' magical command line interface - Compile, test and deploy right from the command line - iOS and Android from the get go - Deploy on multiple platforms from a single codebase

InstaTim

   

http://github.com/thedotmack/instatim

Open Quicktime with Phone Plugged In

Installing Steroids

AppGyver offers a web-based wizard to help you install Steroids.

http://academy.appgyver.com/installwizard

Once you have the prerequisites installed, type this into your terminal window:

$ npm install steroids -g

To check that everything is working correctly, type the following into your terminal:

$ steroids login
Their wizard helps you install the prereqs - Git - Python - XCode + Command-line tools - Node / NVM / NPM

Creating Your App

Steroids comes packed with some nifty command-line tools that make app development a breeze.

steroids create

steroids connect

steroids deploy

steroids create

To create your base Steroids app, type the following into your terminal window:

$ steroids create projectName

This creates a new folder called projectName with your base app inside.

Demo in terminal

steroids connect

In your project's folder, type:

$ steroids connect

The Steroids server will start running and a browser window will open a page displaying a QR code that allows you to test your app on iOS and Android using the Scanner app!

  • Must be on the same network for the scanner to load the app
Demo in terminal

steroids deploy

Type the following into a terminal window in your project's root:

$ steroids deploy

A new QR code will open in your browser. Your app is now hosted on Steroids' Cloud Platform and anyone with the AppGyver Scanner app can scan the QR code to test the app on their device.

- Demo in terminal - Can configure and download builds for the App Store and Google Play using AppGyver's cloud platform

Developing your app

  • Using Native UI Features
  • Navigating in between WebViews
  • Sharing data between WebViews

App Structure and Frameworks

     

- Build your app however you want - Using the tools you're already comfortable with - jQuery - Angular - ionic (included already) - Bootstrap - Ratchet (Purely Mobile Bootstrap)

Suggested File Structure

your_project/
└── app/
    ├── controllers/
    |   └── photo_gallery.js     
    ├── models/
    |   └── photo_gallery.js     
    └── views/
        ├── photo_gallery/
        |   ├── index.html
        |   ├── single.html
        |   └── feed.html
        └── layouts/
            └── photo_gallery.html

Steroids will take the app folder and compile it so you can keep DRY (Don't repeat yourself)

- Set up in a model / view / controller way - Steroids builds these files for you

Bower for the win

Install cool packages using Bower if you'd like. I'm installing jQuery!

$ bower install jquery --save
Bower is already set up for your project, you can use it to manage whatever front end packages you'd like.

The www and dist folders

The www folder is where all of your app's assets live.

When Steroids builds your app, it copies everything from www over to dist, as well as the compiled contents of your app folder.

application.coffee

For an explanation of the steroids.config properties, see the guide at
http://guides.appgyver.com/steroids/guides/project_configuration/config-application-coffee/

Setting your start location

Let's change...

steroids.config.location = "http://localhost/index.html"

to...

steroids.config.location = 
       "http://localhost/views/photo_gallery/index.html"

Don't actually put a line break in the location string. This is for the slides, dude.

- Changing this to use the MVC structure we set up

Using Native UI Features

Native Navigation Bar

In your current view's controller file app/controllers/photo_gallery.js

// Display the native navigation bar with 
// the title "Photo Gallery"
steroids.view.navigationBar.show("Photo Gallery");

Native Tab Bar

Set in config/application.coffee

steroids.config.tabBar.enabled = true
steroids.config.tabBar.tabs = [
  {
    title: "Gallery"
    icon: "icons/photos@2x.png"
    location: "http://localhost/views/photo_gallery/index.html"
  },
  {
    title: "Feed"
    icon: "icons/feed@2x.png"
    location: "http://localhost/views/photo_gallery/feed.html"
  }
]

Navigating in between WebViews

In app/controllers/photo_gallery.js

$('#thumbnails img').on('click',function(){

    var webView = new steroids.views.WebView(
                      '/views/photo_gallery/single.html'
                  );

    steroids.layers.push(webView);

});

Preloading WebViews

In app/controllers/photo_gallery.js

var singleView = new steroids.views.WebView({
    location:   "/views/photo_gallery/single.html",
    id:         "singleView"
});
singleView.preload();
This is so the WebView exists for the data we're about to pass it.

Sharing Data between WebViews

In app/controllers/photo_gallery.js

$('#thumbnails img').on('click',function(){
    message = {
        recipient:  'singleView',
        src:        $(this).attr('src'),
        title:      $(this).attr('alt')
    }
    window.postMessage(message);
    steroids.layers.push(singleView);
});
- Uses the HTML5 postmessage API. - send the message in one webview - listening for that message in our target webview

Listening for Shared Data in Your Target WebView

In app/views/photo_gallery/single.html

function messageReceived(event) {
    // check that the message is intended for us
    if (event.data.recipient == "singleView") {
        $('#single .card').html(
            '<img src="' + event.data.src + 
            '"><h3>' + event.data.title + '</h3>'
        );
    }
}
window.addEventListener("message", messageReceived);

Accessing hardware with Cordova APIs

function getAcceleration() {
  navigator.accelerometer.getCurrentAcceleration(
  accelerometerOnSuccess, accelerometerOnError)
}

function accelerometerOnSuccess(acceleration) {
  acceleration_data.innerHTML =
    "x: " + acceleration.x + "<br>" +
    "y: " + acceleration.y + "<br>" +
    "z: " + acceleration.z + "<br>" +
    "timestamp: " + acceleration.timestamp
}

function accelerometerOnError(error) {
  alert("Accelerometer error: " + JSON.stringify(error));
}

http://docs.appgyver.com/en/stable/index.html

- Access cordova apis - Accelerometer, Camera, Contacts, Geolocation and more - All documented on Steroids' site

Accessing Your Device's Camera

function getPicture() {
    navigator.camera.getPicture(onSuccess, onFail, {
        quality         : 50,
        destinationType : Camera.DestinationType.DATA_URL
    });
}

function onSuccess(imageData) {
    var image = document.getElementById('myImage');
    image.src = "data:image/jpeg;base64," + imageData;
}

function onFail(message) {
    alert('Failed because: ' + message);
}

http://docs.appgyver.com/en/stable/cordova_camera_camera.md.html

Basically just functions with a success and error callback

Testing your app

steroids simulator (iOS Only)

Type simulator in to the Steroids terminal window while steroids connect is running, and the iOS Simulator will open.

You can then open up Safari and inspect your app's WebViews using Safari's Developer Tools!

https://x.appgyver.com/categories/2-tooling/contents/60-debugging-with-the-safari-web-inspector

Building your app

steroids deploy

+

https://cloud.appgyver.com/applications

At the AppGyver Cloud Services page, you can configure builds for iOS and Android, ad-hoc and production.

steroids generate tutorial

  • begin – The very basics of AppGyver Steroids, start here.
  • steroids – Basics of Steroids Native UI enhancements.
  • controllers – Basics of Controllers (requires the steroids tutorial to be generated first)

steroids generate example

  • accelerometer – Access the device's accelerometer.
  • animation – Using native animations without moving to another document (iOS-only).
  • audio – Play back audio files through Cordova's Media API.
  • compass – Access the device's compass.
  • device – Access the device properties.
  • drumMachine – A simple drum machine.
  • geolocation – Access the device's geolocation data.
  • modal – Using the modal window.
  • notification – Access native notifications.
  • preload – Preload WebViews to have them available immediately.
  • storage – Access Cordova's SQL Storage API.

AppGyver Academy

https://x.appgyver.com/categories

Thank You!!!! <3 <3 XOXOXO 5EVER

Follow me on Twitter: @thedotmack

Follow my Cats on Instagram: @thedailytim