building mobile applications with ionic

51
Building Mobile Apps with Ionic An Introduction By Morris Singer ionic

Upload: morris-singer

Post on 05-Dec-2014

749 views

Category:

Software


0 download

DESCRIPTION

An introduction to mobile application development with Ionic and Cordova.

TRANSCRIPT

Page 1: Building Mobile Applications with Ionic

Building Mobile Apps with Ionic An Introduction By Morris Singer

ionic

Page 2: Building Mobile Applications with Ionic

WHO AM I• Senior Software Engineer

Cengage Learning

• Technical Cofounder & General CounselUnionConnect

• Sencha Touch (Two Years)• Angular.js and Node.js (One Year)• Ruby on Rails (Four Years)• Previously…

Page 3: Building Mobile Applications with Ionic

AGENDA

• Put Ionic in context • Make the case for Ionic • Review the Ionic technology stack • Explore some Ionic components • Q & A

Page 4: Building Mobile Applications with Ionic

WHAT’S IN A FRAMEWORKBehind the Design of a Framework Rests a Philosophy about the Roles of Javascript and HTML

ionic DOM Manipulation

JavaScript-CentricTwo-Way Data Binding

Page 5: Building Mobile Applications with Ionic

JUST RIGHT

Page 6: Building Mobile Applications with Ionic

JUST RIGHT

Page 7: Building Mobile Applications with Ionic

WHY IONIC Ionic Builds on Existing Technologies You Love

• Great JavaScript framework • Industry-standard webview • Cordova plugins • Best layout engine ever created • Slick UI components • Robust developer community

Page 8: Building Mobile Applications with Ionic

WHY IONIC Ionic Builds on Existing Technologies You Love

• Great JavaScript framework • Industry-standard webview • Cordova plugins • Best layout engine ever created • Slick UI components • Robust developer community

Page 9: Building Mobile Applications with Ionic

THE IONIC TECHNOLOGY STACK

Page 10: Building Mobile Applications with Ionic

THE IONIC TECHNOLOGY STACK

ngCordova

Page 11: Building Mobile Applications with Ionic

BUILT ON ANGULAR.JS Use Familiar Tools to Construct Out Your Application

Page 12: Building Mobile Applications with Ionic

Providersangular.service() angular.factory() angular.provider()

Controllersangular.controller()

Directivesangular.directive()

Templates<html></html>

BUILT ON ANGULAR.JS Use Familiar Tools to Construct Out Your Application

Page 13: Building Mobile Applications with Ionic

angular.module('ionicApp', ['ionic']) !.config(function ($stateProvider, $urlRouterProvider) { ! $stateProvider .state('menu', { abstract: 'true', templateUrl: 'templates/menu.html', controller: 'MenuCtrl' }) ! /* ... */ ! .state('menu.work', { url: '/work', views: { menuContent: { templateUrl: 'templates/work.html', controller: 'WorkCtrl' } } }); ! $urlRouterProvider.otherwise('/work'); !});

STATES MANAGED BY uiROUTER State-Based Router with Nested Views

Page 14: Building Mobile Applications with Ionic

angular.module('ionicApp', ['ionic']) !.config(function ($stateProvider, $urlRouterProvider) { ! $stateProvider .state('menu', { abstract: 'true', templateUrl: 'templates/menu.html', controller: 'MenuCtrl' }) ! /* ... */ ! .state('menu.work', { url: '/work', views: { menuContent: { templateUrl: 'templates/work.html', controller: 'WorkCtrl' } } }); ! $urlRouterProvider.otherwise('/work'); !});

STATES MANAGED BY uiROUTER State-Based Router with Nested Views

Page 15: Building Mobile Applications with Ionic

COMPONENTS BY IONIC Mobile-Appropriate Components and Events, Packaged as Angular Directives

Page 16: Building Mobile Applications with Ionic

COMPONENTS BY IONIC Mobile-Appropriate Components and Events, Packaged as Angular Directives

UI Components Action Sheets Alerts Buttons Cards Carousels Checkboxes Footers Forms Headers Icons Lists Modals Navigations Radio Buttons Ranges Selects Tabs Toggles

Events on-hold on-tap on-touch on-release on-drag on-drag-up on-drag-right on-drag-down on-drag-left on-swipe on-swipe-up on-swipe-right on-swipe-down on-swipe-left

Page 17: Building Mobile Applications with Ionic

YOUR OWN COMPONENTS Familiar Angular.js Syntax (No Additional Learning Curve)

Page 18: Building Mobile Applications with Ionic

angular.module('ionicApp').directive(function() { !!!!!!!});

YOUR OWN COMPONENTS Familiar Angular.js Syntax (No Additional Learning Curve)

Page 19: Building Mobile Applications with Ionic

angular.module('ionicApp').directive(function() { !!!!!!!});

return { template: '<div>...</div>', scope: { /* ... */ }, restrict: 'E', link: function(scope, element) { /* ... */ } };

YOUR OWN COMPONENTS Familiar Angular.js Syntax (No Additional Learning Curve)

Page 20: Building Mobile Applications with Ionic

ACCESS THE DEVICE WITH ngCORDOVA ngCordova Provides Angular Services for Cordova Plugins

Page 21: Building Mobile Applications with Ionic

ACCESS THE DEVICE WITH ngCORDOVA ngCordova Provides Angular Services for Cordova Plugins

AdMob App Availability BackgroundGeolocation Battery Status Barcode Scanner Camera Capture Clipboard Contacts DatePicker Device Device Motion Device Orientation Dialogs File Flashlight Geolocation Globalization GoogleAnalytics

Keyboard Keychain NativeAudio Media Local Notification Network Pin Dialog Printer Progress Indicator Push Notifications Social Sharing Spinner Dialog Splashscreen SQLite Statusbar Toast Vibration Zip

Page 22: Building Mobile Applications with Ionic

$

GETTING STARTED Install Global Dependencies

Page 23: Building Mobile Applications with Ionic

npm install -g cordova ionic$

GETTING STARTED Install Global Dependencies

Page 24: Building Mobile Applications with Ionic

$

GETTING STARTED Install Global Dependencies

Page 25: Building Mobile Applications with Ionic

$

GETTING STARTED Generate a New Application with a Starter Template

Page 26: Building Mobile Applications with Ionic

ionic start myApp sidemenu $

GETTING STARTED Generate a New Application with a Starter Template

Page 27: Building Mobile Applications with Ionic

ionic start myApp sidemenu $

GETTING STARTED Generate a New Application with a Starter Template

Page 28: Building Mobile Applications with Ionic

$

GETTING STARTED Generate a New Application with a Starter Template

Page 29: Building Mobile Applications with Ionic

$

GETTING STARTED Fire It Up

Page 30: Building Mobile Applications with Ionic

cd myApp; ionic serve $

GETTING STARTED Fire It Up

Page 31: Building Mobile Applications with Ionic

$

GETTING STARTED Fire It Up

Page 32: Building Mobile Applications with Ionic

THE RESULT View Our Skeleton Application with Chrome Canary

Page 33: Building Mobile Applications with Ionic

THE RESULT View Our Skeleton Application with Chrome Canary

Page 34: Building Mobile Applications with Ionic

SCROLLING Responds to Drag Events; Eases and Bounces

<ion-content> </ion-content>

Page 35: Building Mobile Applications with Ionic

SCROLLING Responds to Drag Events; Eases and Bounces

<ion-content> </ion-content>

Page 36: Building Mobile Applications with Ionic

SCROLLING Responds to Drag Events; Eases and Bounces

<ion-content> </ion-content>

has-bouncing="true">

Page 37: Building Mobile Applications with Ionic

LISTS Lists Can Include Dividers, Icons, Badges, Images, and Form Elements

<ion-list> <ion-item nav-clear class="item-icon-left" menu-close ui-sref="^.menu.home"> ! <i class="icon ion-home"></i>Home </ion-item> ! <!--...--> ! <ion-item class="item-divider"> Resources </ion-item> </ion-list>

Page 38: Building Mobile Applications with Ionic

LISTS Lists Can Include Dividers, Icons, Badges, Images, and Form Elements

<ion-list> <ion-item nav-clear class="item-icon-left" menu-close ui-sref="^.menu.home"> ! <i class="icon ion-home"></i>Home </ion-item> ! <!--...--> ! <ion-item class="item-divider"> Resources </ion-item> </ion-list>

<a class="item item-icon-left item-icon-right" href="#"> <i class="icon ion-chatbubble-working"></i> Call Ma <i class="icon ion-ios7-telephone-outline"></i> </a>

ICONS

Page 39: Building Mobile Applications with Ionic

LISTS Lists Can Include Dividers, Icons, Badges, Images, and Form Elements

<ion-list> <ion-item nav-clear class="item-icon-left" menu-close ui-sref="^.menu.home"> ! <i class="icon ion-home"></i>Home </ion-item> ! <!--...--> ! <ion-item class="item-divider"> Resources </ion-item> </ion-list>

<a class="item item-icon-left item-icon-right" href="#"> <i class="icon ion-chatbubble-working"></i> Call Ma <i class="icon ion-ios7-telephone-outline"></i> </a>

ICONS <a class="item item-icon-left" href="#"> <i class="icon ion-person-stalker"></i> Friends <span class="badge badge-assertive">0</span> </a>

BADGES

Page 40: Building Mobile Applications with Ionic

LISTS Lists Can Include Dividers, Icons, Badges, Images, and Form Elements

<ion-list> <ion-item nav-clear class="item-icon-left" menu-close ui-sref="^.menu.home"> ! <i class="icon ion-home"></i>Home </ion-item> ! <!--...--> ! <ion-item class="item-divider"> Resources </ion-item> </ion-list>

<a class="item item-icon-left item-icon-right" href="#"> <i class="icon ion-chatbubble-working"></i> Call Ma <i class="icon ion-ios7-telephone-outline"></i> </a>

ICONS <a class="item item-icon-left" href="#"> <i class="icon ion-person-stalker"></i> Friends <span class="badge badge-assertive">0</span> </a>

BADGESNOTES <a class="item item-icon-left" href="#"> <i class="icon ion-mic-a"></i> Record album <span class="item-note"> Grammy </span> </a>

Page 41: Building Mobile Applications with Ionic

LISTS Lists Can Include Dividers, Icons, Badges, Images, and Form Elements

<ion-list> <ion-item nav-clear class="item-icon-left" menu-close ui-sref="^.menu.home"> ! <i class="icon ion-home"></i>Home </ion-item> ! <!--...--> ! <ion-item class="item-divider"> Resources </ion-item> </ion-list>

<a class="item item-icon-left item-icon-right" href="#"> <i class="icon ion-chatbubble-working"></i> Call Ma <i class="icon ion-ios7-telephone-outline"></i> </a>

ICONS <a class="item item-icon-left" href="#"> <i class="icon ion-person-stalker"></i> Friends <span class="badge badge-assertive">0</span> </a>

BADGESNOTES <a class="item item-icon-left" href="#"> <i class="icon ion-mic-a"></i> Record album <span class="item-note"> Grammy </span> </a>

BUTTONS <div class="item item-button-right"> Call Ma <button class="button button-positive"> <i class="icon ion-ios7-telephone"></i> </button> </div>

Page 42: Building Mobile Applications with Ionic

LISTS Lists Can Include Dividers, Icons, Badges, Images, and Form Elements

<ion-list> <ion-item nav-clear class="item-icon-left" menu-close ui-sref="^.menu.home"> ! <i class="icon ion-home"></i>Home </ion-item> ! <!--...--> ! <ion-item class="item-divider"> Resources </ion-item> </ion-list>

<a class="item item-icon-left item-icon-right" href="#"> <i class="icon ion-chatbubble-working"></i> Call Ma <i class="icon ion-ios7-telephone-outline"></i> </a>

ICONS <a class="item item-icon-left" href="#"> <i class="icon ion-person-stalker"></i> Friends <span class="badge badge-assertive">0</span> </a>

BADGESNOTES <a class="item item-icon-left" href="#"> <i class="icon ion-mic-a"></i> Record album <span class="item-note"> Grammy </span> </a>

BUTTONS <div class="item item-button-right"> Call Ma <button class="button button-positive"> <i class="icon ion-ios7-telephone"></i> </button> </div>

<a class="item item-avatar" href="#"> <img src="venkman.jpg"> <h2>Venkman</h2> <p>Back off, man. I'm a scientist.</p> </a>

AVATARS

Page 43: Building Mobile Applications with Ionic

LISTS Lists Can Include Dividers, Icons, Badges, Images, and Form Elements

<ion-list> <ion-item nav-clear class="item-icon-left" menu-close ui-sref="^.menu.home"> ! <i class="icon ion-home"></i>Home </ion-item> ! <!--...--> ! <ion-item class="item-divider"> Resources </ion-item> </ion-list>

<a class="item item-icon-left item-icon-right" href="#"> <i class="icon ion-chatbubble-working"></i> Call Ma <i class="icon ion-ios7-telephone-outline"></i> </a>

ICONS <a class="item item-icon-left" href="#"> <i class="icon ion-person-stalker"></i> Friends <span class="badge badge-assertive">0</span> </a>

BADGESNOTES <a class="item item-icon-left" href="#"> <i class="icon ion-mic-a"></i> Record album <span class="item-note"> Grammy </span> </a>

BUTTONS <div class="item item-button-right"> Call Ma <button class="button button-positive"> <i class="icon ion-ios7-telephone"></i> </button> </div>

<a class="item item-avatar" href="#"> <img src="venkman.jpg"> <h2>Venkman</h2> <p>Back off, man. I'm a scientist.</p> </a>

AVATARS <a class="item item-thumbnail-left" href="#"> <img src="cover.jpg"> <h2>Nirvana</h2> <p>Nevermind</p> </a>

THUMBNAILS

Page 44: Building Mobile Applications with Ionic

REMEMBER, IT’S JUST ANGULAR Combine Lists with Template Placeholders and ngRepeat

<ion-list ng-controller="ListController"> <ion-item ng-repeat="item in items"> <i class="icon ion-{{item.icon}}"></i>{{item.title}} </ion-item> </ion-list> !!angular.module("IonicApp") .controller("ListController", function ($scope) { $scope.items = [ {icon: "home", title: "Home"}, {icon: "envelope", title: "My Messages"}, ]; });

Page 45: Building Mobile Applications with Ionic

REMEMBER, IT’S JUST ANGULAR Combine Lists with Template Placeholders and ngRepeat

<ion-list ng-controller="ListController"> <ion-item ng-repeat="item in items"> <i class="icon ion-{{item.icon}}"></i>{{item.title}} </ion-item> </ion-list> !!angular.module("IonicApp") .controller("ListController", function ($scope) { $scope.items = [ {icon: "home", title: "Home"}, {icon: "envelope", title: "My Messages"}, ]; });

Page 46: Building Mobile Applications with Ionic

INTELLIGENT NAVIGATION Ionic Can Use uiRouter to Keep Track of History and Expose a Back Button to Users

<ion-nav-bar></ion-nav-bar> <ion-nav-view animation="slide-left-right"> ! <!-- ... -—> !</ion-nav-view>

Page 47: Building Mobile Applications with Ionic

INTELLIGENT NAVIGATION Ionic Can Use uiRouter to Keep Track of History and Expose a Back Button to Users

<ion-nav-bar></ion-nav-bar> <ion-nav-view animation="slide-left-right"> ! <!-- ... -—> !</ion-nav-view>

Page 48: Building Mobile Applications with Ionic

TOUCH GESTURES Ionic Uses Hammer.js for Touch Gesture Support

<div on-swipe="onSwipe()"> Test </div>

SIMPLE EXAMPLE

Page 49: Building Mobile Applications with Ionic

TOUCH GESTURES Ionic Uses Hammer.js for Touch Gesture Support

<div on-swipe="onSwipe()"> Test </div>

SIMPLE EXAMPLE

Page 50: Building Mobile Applications with Ionic

TOUCH GESTURES Ionic Uses Hammer.js for Touch Gesture Support

<div on-swipe="onSwipe()"> Test </div>

SIMPLE EXAMPLE

https://github.com/driftyco/ionic-contrib-swipe-cards

<swipe-cards> <swipe-card ng-repeat="card in cards" on-destroy="cardDestroyed($index)" on-card-swipe="cardSwiped($index)"> Card content here </swipe-card> </swipe-cards>

CARD SWIPE EXAMPLE

Page 51: Building Mobile Applications with Ionic

Q & A