3 Anatomy of a NativeScript app

 

This chapter covers

  • How NativeScript apps are structured
  • How the NativeScript runtime loads the first page of your app
  • How you can target different mobile platforms using conventions
  • How to organize your NativeScript app code

In Chapter 2 you learned how to create your first cross-platform app with the NativeScript CLI, how to further use the CLI to add the Android and iOS platforms to an app, and how to test your app by running it in an emulator. In this chapter, we’ll take a deeper look at the app structure the NativeScript CLI scaffolds.

The structure of a NativeScript app is important because NativeScript is an opinionated framework for developing mobile apps. Opinionated frameworks require you to write code, name files, and organize app components in certain ways; if you don’t follow the rules of NativeScript, your app won’t run. At this point, working with an opinionated framework probably sounds painful and frustrating. After all, why would you want to be restricted to following such specific rules? Don’t worry: I’ve got your back. NativeScript’s rules (also known as conventions) are easy to understand and make writing apps that work on Android and iOS simpler, not more complex. Let’s jump in and learn!

3.1   Exploring the structure of a NativeScript app

3.1.1   The root application folder and files

3.1.2   The node_modules folder

3.1.3   The platforms folder

3.1.4   The app folder

3.2   Understanding app startup

3.3   Style guide and app organization

3.4   Summary

3.5   Exercise

3.6   Solutions