Nativescript O Architecture O Developer Experience O Future Goals • Conclusions Hybrid Approaches
Total Page:16
File Type:pdf, Size:1020Kb
Runtime Based Hybrid Apps Ruben Smeets Kris Aerts ES&S 26/04/2016 Agenda • Hybrid Approaches • Runtime Based CPT Candidates • Comparison of Titanium / React Native / NativeScript o Architecture o Developer Experience o Future goals • Conclusions Hybrid Approaches WebView Based Runtime Based WebView Container JavaScript Runtime Web Code JavaScript HTML CSS JS Native UI + Device APIs Device APIs Hybrid Approaches WebView Based Web Code UI frameworks & libs DOM - based WebGL - based React Canvas Famo.us + Architectural frameworks Combined frameworks Hybrid Approaches WebView Based Web Code Pure Hybrid Apps Tools Properties UI frameworks & libs • Single WebView • Content & navigation DOM - based WebGL - based in HTML5 • Thin native wrapper React Canvas Famo.us + Architectural frameworks Combined frameworks Hybrid Approaches WebView Based Web Code Pure Hybrid Apps Tools Properties UI frameworks & libs • Single WebView • Content & navigation DOM - based WebGL - based in HTML5 • Thin native wrapper React Canvas Mixed hybrid Apps Pattern Tools Properties • Multiple WebViews Famo.us Blended • Native navigation • E.g.: Apple Store + • WebViews for later stages of Architectural Mullet user flow frameworks • E.g.: Walmart • WebViews for little used or frequently Combined frameworks Fallback changing content • E.g.: Instagram Hybrid Approaches Runtime Based WebView Based Runtime Based WebView Container JavaScript Runtime Web Code JavaScript HTML CSS JS Native UI + Device APIs Device APIs Hybrid Approaches Runtime Based – The “WHY” • Consistent with platform • Fast and responsive • Complex gestures and smooth animations • No knowledge & code sharing • Different technology stacks • Slow iteration speeds* • Hard to scale *Android Instant Run Hybrid Approaches Runtime Based – The “WHY” continued • HTML / CSS / JavaScript • Same code and technologies • Frameworks provide scaling • F5 / ⌘+R • Very hard to provide smooth experiences • Not designed for complex interactions • Feel out of place with the platform Hybrid Approaches Runtime Based – The “WHY” continued Web advantages • JSX / XML / CSS / JavaScript • Same code and technologies • Frameworks provide scaling • Live-reload Native advantages • Consistent with platform • Fast and responsive UI • Complex gestures and smooth 60fps animations Hybrid Approaches Runtime Based – The “HOW” JavaScript Runtime Composition • Native side JavaScript • JavaScript side • JS-to-native bridge Key concepts Native UI • Proxy objects + Device APIs • Asynchronous calls Runtime Based CPT Candidates Titanium React Native Nativescript Fusetools TabrisJS Smartface Announced 2008 2015 2014 2015 2014 2011 Version V5.2.2 V0.24 V1.7 V0.12 V1.7 v4.5.0 Android Android Android Android Android Android 4.0.x – 6.0.x 4.1.x – 6.0.x 4.2.x – 6.0.x 4.2.x – 6.0.x 3.7.x - 5.x 4.2.x – 6.0.x Platforms iOS iOS iOS iOS iOS iOS 7.1.x – 9.2.x 7.0.x – 9.2.x 7.1.x – 9.2.x 7.1.x – 9.2.x 6.x - 8.x 7.1.x – 9.2.x WP8.1-UWP UWP (alpha) UWP (alpha) 11658 556 2300 5871 634 63 Popularity 23564 72340 7142 16028 252 1102 2063 30206 6393 / 384 / 2303 3439 259 1119 2 283 Popularity numbers are checked on 04/2016 Agenda • Hybrid Approaches • Runtime Based CPT Candidates • Comparison of Titanium / React Native / NativeScript o Architecture o Developer Experience o Future goals • Conclusions Architecture Comparing Ti vs RN vs {N} Architecture – Used Technologies Programming • JavaScript (ES5) • XML mark-up • TSS styling (CSS-like styling) Layout system • Relative to parent view Comparing Ti vs RN vs {N} Architecture – Used Technologies Examples views/index.xml styles/index.tss controllers/index.js Comparing Ti vs RN vs {N} Architecture – Used Technologies Programming • JavaScript (ES5) • JavaScript (ES6+ES7 • XML mark-up using Babel transpiler) • JSX (XML like mark-up • TSS styling (CSS-like language) styling) • JavaScript “inline” styles • Flow (static type checker for JavaScript) Layout system • Relative to parent view • Flexbox Comparing Ti vs RN vs {N} Architecture – Used Technologies Examples index.ios.js • Mixing XML-like mark-up inside JavaScript • Inline styles Comparing Ti vs RN vs {N} Architecture – Used Technologies Programming • JavaScript (ES5) • JavaScript (ES6+ES7 • JavaScript (ES5) or • XML mark-up using Babel transpiler) Typescript (ES6+ES7) • JSX (XML like mark-up • XML mark-up • TSS styling (CSS-like language) styling) • JavaScript “inline” • CSS styling styles • Flow (static type checker for JavaScript) Layout system • Relative to parent view • Flexbox • Native layout sys. Comparing Ti vs RN vs {N} Architecture – Used Technologies Examples View/home/home.xml View/home/home.css View/home/home.js Comparing Ti vs RN vs {N} Architecture – Application Structure Design Pattern • MVC (using Alloy) Additional concepts Philosophy • Write once, adapt everywhere Comparing Ti vs RN vs {N} Architecture – Application Structure Comparing Ti vs RN vs {N} Architecture – Application Structure MVC Data Package: uses BackboneJS models and collections Comparing Ti vs RN vs {N} Architecture – Application Structure Design Pattern • MVC (using Alloy) • Flux or Redux (unidirectional data flow) Additional concepts • React Components • Virtual DOM • Used as part of app Philosophy • Write once, adapt • Learn once, write everywhere anywhere (changed to horizontal platform) Comparing Ti vs RN vs {N} Architecture – Application Structure Comparing Ti vs RN vs {N} Architecture – Application Structure ReactJS One way data flow inside components ReactJS: Keep Simple. Everything can be a component! – Pedro Nauck Comparing Ti vs RN vs {N} Architecture – Application Structure Flux Manage one-way dataflow inside the application https://facebook.github.io/flux/docs/overview.html Comparing Ti vs RN vs {N} Architecture – Application Structure VirtualDOM React Virtual DOM vs Incremental DOM vs Ember’s Glimmer: Fight - Sebastián Peyrott Comparing Ti vs RN vs {N} Architecture – Application Structure Design Pattern • MVC (using Alloy) • Flux or Redux • MVC or MVVM (unidirectional data flow) Additional concepts • React Components • Virtual DOM • Used as part of app Philosophy • Write once, adapt • Learn once, write • Write once, run everywhere anywhere (changed to everywhere horizontal platform) Comparing Ti vs RN vs {N} Architecture – Application Structure Comparing Ti vs RN vs {N} Architecture – Application Structure MVVM (View-Model) User-viewModel.js (Model) User.js (View) First Name Form.xml Last Name First Name: ... Last Name: … Hotel (View-Model) Name: … Hotel-viewModel.js (Model) Name Hotel.js • Two-way data binding • Observables • Increased testability • Code reusability Comparing Ti vs RN vs {N} Architecture – Runtime Architecture Properties • 2 Threads • Main UI thread • JS thread • Asynchronous • Serializable (iOS) • Spawn native threads for work offloading Comparing Ti vs RN vs {N} Architecture – Runtime Architecture Various Proxies: • Proxy • Module • ViewProxy • View Titanium documentation Comparing Ti vs RN vs {N} Architecture – Runtime Architecture Properties • 2 Threads • 3 Threads • Main UI thread • Shadow thread • JS thread • Main UI thread • Asynchronous • JS thread • Serializable (iOS) • Asynchronous • Spawn native threads • Batched native calls for work offloading • Serializable Comparing Ti vs RN vs {N} Architecture – Runtime Architecture Native 1 Event 8 Update UI (touch, timer, networks, etc.) (if needed) 2 Collect data and notify JS 7 Process commands 3 Serialized payload 6 Serialized response React Native Bridge Call 0 - ∞ 4 Process event 5 Native methods JavaScriptCore Under the hood of React Native - Martin Konicek Comparing Ti vs RN vs {N} Architecture – Runtime Architecture Ex. RN Worker UI Event Queue JS Event Queue Event Queue(s) 2 Handle Event 1 Touch Event àbridge à Runs JS 3 Dispatch View 4 Update UI Updates Image decode, Disk I/O, Layout, Etc. Under the hood of React Native - Martin Konicek Comparing Ti vs RN vs {N} Architecture – Runtime Architecture Properties • 2 Threads • 3 Threads • 2 Threads • Main UI thread • Shadow thread • Main UI thread • JS thread • Main UI thread • JS thread • Asynchronous • JS thread • Asynchronous • Serializable (iOS) • Asynchronous • Direct native API • Spawn native threads • Batched native calls access for work offloading • Serializable Note: every bridge has a type conversion mechanism Comparing Ti vs RN vs {N} Architecture – Runtime Architecture Native Native APIs Call Dispatcher Type-conversion marshalling service Calls JavaScript functions Meta-data NativeScript runtime Bindings Calls native API using JavaScript App Code JavaScript (JS ES5 & Libraries Typescript) JavaScript VM How NativeScript Works - Te l e ri k Comparing Ti vs RN vs {N} Architecture – Runtime Architecture Ex. V8 JavaScript Engine var file = new java.io.File( path ); File = FileProxy Native Type conversion Service Android java.lang.String Metadata java.io.File() Call dispatcher java.io.File() How NativeScript Works - Te l e ri k Comparing Ti vs RN vs {N} Architecture – Modularity Options • Titanium modules • React Native modules • NativeScript • Built-in (100+) • Build-in (60+) modules • gitTrio community • JS Coach (1000+) • Build-in (54) modules and widgets • Cordova plugin • Community (1351) + (674) integration NPM (198) • Appcelerator modules • CocoaPods/ Java • Verified (open source) (27) marketplace (13) JAR integration • Marketplace (383) • Telerik UI for • NPM JS libraries • NPM JS libraries (no DOM reliance) NativeScript (4) through titaniumifier • CocoaPods/ Java (no DOM reliance) JAR integration • NPM JS libraries (no DOM