kotlin

Designs and reviews Kotlin and Android APIs with type-safe modeling and explicit async boundaries.

172|8|Updated Apr 13, 2026
One-click install
npx skills add https://github.com/margelo/react-native-skills --skill kotlin-margelo
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: kotlin
Source: https://github.com/margelo/react-native-skills/tree/main/skills/kotlin
Command: npx skills add https://github.com/margelo/react-native-skills --skill kotlin-margelo

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Kotlin and Android codebases often suffer from loose type modeling, hidden thread hops, blocking work disguised as properties, and race-prone async code. This Skill provides concrete design rules and review criteria for writing idiomatic, type-safe Kotlin APIs, especially for React Native Nitro Module implementations. ## Core Features & Use Cases - Type-Safe API Design: Models state variants with sealed interfaces and data classes instead of nullable-field grab bags, enforcing compile-time narrowing. - Async and Threading Discipline: Guides when to use coroutines, owned dispatchers, or synchronous code, and forbids runBlocking, delay-based race fixes, and excessive thread hops. - Nitro Module Integration: Covers HybridObject spec extension, Promise.async/Promise.parallel usage, Task await adapters, and annotation requirements for Kotlin-backed React Native modules. - Use Case: When implementing a Kotlin HybridObject for a barcode scanner Nitro Module, use this Skill to model scanned results as a sealed interface, expose async work via Promise.async, and keep conversions in dedicated extension files. ## Quick Start Use the kotlin skill to review my HybridDataScanner.kt implementation for type safety, threading, and Nitro conventions.

Frequently Asked Questions about kotlin

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I design type-safe Kotlin APIs with sealed classes?

Model each state variant as its own type under a sealed interface or sealed class, keeping related fields non-null on the variant where they are valid. Avoid one data class with many nullable fields, since repeated null checks signal the model is too loose.

When should I use coroutines vs synchronous code in Kotlin?

Use coroutines for naturally suspending APIs and Android I/O with existing coroutine support. Keep quick, deterministic, local work synchronous, and use owned dispatchers or Nitro Promise.parallel for CPU-bound work that should not run on the caller thread.

How do I implement a Kotlin HybridObject for Nitro Modules?

Extend the generated Hybrid*Spec class and add @Keep plus @DoNotStrip annotations. Use Promise.async for suspending or I/O work, Promise.parallel for CPU-bound work, and Promise<Unit> for Promise<void> return types.

Can I use runBlocking in Kotlin library or Android code?

No, runBlocking should not appear in library code, property getters, setters, or JS-facing entry points. If a value requires waiting on another thread, redesign it as an async method, listener, Flow, or Promise-based API instead.

Why should Kotlin files contain only one top-level type?

One type per file keeps code splitting, maintainability, and diffs clean. Extensions and conversions belong in separate named files like Barcode+toScannedCode.kt, and helpers or Android preflight checks should live in focused files rather than broad Utils.kt catch-alls.

How do I bridge Google Task callbacks to Kotlin coroutines?

Write a generic suspend adapter in its own extension file such as Task+await.kt, then call it from Promise.async { task.await() }. Avoid hand-wiring addOnSuccessListener or addOnFailureListener directly into public HybridObject methods.