1k-cross-platform
Cross-platform development patterns for OneKey. Use when writing platform-specific code, handling platform differences, or working with native/web/desktop/extension platforms. Triggers on platform, native, web, desktop, extension, iOS, Android, Electron, platformEnv, .native.ts, .web.ts, .desktop.ts, .ext.ts, cross-platform, multi-platform.
Best use case
1k-cross-platform is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Cross-platform development patterns for OneKey. Use when writing platform-specific code, handling platform differences, or working with native/web/desktop/extension platforms. Triggers on platform, native, web, desktop, extension, iOS, Android, Electron, platformEnv, .native.ts, .web.ts, .desktop.ts, .ext.ts, cross-platform, multi-platform.
Teams using 1k-cross-platform 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/1k-cross-platform/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How 1k-cross-platform Compares
| Feature / Agent | 1k-cross-platform | 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?
Cross-platform development patterns for OneKey. Use when writing platform-specific code, handling platform differences, or working with native/web/desktop/extension platforms. Triggers on platform, native, web, desktop, extension, iOS, Android, Electron, platformEnv, .native.ts, .web.ts, .desktop.ts, .ext.ts, cross-platform, multi-platform.
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
# Cross-Platform Development
Patterns for writing platform-specific code in OneKey.
## Platform Extensions
Use platform extensions for platform-specific implementations:
| Extension | Platform |
|-----------|----------|
| `.native.ts` | React Native (iOS/Android) |
| `.web.ts` | Web platform |
| `.desktop.ts` | Desktop (Electron) |
| `.ext.ts` | Browser extension |
## Platform Detection
**ALWAYS use `platformEnv` for platform detection:**
```typescript
// ✅ CORRECT
import platformEnv from '@onekeyhq/shared/src/platformEnv';
if (platformEnv.isNative) {
// React Native specific code
}
if (platformEnv.isWeb) {
// Web specific code
}
if (platformEnv.isDesktop) {
// Desktop (Electron) specific code
}
if (platformEnv.isExtension) {
// Browser extension specific code
}
// ❌ FORBIDDEN - Direct platform checks
if (typeof window !== 'undefined') { }
if (process.env.REACT_APP_PLATFORM === 'web') { }
```
## Available Platform Flags
```typescript
platformEnv.isNative // React Native (iOS or Android)
platformEnv.isWeb // Web browser
platformEnv.isDesktop // Electron desktop app
platformEnv.isExtension // Browser extension
platformEnv.isIOS // iOS specifically
platformEnv.isAndroid // Android specifically
platformEnv.isWebEmbed // Embedded web components
```
## Platform-Specific File Structure
```
MyComponent/
├── index.ts # Main entry, common logic
├── MyComponent.tsx # Shared component
├── MyComponent.native.tsx # React Native specific
├── MyComponent.web.tsx # Web specific
├── MyComponent.desktop.tsx # Desktop specific
└── MyComponent.ext.tsx # Extension specific
```
The bundler automatically resolves the correct file based on platform.
## Example: Platform-Specific Storage
```typescript
// storage.ts - shared interface
export interface IStorage {
get(key: string): Promise<string | null>;
set(key: string, value: string): Promise<void>;
}
// storage.native.ts
import AsyncStorage from '@react-native-async-storage/async-storage';
export const storage: IStorage = {
get: (key) => AsyncStorage.getItem(key),
set: (key, value) => AsyncStorage.setItem(key, value),
};
// storage.web.ts
export const storage: IStorage = {
get: async (key) => localStorage.getItem(key),
set: async (key, value) => localStorage.setItem(key, value),
};
// storage.desktop.ts
import { ipcRenderer } from 'electron';
export const storage: IStorage = {
get: (key) => ipcRenderer.invoke('storage:get', key),
set: (key, value) => ipcRenderer.invoke('storage:set', key, value),
};
```
## Detailed Guide
For comprehensive cross-platform patterns and platform considerations, see [cross-platform.md](references/rules/cross-platform.md).
Topics covered:
- Platform extensions and file structure
- Platform detection with `platformEnv`
- Platform-specific imports
- Platform considerations (Extension, Mobile, Desktop, Web)
- Real-world examples
- Cross-platform checklist
## Platform Considerations
### Extension (Chrome, Firefox, Edge, Brave)
- MV3/service worker lifetimes, permissions, CSP, background script limitations
### Mobile (iOS/Android)
- WebView limitations, native modules, background/foreground states, deep linking
### Desktop (Electron)
- Security boundaries, IPC communication, file system access
### Web
- CORS restrictions, storage limitations, XSS prevention, bundle size
## Checklist
- [ ] Platform-specific code uses correct file extension
- [ ] Uses `platformEnv` instead of direct checks
- [ ] Common logic extracted to shared files
- [ ] Tested on all target platforms
## Related Skills
- `/1k-coding-patterns` - General coding patterns
- `/1k-architecture` - Project structure and importsRelated Skills
1k-platform-requirements
Documents minimum SDK/OS version requirements for all OneKey platforms. Use when checking platform compatibility, understanding deployment targets, verifying version requirements, or when user asks if their device can run the project. Triggers on minimum version, SDK version, API level, deployment target, platform requirements, iOS version, Android version, Chrome version, Electron version, can I run, environment check, device compatibility, check environment.
hig-platforms
Apple Human Interface Guidelines for platform-specific design.
agent-platforms
Guide for multi-platform skill compatibility across Claude Code, Codex, Gemini CLI, Cursor, GitHub Copilot, and other AI coding agents.
u01549-constraint-compilation-for-civic-participation-platforms
Operate the "Constraint Compilation for civic participation platforms" capability in production for civic participation platforms workflows. Use when mission execution explicitly requires this capability and outcomes must be reproducible, policy-gated, and handoff-ready.
symfony:api-platform-versioning
Use when symfony api platform versioning
symfony:api-platform-tests
Use when symfony api platform tests
symfony:api-platform-state-providers
Use when symfony api platform state providers
symfony:api-platform-serialization
Use when symfony api platform serialization
symfony:api-platform-security
Use when symfony api platform security
symfony:api-platform-resources
Use when symfony api platform resources
symfony:api-platform-filters
Use when symfony api platform filters
symfony:api-platform-dto-resources
Use when symfony api platform dto resources