You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 17, 2022. It is now read-only.
Copy file name to clipboardExpand all lines: docs/core-concepts/accessing-native-apis-with-javascript.md
+11-17
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ slug: access-native-apis
8
8
9
9
# Accessing native iOS and Android APIs through JavaScript
10
10
11
-
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.
11
+
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 `@nativescript/types` add-on which gives you TypeScript definitions for the Android and iOS development platforms.
12
12
13
13
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.
14
14
@@ -223,25 +223,24 @@ button.setOnClickListener(undefined); // the Java call will be made using the nu
223
223
224
224
## IntelliSense and Access to the Native APIs via TypeScript
225
225
226
-
To have access and Intellisense for the native APIs, you have to add a developer dependency to `tns-platform-declarations`.
226
+
To have access and Intellisense for the native APIs, you have to add a developer dependency to `@nativescript/types`.
> **Note:** Always install the plugin as a `devDependency` (`npm i tns-platform-declarations --save-dev` flag) to avoid bringing the enormously big declaration files in the output built file.
232
+
> **Note:** Always install the plugin as a `devDependency` (`npm i @nativescript/types --save-dev` flag) to avoid bringing the enormously big declaration files in the output built file.
233
233
234
234
Create `reference.d.ts` in the root project directory and add the following:
By default, the file `android.d.ts` comes with typings generated for API level 17. As an Android developer, you might need access to a specific class, method, or property introduced in a newer API level. The `tns-platform-declarations` plugin comes with generated typings for all API levels from 17 to 27 including the related typings from the respective support library. To use typings for a specific Android level replace the reference to the default declaration file with the preferred one. The files for each API level comes postfixed with a dash followed by the number of the API level (e.g. for API 21 the file is named `android-21.d.ts`).
239
+
By default, the file `android.d.ts` comes with typings generated for API level 17. As an Android developer, you might need access to a specific class, method, or property introduced in a newer API level. The `@nativescript/types` plugin comes with generated typings for all API levels from 17 to 27 including the related typings from the respective support library. To use typings for a specific Android level replace the reference to the default declaration file with the preferred one. The files for each API level comes postfixed with a dash followed by the number of the API level (e.g. for API 21 the file is named `android-21.d.ts`).
241
240
242
241
For example, let's assume you are developing an application for API 21+ and you need typings generated for that API level:
> **Note:** Proceed with caution when using functionalities introduced in newer API level. If you attempt
@@ -252,18 +251,13 @@ For example, let's assume you are developing an application for API 21+ and you
252
251
{
253
252
"compilerOptions": {
254
253
...
255
-
"lib": ["es6", "dom"],
256
-
"baseUrl": ".",
257
-
"paths": {
258
-
"*": [
259
-
"./node_modules/tns-core-modules/*",
260
-
"./node_modules/*"
261
-
]
262
-
}
254
+
"module": "esnext",
255
+
"target": "es2015",
256
+
"moduleResolution": "node",
257
+
"lib": ["es2018", "dom"],
263
258
}
264
259
```
265
260
Note that `d.ts` files require a lot of memory and CPU. Consider adding **skipLibCheck** option to `tsconfig.json`.
266
-
For more information visit the GitHub repository of [tns-platform-declarations](https://github.com/NativeScript/NativeScript/tree/master/tns-platform-declarations)
Copy file name to clipboardExpand all lines: docs/core-concepts/android-runtime/advanced-topics/marking-mode-none.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,7 @@ slug: marking-mode-none
9
9
10
10
Starting with NativeScript 3.2, a new (experimental at the time) feature was added to the Android runtime called `markingMode`. Its purpose is to speed up garbage collection in the V8 engine. In some cases, a GC pass could take from 0.5 to 1 second and since it runs on the main UI thread, the user would experience a frozen app until GC is done. Setting “markingMode” to “none” will speed up the garbage collection greatly, so it would be less noticeable (if at all) to the app user. The downside of this approach is that some objects could be collected while their counterparts (in V8 or Android) are still in use. Such case is when JavaScript objects are referenced only from native code and in the eyes of the V8 GC no JS object holds reference to them. In other words – the objects are no longer “marked” as used and the V8 GC might collect them too early.
11
11
12
-
The code inside `tns-core-modules` and all plugins published by the NativeScript Team (since version 5.1.0) are written in such a way, that it does not depend on the scope to keep those Java/Kotlin instances alive. This makes apps using these plugins fully compatible with the much more performant `markingMode: "none"` option.
12
+
The code inside `@nativescript/core` and all plugins published by the NativeScript Team (since version 5.1.0) are written in such a way, that it does not depend on the scope to keep those Java/Kotlin instances alive. This makes apps using these plugins fully compatible with the much more performant `markingMode: "none"` option.
13
13
14
14
## Benefits and drawbacks of using markingMode: none
Copy file name to clipboardExpand all lines: docs/core-concepts/android-runtime/advanced-topics/memory-management.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -48,7 +48,7 @@ There's a `app/package.json` option which apps can set in order to disable `Mark
48
48
}
49
49
```
50
50
51
-
The code inside `tns-core-modules` and all plugins published by the NativeScript Team (since version 5.1.0) are written in such a way, that it does not depend on the scope to keep those Java/Kotlin instances alive. This makes apps using these plugins fully compatible with the much more performant `markingMode: "none"` option. [More information on `markingMode:none`](./marking-mode-none).
51
+
The code inside `@nativescript/core` and all plugins published by the NativeScript Team (since version 5.1.0) are written in such a way, that it does not depend on the scope to keep those Java/Kotlin instances alive. This makes apps using these plugins fully compatible with the much more performant `markingMode: "none"` option. [More information on `markingMode:none`](./marking-mode-none).
52
52
53
53
> **WARNING**: Enabling this option if the JavaScript code dealing with native objects (either in the application or any plugins you are using) does not correctly take care of the lifetime of Java/Kotlin instances may cause unexpected and unpredictable crashes of the application. This would be caused by Java/Kotlin instances being prematurely collected. Use caution when enabling it and make sure to thoroughly test your apps with different memory constrains and devices! The errors generated in such cases look like this:
54
54
`Error: com.tns.NativeScriptException: Attempt to use cleared object reference id=<some-object-id-number>`
Copy file name to clipboardExpand all lines: docs/core-concepts/android-runtime/metadata/accessing-packages.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -43,7 +43,7 @@ To find out the package name of an Android class, refer to the [Android SDK Refe
43
43
44
44
For example, if you need to work with the Google API for Google Maps, after following the installation guide, you may need to access packages from the plugin like `com.google.android.gms.maps`, which you can find a reference for at [Google APIs for Android Reference](https://developers.google.com/android/reference/com/google/android/gms/maps/package-summary)
45
45
46
-
> **Note:** To have access and Intellisense for the native APIs with **NativeScript + TypeScript** or **NativeScript + Angular** projects, you have to add a dev dependency to `tns-platform-declarations`. More details about accessing native APIs with TypeScript can be found [here]({% slug access-native-apis %}#intellisense-and-access-to-native-apis-via-typescript).
46
+
> **Note:** To have access and Intellisense for the native APIs with **NativeScript + TypeScript** or **NativeScript + Angular** projects, you have to add a dev dependency to `@nativescript/types`. More details about accessing native APIs with TypeScript can be found [here]({% slug access-native-apis %}#intellisense-and-access-to-native-apis-via-typescript).
47
47
48
48
49
49
> **Note:****(Experimental)** Alternatively, to get Intellisense for the native APIs based on the available Android Platform SDK and imported Android Support packages (added by default to your Android project), supply the `--androidTypings` flag with your `tns run | build android` command. The resulting `android.d.ts` file can then be used to provide auto-completion.
Copy file name to clipboardExpand all lines: docs/core-concepts/android-runtime/metadata/generating-typescript-declarations.md
+5-5
Original file line number
Diff line number
Diff line change
@@ -29,14 +29,14 @@ The above is a bad practice for two reasons:
29
29
30
30
### The Good Practice
31
31
32
-
To resolve the above, in NativeScript, there is a developer dependency called [tns-platform-declarations].(https://preview.npmjs.com/package/tns-platform-declarations) After the intial instalation and setup, you could directly access the `android` namespace from the Android SDK.
32
+
To resolve the above, in NativeScript, there is a developer dependency called [@nativescript/types].(https://preview.npmjs.com/package/@nativescript/types) After the intial instalation and setup, you could directly access the `android` namespace from the Android SDK.
33
33
```TypeScript
34
-
// npm i tns-platform-declarations --save-dev
35
-
// follow the setup instructions at https://preview.npmjs.com/package/tns-platform-declarations
34
+
// npm i @nativescript/types --save-dev
35
+
// follow the setup instructions at https://preview.npmjs.com/package/@nativescript/types
36
36
let androidContext =android.content.Context;
37
37
```
38
38
39
-
The `tns-platform-declarations` plugin is providing access to the Android SDK. The plugin comes with pre-generated TypeScript declaration files for all API levels from 17 to 27 exclusive (detailed usage instructions in [this documentation section](../../accessing-native-apis-with-javascript#intellisense-and-access-to-the-native-apis-via-typescript)). In cases, where we need a declaration file for a third-party library or newer API (e.g. API 28) we can generate our own definitions using the **[Android DTS generator](#android-dts-generator)**.
39
+
The `@nativescript/types` plugin is providing access to the Android SDK. The plugin comes with pre-generated TypeScript declaration files for all API levels from 17 to 27 exclusive (detailed usage instructions in [this documentation section](../../accessing-native-apis-with-javascript#intellisense-and-access-to-the-native-apis-via-typescript)). In cases, where we need a declaration file for a third-party library or newer API (e.g. API 28) we can generate our own definitions using the **[Android DTS generator](#android-dts-generator)**.
40
40
41
41
## Android DTS Generator
42
42
@@ -154,4 +154,4 @@ By repeating the steps above, we've found that:
154
154
- Android support 23 typings(built with super jar from Android API 23) can be reused until Android API 25
155
155
- Android support 26 typings(built with super jar from Android API 26) can be reused for API 26 and 27
156
156
157
-
The corresponding typings files can be found in the `tns-platform-declarations` package. The repo's [Makefile](https://github.com/NativeScript/android-dts-generator/blob/master/Makefile) can be used as a reference for creating these typings files.
157
+
The corresponding typings files can be found in the `@nativescript/types` package. The repo's [Makefile](https://github.com/NativeScript/android-dts-generator/blob/master/Makefile) can be used as a reference for creating these typings files.
0 commit comments