building native win8 apps with yui

75

Upload: tilo-mitra

Post on 07-Nov-2014

2.234 views

Category:

Technology


0 download

DESCRIPTION

Using the YUI App Framework we can build native Windows 8 apps with access to hardware and native APIs while reducing our overall code-base. The views and models that you write for your web app can be re-used for Windows 8.

TRANSCRIPT

Page 1: Building native Win8 apps with YUI
Page 2: Building native Win8 apps with YUI

Building native Windows 8 appsusing YUI 3@tilomitra // YUI Engineer

Page 3: Building native Win8 apps with YUI
Page 4: Building native Win8 apps with YUI

About this talk

Page 5: Building native Win8 apps with YUI

About this talk

• A bit about Windows 8 and IE10

Page 6: Building native Win8 apps with YUI

About this talk

• A bit about Windows 8 and IE10

• WinJS

Page 7: Building native Win8 apps with YUI

About this talk

• A bit about Windows 8 and IE10

• WinJS

• WinJS + YUI (with Demo)

Page 8: Building native Win8 apps with YUI

About this talk

• A bit about Windows 8 and IE10

• WinJS

• WinJS + YUI (with Demo)

• Questions & Discussion

Page 10: Building native Win8 apps with YUI
Page 11: Building native Win8 apps with YUI
Page 12: Building native Win8 apps with YUI

Apps. Opportunity.

Page 13: Building native Win8 apps with YUI

Apps. Opportunity.

Page 14: Building native Win8 apps with YUI

We gave ourselves 10 days (which included weekends) to get the job done…We were able to add support for all these new environments very quickly because of YUI’s architecture.

-Eric F.

YUI 3.7.3

Page 15: Building native Win8 apps with YUI

Windows 8

Page 16: Building native Win8 apps with YUI

Win8 vs WinRTWin8 Can run traditional Windows apps and the

new Metro apps

WinRT“Windows 8 Lite” designed primarily for tablets such as the Surface.

Can only run Metro apps

Page 17: Building native Win8 apps with YUI

4 different JS runtimes

• IE10 Desktop

• IE10 Start Screen (Metro)

• Webview inside a C# app

• WinJS

Page 18: Building native Win8 apps with YUI

IE10 “Metro”

• More restrictive than IE10 Desktop

• Minimal support for plugins (ActiveX, Flash, Silverlight, etc.)*

* Metro IE10 does have Flash support but only sites that are on the Compatibility List can play Flash content.

Page 19: Building native Win8 apps with YUI

IE10 “Metro”

• More restrictive than IE10 Desktop

• Minimal support for plugins (ActiveX, Flash, Silverlight, etc.)*

* Metro IE10 does have Flash support but only sites that are on the Compatibility List can play Flash content.

Page 20: Building native Win8 apps with YUI

Webview

• Similar to web-views on iOS or Android

• No access to device APIs, limited HTML5 support

       

<WebView Name="wv" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Source="http://yuilibrary.com"/>

Page 21: Building native Win8 apps with YUI

WinJS

Page 22: Building native Win8 apps with YUI

WinJS• A restricted IE10 runtime with access to

native APIs

• Allows developers to create WinRT apps using HTML/CSS/JS

• All scripts/styles must be available on device

Page 23: Building native Win8 apps with YUI

WinJS• A restricted IE10 runtime with access to

native APIs

• Allows developers to create WinRT apps using HTML/CSS/JS

• All scripts/styles must be available on device

Page 24: Building native Win8 apps with YUI

WinJSWhat’s different about it?

Page 25: Building native Win8 apps with YUI

Overview

Page 26: Building native Win8 apps with YUI

Overview

• Uses IE10 to process HTML/CSS/JS

Page 27: Building native Win8 apps with YUI

Overview

• Uses IE10 to process HTML/CSS/JS

• Stylesheets and scripts bundled locally

Page 28: Building native Win8 apps with YUI

Overview

• Uses IE10 to process HTML/CSS/JS

• Stylesheets and scripts bundled locally

• No JSONP, safe innerHTML

Page 29: Building native Win8 apps with YUI

Overview

• Uses IE10 to process HTML/CSS/JS

• Stylesheets and scripts bundled locally

• No JSONP, safe innerHTML

• Access to Windows and WinJS namespaces

Page 30: Building native Win8 apps with YUI

Injecting HTML

myDiv.innerHTML  =  ‘<script>function  test()  {  alert("Testing,  Testing,  123...");  }</script><span  onclick="test()">Click  Me</span>’

//results  in  <span>Click  me</span>

List of all filtered elements

Page 31: Building native Win8 apps with YUI

A WinJS App

default.html

default.js default.css

base.js

ui.js

navigator.js

WinJS References

ui.css

Page 32: Building native Win8 apps with YUI

A WinJS App

default.html

default.js default.css

base.js

ui.js

navigator.js

WinJS References

ui.css

Basic Shell

App Lifecycle Code

Native styles

JS Utilities

UI Views

NavigationMedia queries

Page 33: Building native Win8 apps with YUI

Adding Pages

default.html

WinJS References

Other scripts/styles

Master View

masterview.html

masterview.css

masterview.js

Detail View

detailview.html

detailview.css

detailview.js

Page 34: Building native Win8 apps with YUI

Pages adopt MVCEach “page” of the app has has it’s own HTML, CSS, and JS

View Defined by page.html and page.css

Controller Defined by page.js

Model Defined in default.html and available in all pages

Page 35: Building native Win8 apps with YUI

default.html

A “wrapper” around different pages.

default.html

homepage.htmlhomepage.csshomepage.js

<div  idcontroligator"        data-­‐win-­‐optionspages/homepage/homepage'}"></div>

Page 36: Building native Win8 apps with YUI

default.html

A “wrapper” around different pages.

default.html

homepage.htmlhomepage.csshomepage.js

<div  id="contenthost"  data-­‐win-­‐control="Application.PageControlNavigator"        data-­‐win-­‐options="{home:  '/pages/homepage/homepage'}"></div>

Page 37: Building native Win8 apps with YUI

default.js: Lifecycle eventsactivated When the app is launched.

loadedAfter DOMContentLoaded (HTML parsed, resources not loaded)

ready When the app ready for use

checkpointWhen the user switches away from your app. Good time to save state.

unload When app is about to be unloaded

Page 38: Building native Win8 apps with YUI

Navigation

Single page navigation model provided by navigator.js through WinJS.Navigation.navigate(...)

default.html

masterView.html

default.html

detailView.html

Page 39: Building native Win8 apps with YUI

Navigation

This is what happens if you use <a href=”...”>

default.html

masterView.html detailView.html

Page 40: Building native Win8 apps with YUI

Navigation

This is what happens if you use <a href=”...”>

default.html

masterView.html detailView.html

Where am I?Who am i?

What is the meaning of life?

Page 41: Building native Win8 apps with YUI

Navigation

Use WinJS.Navigation.navigate() instead of location.href

WinJS.Navigation.navigate("/pages/itemDetail/itemDetail.html",  {  model:  model});

//the  passed  object  can  be  retrieved  in  itemDetail.js

groupedMaster.js

Page 42: Building native Win8 apps with YUI

WinJS + YUILeveraging YUI to build Win 8 apps

Page 43: Building native Win8 apps with YUI

It’s all about reusing code

• Re-use your existing web code-base when making Win 8 apps

• Use existing concepts - don’t re-invent the wheel

• But what about UI/UX?

Page 44: Building native Win8 apps with YUI
Page 45: Building native Win8 apps with YUI
Page 46: Building native Win8 apps with YUI

Y.Sights.GridView

Page 47: Building native Win8 apps with YUI

Y.Sights.GridView

Y.Sights.ShotList

Page 48: Building native Win8 apps with YUI

Y.Sights.GridView

Y.Sights.ShotList

Y.Sights.Shot

Page 49: Building native Win8 apps with YUI
Page 50: Building native Win8 apps with YUI
Page 51: Building native Win8 apps with YUI

Y.Masonry

Page 52: Building native Win8 apps with YUI
Page 53: Building native Win8 apps with YUI

Y.Sights.GridView

Page 54: Building native Win8 apps with YUI

Y.Sights.GridView

Y.Sights.ShotList

Page 55: Building native Win8 apps with YUI

Y.Sights.GridView

Y.Sights.ShotList

Y.Sights.Shot

Page 56: Building native Win8 apps with YUI
Page 57: Building native Win8 apps with YUI

Y.DetailView

Page 58: Building native Win8 apps with YUI

demo

Page 59: Building native Win8 apps with YUI

Including YUI• Pull down necessary modules using the

Dependency Configurator

• Clone YUI and include build/ and src/

• Clone YUI and include build/

Page 60: Building native Win8 apps with YUI

Including YUI• Pull down necessary modules using the

Configurator

• Clone YUI and include build/ and src/

• Clone YUI and include build/

Page 61: Building native Win8 apps with YUI

Including YUI        

               <!-­‐-­‐  WinJS  references  -­‐-­‐>        <link  href="//Microsoft.WinJS.1.0.RC/css/ui-­‐dark.css"  rel="stylesheet"  />        <script  src="//Microsoft.WinJS.1.0.RC/js/base.js"></script>        <script  src="//Microsoft.WinJS.1.0.RC/js/ui.js"></script>          <script>              YUI_config  =  {                    ...              };        </script>        <script  src="/js/lib/yui3/build/yui/yui-­‐min.js"></script>

default.html

Page 62: Building native Win8 apps with YUI

Let’s re-visit MVC

MVC, you say? Reminds me of the YUI App Framework.

Page 63: Building native Win8 apps with YUI

Let’s re-visit MVC

Model Defined by Y.Model/Y.ModelList

View Defined by Y.View

Controller Defined by {page}.js

Page 64: Building native Win8 apps with YUI

Models

• Should be environment agnostic

• Y.Model/Y.ModelList + Y.YQL

• Work on the browser and on WinJS

Page 65: Building native Win8 apps with YUI

Views

Should we use native WinJS UI Views, or leverage Y.View?

Page 66: Building native Win8 apps with YUI
Page 67: Building native Win8 apps with YUI
Page 68: Building native Win8 apps with YUI

Native ViewsEasy to get it to look “right”

It’s the WinJS way (documentation, code samples, etc.)

Code can’t be re-used outside this environment

Need to figure out how to organize native code and YUI code

No performance gain for using native views

Page 69: Building native Win8 apps with YUI

Y.ViewCode once, re-use in different environments

Works well with YUI

Achieving the look and feel of Win 8 is fairly easy

Need to code and determine markup and styles

Page 70: Building native Win8 apps with YUI

Native Views vs. Y.View• Depends on the app

• Over the long term, Y.View probably offers greater benefits

• Try using both and see what you are comfortable with

Page 71: Building native Win8 apps with YUI

Controllers

• Haven’t experimented with Y.Router in this environment yet

• Page navigation done through WinJS.Navigation.navigate(...)

• Navigation history maintained by navigator.js

Page 72: Building native Win8 apps with YUI

UI/UX

Won’t user experience suffer if we don’t use native APIs?

Page 73: Building native Win8 apps with YUI

UI/UX• Everything is HTML, CSS, and JS, whether it’s

native or not.

• CSS3 transitions are supported

• Easy to leverage ui-*.css styles to get the right look and feel

• Remember, Win 8 UI !== Web UI

Page 74: Building native Win8 apps with YUI

Debugging WinJS apps• Breakpoints and JavaScript console for

standard debugging

• Windows Simulator

• View the DOM while the app is running with the DOM Explorer

Page 75: Building native Win8 apps with YUI

Thanks!Questions or comments? Fire away.

@tilomitrahttp://github.com/tilomitra/Sights