Advanced Concepts
Adding custom native code to a project
NativeScript allows you to access any native API anytime in your app.
If the native API you need is not exposed through @nativescript/core, third party plugins or @nativescript/* plugins), you can add it to your project and access it right away in TypeScript.
Ever since NativeScript 8.8, you can use a single command to add platform language files and have them auto configured ready to use with:
bash
ns native add swift AwesomeClass
# Swift file 'nativescript-project/App_Resources/iOS/src/AwesomeClass.swift' generated successfully.
ns native add objective-c OtherAwesomeClass
# Module map 'nativescript-project/App_Resources/iOS/src/module.modulemap' has been updated with the header 'OtherAwesomeClass.h'.
ns native add kotlin com.company.AwesomeClass
# Kotlin file 'nativescript-project/App_Resources/Android/src/main/java/com/company/AwesomeClass.kt' generated successfully.
ns native add java com.company.OtherAwesomeClass
# Java file 'nativescript-project/App_Resources/Android/src/main/java/com/company/OtherAwesomeClass.java' generated successfully.
- You can also manually add native code to App_Resources:
- Optionally generate TypeScript types for the added APIs
Additionally, NativeScript also supports Jetpack Compose and SwiftUI through plugins.
- Previous
- Previewing visionOS from StackBlitz