Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Nativescript - Building truly native apps with Javascript

Nativescript - Building truly native apps with Javascript

Márcio Vicente

October 08, 2016
Tweet

More Decks by Márcio Vicente

Other Decks in Programming

Transcript

  1. } The problem Native UX
 Native APIs Web Easy to

    learn
 Reuse Code (desktop/mobile) Hybrid
  2. } What is NativeScript? What is NativeScript? "An open source

    framework for building truly native mobile apps with JavaScript. Use web skills, like TypeScript, Angular and CSS, and get native UI and performance on iOS and Android"
  3. Architectural pattern
 No more MVC M V VM Model View

    View-Model Data logic UI Application Logic }
  4. }

  5. }

  6. }

  7. }

  8. } // app/components/buttons/flat.xml <button>{{ label }}</button> 
 
 // app/main.xml

    <Page xmlns:buttons=“components/buttons“> <buttons:flat label=“{{ btnLabel }}” /> </Page> // Custom components
  9. } // app/page.ts @Component({ selector: ‘flat-btn', template: ‘<button class="flat">{{label}}</button>’ });

    // app/page.html <flat-btn label=“Submit”></flat-btn> Custom components
  10. } //Custom NS plugins // custom-plugins/device.ios.js
 module.exports = { version:

    UIDevice.currentDevice().systemVersion }
 
 // custom-plugins/device.android.js
 module.exports = { version: Build.VERSION.RELEASE }
 
 // app.js
 import device from ‘./custom-plugins/device’;
 console.log(device.version);
  11. } //Same codebase <Button ios:text=“Submit" android:text=“Send" /> // from attributes

    if (page.ios) {
 new UiAlertDialog().show('text');
 } else {
 new CustomJavaDialog('text'); } // from JS
  12. } Get started $ npm install -g nativescript 
 $

    tns create my-app $ tns platform add ios $ tns build ios $ tns livesync ios --emulator --watch
  13. } Some tips • Use VS Code (+ NS extension)

    • Create from template • nativescript.rocks