Skip to content

Commit 4e4de8c

Browse files
OmbuwebNathanWalkerSeanKelly369
authored
docs: initial content for Adding Native Code (#24)
Co-authored-by: Nathan Walker <[email protected]> Co-authored-by: Sean Kelly <[email protected]>
1 parent 572646d commit 4e4de8c

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

content/guide/adding-native-code.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
title: Adding custom native code to a project
3+
---
4+
5+
6+
NativeScript allows you to access any native APIs anytime in your app. If the native API you need is not exposed through [@nativescript/core](https://docs.nativescript.org/understanding-packages#nativescript-core) or [third party plugins](https://market.nativescript.org/) or [@nativescript/* plugins](https://docs.nativescript.org/plugins/index.html)), you can add it to your project and access it right away in TypeScript.
7+
8+
9+
1. Add native code to [App_Resources](/project-structure/app-resources). For example, see [Adding Java/Kotlin code to an application](/project-structure/app-resources#adding-java-kotlin-code-to-an-application) and [Adding ObjectiveC/Swift Code to an application](/project-structure/app-resources#adding-objectivec-swift-code-to-an-application)
10+
11+
2. Generate types for the added APIs
12+
For iOS types run:
13+
14+
```cli
15+
ns typings ios
16+
```
17+
18+
For Android run:
19+
20+
```cli
21+
ns typings android --jar <.jar path>
22+
```
23+
24+
3. Reference the generated types in [references.d.ts](/project-structure/references-d-ts-in-nativescript)
25+
26+
4. You can now code (_strongly typed_) against the platform native APIs. For various examples on how to interact with native API's in JavaScript/TypeScript, visit the [Subclassing](/guide/subclassing/), [iOS Marshalling](/guide/marshalling/nativescript-ios-marshalling) and [Android Marshalling](/guide/marshalling/nativescript-android-marshalling) pages
27+
28+
:::details Additional Resources
29+
30+
- [Android d.ts Generator](https://github.com/NativeScript/android-dts-generator), for advanced types generation for Android
31+
32+
:::

content/sidebar.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,10 @@ export default [
220220
{
221221
text: 'Advanced Concepts',
222222
items: [
223+
{
224+
text: 'Adding Native Code',
225+
link: '/guide/adding-native-code'
226+
},
223227
{
224228
text: 'Data Binding',
225229
link: '/guide/data-binding',

0 commit comments

Comments
 (0)