Skip to content

Commit

Permalink
refactor: removed the internal TOCs + revised H1, h2, h3 to comply wi…
Browse files Browse the repository at this point in the history
…th the generation of right TOCs
  • Loading branch information
NickIliev committed Jun 22, 2018
1 parent 84b2cee commit 2f1714a
Show file tree
Hide file tree
Showing 73 changed files with 253 additions and 720 deletions.
8 changes: 1 addition & 7 deletions docs/app-and-screen-templates/app-templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,9 @@ slug: nativescript-application-templates

There are several available templates that can help you bootstrap your NativeScript application using the best coding practices, in all supported flavors, including Angular & TypeScript, Vanilla JavaScript or TypeScript.

1. [Blank](#blank)
2. [Navigation Drawer](#navigation-drawer)
3. [Tabs](#tabs)
4. [Master Detail with Firebase](#master-detail-with-firebase)
4. [Master Detail with Kinvey](#master-detail-with-kinvey)

To create a new app using one of the templates, you can use the following command:

```bash
```Bash
$ tns create my-app-name --template tns-template-name
```

Expand Down
6 changes: 3 additions & 3 deletions docs/cookbook/tab-view-ng.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ environment: angular
Using a `TabView` inside an Angular app requires some special attention about how to provide title, iconSource and content (view) of the TabItem. In a pure NativeScript application, `TabView` has an items property which could be set via XML to an array of TabViewItems (basically, an array of objects with `title` and `view` properties). However, NativeScript-Angular does not support nested properties in its HTML template, so adding `TabViewItem` to TabView is a little bit different. NativeScript-Angular provides a custom Angular directive that simplifies the way native `TabView` should be used. The following example shows how to add a `TabView` to your page (with some clarifications later):

```XML
// tab-view-test.html
<!-- tab-view-test.html -->
<TabView>
<StackLayout *tabItem="{title: 'Profile', iconSource: '~/icon.png'}" >
<ListView [items]="items">
Expand Down Expand Up @@ -62,7 +62,7 @@ This is a typical usage of the TabView directive; however, if further customizat
The most common customization of TabView is customizing the background color of the selected tab item to use something other than the first tab item for start up. <Comment: Please review my changes to the previous sentence to verify I did not create a technical error.> The following example shows how to achieve that with a few modifications to the previous example.

```XML
// tab-view-test.html
<!-- tab-view-test.html -->
<TabView selectedIndex="1" selectedColor="#FF0000">
<StackLayout *tabItem="{title: 'Profile', iconSource: '~/icon.png'}" >
<ListView [items]="items">
Expand All @@ -87,7 +87,7 @@ The result is a TabView that selects the second tab at start up and uses the col
You can use the NativeScript-Angular TabView `selectedIndex` property in two-way binding scenarios. Using this kind of binding is relatively simple. Just use the standard `ngModel` syntax to a data model property (for the sake of example, the TabViewTest class is used as binding context) and set the data model property `tabSelectedIndex` to the desired value. <Comment: Please review my changes to the previous sentence to verify I did not create a technical error. I think there is a word missing in the phrase, "syntax to a data model property".>

```XML
// tab-view-test.html
<!-- tab-view-test.html -->
<TabView [(ngModel)]="tabSelectedIndex" selectedColor="#FF0000">
<StackLayout *tabItem="{title: 'Profile', iconSource: '~/icon.png'}" >
<ListView [items]="items">
Expand Down
30 changes: 11 additions & 19 deletions docs/core-concepts/accessing-native-apis-with-javascript.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,14 @@ slug: access-native-apis

In this article we are going through the basic concepts of how native APIs are accessed through JavaScript. Our focus is on how primitive types are mapped between JavaScript and the corresponding native platform. We then continue with explaining how complex objects are represented and accessed. At the end, we talk about TypeScript and the `tns-platform-declarations` add-on which gives you TypeScript definitions for the Android and iOS development platforms. The article is divided into the following sections:

- [Overview](#overview)
- [Numeric Types](#numeric-types)
- [String](#string)
- [Boolean](#boolean)
- [Array](#array)
- [Classes and Objects](#classes-and-objects)
- [Undefined & Null](#undefined-and-null)
- [Intellisense and access to native APIs via TypeScript](#intellisense-and-access-to-native-apis-via-typescript)

# Overview
## Overview

NativeScript lets you access all native APIs from the underlying platform. To achieve this behaviour, many things happen under the hood. One of them is marshalling - the conversion between JavaScript and Objective-C data types for iOS and Java data types for Android.

In this article, you will learn how to call native APIs from JavaScript with various data types parameters. For more information, see the platform-specific resources about data conversion in the [iOS Runtime](./../runtimes/ios/marshalling/Marshalling-Overview.md) and [Android Runtime](./../runtimes/android/marshalling/overview.md) sections.

# Numeric Types
## Numeric Types

All native numeric types (e.g., char, short, int, double, float on iOS and byte, short, int, long, double, float on Android) are implicitly converted to JavaScript number and vice versa. For example, when you run the following code on iOS:

Expand All @@ -42,7 +34,7 @@ console.log('min(3, 4) = ', java.lang.Math.min(3, 4));

The native `java.lang.Math.min()` method expects two integers. The Android Runtime knows the signature of the function `java.lang.Math.min()` and translates the literals `3` and `4` to their representation in a Java integer data type. The returned integer is also automatically translated to a JavaScript number and passed to `console.log()`.

# String
## String

JavaScript strings are implicitly marshalled to `java.lang.String` on Android and `NSString` on iOS and vice versa.

Expand All @@ -62,7 +54,7 @@ The exception to this are the methods on `NSString` classes declared as returnin

> Exception: Methods on `NSString` classes declared as returning `instancetype` (e.g., init methods and factory methods). For example, calls to `NSString.stringWithString` return `instancetype` results in Objective-C. In your NativeScript code, such calls will return a wrapper around a `NSString` instance instead of a JavaScript string.
# Boolean
## Boolean

JavaScript boolean values are implicitly marshalled to `boolean` on Android and `BOOL` on iOS and vice versa.

Expand All @@ -79,7 +71,7 @@ var result = str.endsWith('world!');
console.log(result); // true
```

# Array
## Array

JavaScript arrays map to specialized Java arrays on Android and `NSArray` on iOS.

Expand All @@ -100,11 +92,11 @@ var numbers = [3, 6, 19, -2, 7, 6];
var min = ns.example.Math.minElement(numbers); // -2
```

# Classes and Objects
## Classes and Objects

All native classes are represented in the JavaScript world by a constructor function. Each static method on a native class becomes a function on its JavaScript constructor function and each instance method becomes a function on the JavaScript prototype. Although quite intuitive, instantiating objects and calling methods via JavaScript has some specifics (particularly on iOS) which are explained below.

## Working With Classes and Objects on iOS
### Working With Classes and Objects on iOS

Here is an example of how an instance of the `NSMutableArray` class is made and consumed in JavaScript:

Expand All @@ -116,7 +108,7 @@ array.addObject(new NSObject());

This snippet creates an instance of `NSMutableArray` and adds an object to it using the `addObject(object)` method. Here is what happens behind the curtains: the `new NSMutableArray()` call is translated to a `[[NSMutableArray alloc] init]` call by the iOS Runtime. This instance is then wrapped in a JavaScript object and stored in the `array` variable. It contains all public properties and methods exposed by `NSMutableArray` (and its base classes) in its prototype chain. While the `addObject(object)` call is straightforward, calling Objective-C methods with more arguments follows several simple rules that define how Objective-C selectors are mapped to JavaScript functions. Let's consider the following `NSMutableArray` selector: `replaceObjectsInRange:withObjectsFromArray:range:`. In JavaScript it is represented by the following function: `replaceObjectsInRangeWithObjectsFromArrayRange(objectsToRange, souceArray, sourceRange)` (argument names are arbitraty). Note that the function name is generated by appending the names of the arguments as defined by the Objective-C selector by starting with a small letter for the first argument and appending each subsequent with a capital letter.

### NSDictionary
#### NSDictionary

You will most probably encounter methods accepting NSDictionary instances as parameters. There are few ways of creating an NSDictionary instance:

Expand All @@ -130,7 +122,7 @@ var cookie = NSHTTPCookie.cookieWithProperties({[NSHTTPCookieDomain]:".example.c
```
In the second example we are passing a JSON literal to the method.**NSHTTPCookieDomain** is a variable and we need to use a [computed property name](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer) in order to have its value (otherwise we are getting *"NSHTTPCookieDomain"* as key).

## Working With Classes And Objects on Android
### Working With Classes And Objects on Android

The following code snippet demonstrates how an instance of the `android.widget.Button` is created in JavaScript:

Expand All @@ -142,7 +134,7 @@ button.setText("My Button"); // "My Button" is converted to java.lang.String
```
As you can see, the native Java types are exposed through their corresponding packages. In other words, to access a native Java type, you simply need to know the package it is contained in and explicitly state it. Native Java methods are accessed in the same way as regular JavaScript methods: by using the method identifier and supplying the required arguments. You can read more about Java packages on Android [here](https://docs.nativescript.org/runtimes/android/metadata/accessing-packages).

# Undefined and Null
## Undefined and Null

JavaScript [Undefined](http://www.w3schools.com/jsref/jsref_undefined.asp) & [Null](http://www.w3schools.com/js/js_datatypes.asp) map to Java null pointer and Objective-C nil. Native null values map to JavaScript null.

Expand All @@ -158,7 +150,7 @@ var button = new android.widget.Button(context);
button.setOnClickListener(undefined); // the Java call will be made using the null keyword
```

# Intellisense and access to native APIs via TypeScript
## Intellisense and access to native APIs via TypeScript

To have access and Intellisense for the native APIs with TypeScript enabled project, you have to add a dev dependency to `tns-platform-declarations`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ position: 5

V8 comes with a set of controlling flags that may be useful for a fine-grained tuning. Currently, we use `--expose_gc` flag to expose global `gc()` function which comes handy in advanced memory management scenarios. You can set these flags in `package.json` configuration file.

```
```JSON
{
...
"android": {
Expand All @@ -27,7 +27,7 @@ For improved performance V8 keeps a cache of various values used for date / time

While this is not a common requirement for most applications, under some circumstances this be needed. To enable this scenario, you can set the `handleTimeZoneChanges` flag:

```
```JSON
{
...
"android": {
Expand All @@ -43,7 +43,7 @@ As a result, the application will register a [BroadcastReceiver](https://develop

By default all messages sent to Logcat are limited to 1024 characters and larger messages are automatically truncated. This value can be controlled with the `maxLogcatObjectSize` field:

```
```JSON
{
...
"android": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ var file = new java.io.File("somefile");
it creates two objects - one in the JavaScript heap and another in the Java heap. The JavaScript object serves only as a proxy to the actual Java object. Thus the size of the JavaScript object is very small. Suppose the app has to execute the following line

```javascript
var success = file.delete();
let success = file.delete();
```

The only information we need is some sort of `id` in order to find the corresponding Java object and call `delete()` on it. Currently we use `int32` for the `id`. So practically, we can think of `file` as

```javascript
var file = { javaObjectId: 123 };
```JavaScript
let file = { javaObjectId: 123 };
```

if the actual `id` has value `123`. In other worlds, creating JavaScript objects is very cheap.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ position: 5

V8 comes with a set of controlling flags that may be useful for a fine-grained tuning. Currently, we use `--expose_gc` flag to expose global `gc()` function which comes handy in advanced memory management scenarios. You can set these flags in `package.json` configuration file.

```
```JSON
{
...
"android": {
Expand Down
2 changes: 1 addition & 1 deletion docs/core-concepts/android-runtime/debug/debug-cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,6 @@ Detaching the debugger is as simple as closing the chrome-devtools tab.
# See Also
* [Chrome DevTools reference](https://developer.chrome.com/devtools/index).
* [Chrome DevTools in NativeScript - Overview]({% slug chrome-devtools %})
* [Chrome DevTools in NativeScript]({% slug chrome-devtools %})
* [JavaScript debugging](https://developer.chrome.com/devtools/docs/javascript-debugging).
* [debugger; statement](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Statements/debugger)
8 changes: 0 additions & 8 deletions docs/core-concepts/android-runtime/debug/debug-native.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,6 @@ previous_url: /debug-eclipse

# Debugging the Android Runtime

1. [Overview](#overview)
1. [Setting up the project for native debugging](#setting-up-the-project-for-native-debugging)
1. [Debugging with chrome-dev-tools and Android Studio](#debugging-with-chrome-dev-tools-and-android-studio)
1. [Adb Forward](#adb-forward)
1. [Open Google Chrome with debug url](#open-google-chrome-with-debug-url)
1. [Known Issues](#known-issues)
1. [See Also](#see-also)

## Overview

The [Debug article](./debug-cli) shows how to debug the business logic of your application. But what happens when the problem is in the runtime? How do I debug the application and the runtime simultaneously?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ position: 1
The content in this document describes how to create a NativeScript Application in Android Studio.
> **Note:** The recommended way of creating truly cross-platform NativeScript projects is through its [Command-Line Interface](https://github.com/NativeScript/nativescript-cli).
# Prerequisites
## Prerequisites
* [Android Developer Tools](http://developer.android.com/sdk/index.html) with Android Studio.
* The NPM Android Runtime Project (`npm install tns-android`).

# Setup Project Directory Structure
## Setup Project Directory Structure
> **Note:** The tns-android folder structure follows the ADT's plugin for Eclipse format, which differs from the Android Studio's one, hence some manual copy-paste steps are required.
* Create a new `Blank Activity` project in Android Studio.
Expand All @@ -27,24 +27,24 @@ The content in this document describes how to create a NativeScript Application
* Within the project's `assets` folder create a new folder named `app`.
* Create a new `bootstrap.js` file within the `app` folder.
* Open the` AndroidManifest.xml` file and edit the name of the application like:
```xml
```XML
<application
android:name="com.tns.NativeScriptApplication"
...
```
* Open the` AndroidManifest.xml` file and edit the name of the activity like:
```xml
```XML
<activity
android:name="com.tns.NativeScriptActivity"
...
```

# Setup Bootstrap.js
## Setup Bootstrap.js
Now that the project is properly setup, we need to properly initialize the `bootstrap.js` file. It may be thought of as the **Main Entry Point** of a NativeScript application. The NativeScript Runtime will expose the `app` object within the global context and use it to initialize the application from JavaScript. Following is the minimum required code:

```javascript
```JavaScript
// declare the extended NativeScriptActivity functionality
var extendsObject = {
let extendsObject = {
onCreate: function(savedState){
// call the base NativeScriptActivity.onCreate method
// the "this" variable points to a NativeScriptActivity instance
Expand All @@ -59,9 +59,9 @@ var extendsObject = {
}

// pass the extends object to create a new NativeScriptActivity instance
var mainActivity = com.tns.NativeScriptActivity.extends(extendsObject);
const mainActivity = com.tns.NativeScriptActivity.extends(extendsObject);

var applicationInitObject = {
let applicationInitObject = {
getActivity: function(intent) {
// this method is called whenever a new instance of NativeScriptActivity is about to be created
return mainActivity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ position: 3
# Modules
The Module Design Pattern is an integral piece of any robust application and is used to keep units of code cleanly separated and organized. NativeScript has a simple module loading mechanism which strictly follows the [CommonJS Specification](http://www.commonjs.org/specs/modules/1.0/). Most of the functionality is similar with the [Node.js](http://nodejs.org/api/modules.html) implementation with some minor differences. A typical NativeScript application will use the [set of modules](https://github.com/NativeScript/docs) which add cross-platform abstraction layer on top of OS-specific APIs.

# NativeScript Modules vs. Node Modules
## NativeScript Modules vs. Node Modules
Following are the differences between Node modules and NativeScript modules:

### Core Modules
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ position: 4
# Overview
Both Java and JavaScript are high-level languages meaning that they both provide strong abstraction from the computer details. It is relatively straightforward to express a high-level language to low-level one (for example to translate Java to Assembly). However, there are technical difficulties when it comes to translating one high-level concept to another. Such difficulties are largely known as *impedance mismatch*. This article explains how the deal with the impedance mismatch when it comes to working with Java inner and nested types.

# Java Nested Types
## Java Nested Types
Here is a short example that summarizes the relation between Java nested and inner types.
```Java
public class Outer {
Expand Down Expand Up @@ -44,7 +44,7 @@ var inner2 = new new Outer().Inner();
var nested = new Outer.Nested();
```

# Accessing Static Members
## Accessing Static Members
NativeScript for Android supports accessing static members of inner/nested types as well.
```JavaScript
var c = android.hardware.Camera.Parameters.ANTIBANDING_50HZ;
Expand Down
Loading

0 comments on commit 2f1714a

Please sign in to comment.