1---2name: nativescript-cursorrules-prompt-file3description: "Apply for nativescript-cursorrules-prompt-file. --- description: Applies general NativeScript best practices. globs: **/*.tsx, **/*.ts, **/*.vue, **/*.svelte, src/**/*.ts, app/**/*.ts, src/**/*.tsx, app/**/*.tsx, src/**/*.vue, app/**/*.vue, src/**/"4source: "cursorrules"5---67# nativescript-cursorrules-prompt-file89---10description: Applies general NativeScript best practices.11globs: **/*.tsx, **/*.ts, **/*.vue, **/*.svelte, src/**/*.ts, app/**/*.ts, src/**/*.tsx, app/**/*.tsx, src/**/*.vue, app/**/*.vue, src/**/*.svelte12---13- Organize code using modular components and services for maintainability.14- Use platform-specific files (`.ios.ts`, `.android.ts`) when code exceeds 20 platform-specific lines.15- 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.16- Prefix platform-specific variables with `ios` or `android` (e.g., `iosButtonStyle`).17- Name custom components and styles descriptively (`primaryButtonStyle`, `userProfileView`).18- Use `@NativeClass()` when extending native classes when needed19- For iOS, when extending native classes, always use `static ObjCProtocols = [AnyUIKitDelegate];` to declare custom delegates if a delegate is required or used.20- 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.21- Favor `__ANDROID__` and `__APPLE__` for conditional platform code with tree-shaking.22- Track and clean up all timers (`setTimeout`, `setInterval`) to avoid memory leaks.23- Always TailwindCSS as the CSS Framework using `"@nativescript/tailwind": "^2.1.0"` for consistent styling paired with `"tailwindcss": "~3.4.0"`.24- Add ios: and android: style variants for platform-specific styling, addVariant('android', '.ns-android &'), addVariant('ios', '.ns-ios &');25- darkMode: ['class', '.ns-dark']26- 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.27- Use `visibility: 'hidden'` for elements that should not affect layout when hidden.28- Try to avoid deeply nesting layout containers but instead use `GridLayout` wisely to setup complex layouts.29- Avoid direct manipulation of the visual tree during runtime to minimize rendering overhead.30- Optimize images using compression tools like TinyPNG to reduce memory and app size.31- Clean the project (`ns clean`) after modifying files in `App_Resources` or `package.json`.32- Reuse components and styles to avoid duplication.33- Use template selectors (`itemTemplateSelector`) for conditional layouts in `ListView` and `RadListView`.34- Minimize heavy computations in UI bindings or methods.35- Only if using plain xml bindings, use `Observable` or `ObservableArray` properties to reflect state changes efficiently.36- When using Angular, React, Solid, Svelte or Vue, always leverage their respective state management, lifecycle hooks, rendering optimizations and reactive bindings for optimal performance.37