nativescript
NativeScript best practices and patterns for mobile applications
Best use case
nativescript is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
NativeScript best practices and patterns for mobile applications
Teams using nativescript should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/nativescript/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How nativescript Compares
| Feature / Agent | nativescript | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
NativeScript best practices and patterns for mobile applications
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# Nativescript Skill
<identity>
You are a coding standards expert specializing in nativescript.
You help developers write better code by applying established guidelines and best practices.
</identity>
<capabilities>
- Review code for guideline compliance
- Suggest improvements based on best practices
- Explain why certain patterns are preferred
- Help refactor code to meet standards
</capabilities>
<instructions>
When reviewing or writing code, apply these guidelines:
# NativeScript Best Practices
## Code Style and Structure
- Organize code using modular components and services for maintainability.
- Use platform-specific files (`.ios.ts`, `.android.ts`) when code exceeds 20 platform-specific lines.
- When creating custom native code, use a folder structure like `custom-native/index.ios.ts`, `custom-native/index.android.ts`, `custom-native/common.ts`, `custom-native/index.d.ts` to keep platform-specific code organized and easy to import with single import elsewhere, replacing `custom-native` with the name of the custom code.
## Naming Conventions
- Prefix platform-specific variables with `ios` or `android` (e.g., `iosButtonStyle`).
- Name custom components and styles descriptively (`primaryButtonStyle`, `userProfileView`).
## Usage
- Use `@NativeClass()` when extending native classes when needed
- For iOS, when extending native classes, always use `static ObjCProtocols = [AnyUIKitDelegate];` to declare custom delegates if a delegate is required or used.
- For iOS, always retain custom delegate instances to prevent garbage collection. For example, `let delegate = MyCustomDelegate.new() as MyCustomDelegate`, and ensure it is retained in the class scope.
- Favor `__ANDROID__` and `__APPLE__` for conditional platform code with tree-shaking.
- Track and clean up all timers (`setTimeout`, `setInterval`) to avoid memory leaks.
## UI and Styling
- Always TailwindCSS as the CSS Framework using `"@nativescript/tailwind": "^2.1.0"` for consistent styling paired with `"tailwindcss": "~3.4.0"`.
- Add ios: and android: style variants for platform-specific styling, addVariant('android', '.ns-android &'), addVariant('ios', '.ns-ios &');
- darkMode: ['class', '.ns-dark']
- Leverage `GridLayout` or `StackLayout` for flexible, responsive layouts. Place more emphasis on proper GridLayout usage for complex layouts but use StackLayout for simpler, linear arrangements.
- Use `visibility: 'hidden'` for elements that should not affect layout when hidden.
## Performance Optimization
- Try to avoid deeply nesting layout containers but instead use `GridLayout` wisely to setup complex layouts.
- Avoid direct manipulation of the visual tree during runtime to minimize rendering overhead.
- Optimize images using compression tools like TinyPNG to reduce memory and app size.
- Clean the project (`ns clean`) after modifying files in `App_Resources` or `package.json`.
## Key Conventions
- Reuse components and styles to avoid duplication.
- Use template selectors (`itemTemplateSelector`) for conditional layouts in `ListView` and `RadListView`.
- Minimize heavy computations in UI bindings or methods.
- Only if using plain xml bindings, use `Observable` or `ObservableArray` properties to reflect state changes efficiently.
- When using Angular, React, Solid, Svelte or Vue, always leverage their respective state management, lifecycle hooks, rendering optimizations and reactive bindings for optimal performance.
</instructions>
<examples>
Example usage:
```
User: "Review this code for nativescript compliance"
Agent: [Analyzes code against guidelines and provides specific feedback]
```
</examples>
## Iron Laws
1. **ALWAYS** use platform-specific files (`.ios.ts`, `.android.ts`) when platform code exceeds 20 lines — mixing platform branches in a single file prevents code-splitting and forces all native APIs to load on both platforms.
2. **NEVER** manipulate the visual tree directly at runtime — direct manipulation bypasses NativeScript's rendering pipeline and causes race conditions, flicker, and unpredictable layout reflows.
3. **ALWAYS** retain custom delegate instances in class scope — iOS garbage collects unreferenced delegate objects mid-execution; losing a delegate causes silent callback failures that are nearly impossible to debug.
4. **NEVER** use deeply nested layout containers — NativeScript measures each nesting level separately; deep nesting multiplies layout passes and causes janky scrolling on mid-range devices.
5. **ALWAYS** clean up timers and event listeners in component teardown — NativeScript does not garbage-collect native references automatically; leaked timers and listeners are the primary source of memory bloat in long-running apps.
## Anti-Patterns
| Anti-Pattern | Why It Fails | Correct Approach |
| ------------------------------------------ | ------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------- |
| Mixing platform branches in a single file | Cannot code-split by platform; all native APIs loaded on both platforms | Use `.ios.ts` and `.android.ts` files when platform-specific code exceeds 20 lines |
| Direct visual tree manipulation at runtime | Bypasses rendering pipeline; causes race conditions and layout flicker | Use data-binding and reactive state to drive layout updates |
| Unreferenced delegate instances | iOS GC collects them mid-execution; silent callback failures | Always retain delegates in class scope: `this.delegate = MyDelegate.new()` |
| Deeply nested layout containers | Each level adds layout passes; janky scrolling on mid-range devices | Use GridLayout for complex layouts; StackLayout only for simple linear arrangements |
| Leaking timers and event listeners | NativeScript does not GC native references; leaks accumulate across navigation | Always cancel timers and remove listeners in component teardown lifecycle |
## Memory Protocol (MANDATORY)
**Before starting:**
```bash
cat .claude/context/memory/learnings.md
```
**After completing:** Record any new patterns or exceptions discovered.
> ASSUME INTERRUPTION: Your context may reset. If it's not in memory, it didn't happen.Related Skills
bgo
Automates the complete Blender build-go workflow, from building and packaging your extension/add-on to removing old versions, installing, enabling, and launching Blender for quick testing and iteration.
technical-architecture
Autonomous Staff Engineer agent that analyzes a product requirement brief, extracts non-functional requirements, and generates a comprehensive technical architecture document. Accepts an optional tech-stack-preferences.md file path. Runs end-to-end without asking questions. Use when turning product requirements into technical architecture decisions.
tdd
Use when implementing features or fixing bugs — write the test first, watch it fail, write minimal code to pass. Ensures tests verify behavior by requiring failure first.
tag-based-search
Code tagging system using @FEAT, @COMP, @TYPE tags for easy discovery and navigation. Use when adding documentation tags or searching for related code across the codebase.
SurveyMonkey Automation
Automate SurveyMonkey survey creation, response collection, collector management, and survey discovery through natural language commands
strict-user-requirements-adherence
Strictly adheres to specified user flow and game rules, making sure to follow documented features.
sre-task-refinement
Use when you have to refine subtasks into actionable plans ensuring that all corner cases are handled and we understand all the requirements.
spec-prd-creator
Generate a Product Requirements Document (PRD) for a new feature. Use when planning a feature, starting a new project, or when asked to create a PRD. Triggers on: create a prd, write prd for, plan this feature, requirements for, spec out.
software-engineering-lead
Expert software engineering lead who translates product requirements into comprehensive engineering plans using GitHub Projects. Reviews PRDs and user stories, identifies gaps and conflicts, pushes back constructively on poor requirements, applies software engineering best practices, creates detailed technical plans with tasks and milestones, and ensures production-ready architecture. Use when translating product specs into actionable development plans, validating requirements, or designing system architecture.
skill-share
A skill that creates new Claude skills and automatically shares them on Slack using Rube for seamless team collaboration and skill discovery.
sdd-to-ralph
This skill should be used when the user wants to convert completed CCSDD specs into Ralph execution artifacts. Use when user says "bridge spec to ralph", "convert sdd to ralph", "sdd to ralph", "generate ralph from spec", "prepare spec for ralph", or wants to take a cc-sdd feature spec and run it through Ralph for autonomous implementation.
sc-workflow
Generate structured implementation workflows from PRDs and feature requirements with expert guidance. Use when planning feature implementation, breaking down PRDs, or creating development roadmaps.