platform-code

0xsend 的头像作者 0xsend

Web 与本机的特定于平台的代码模式(.native.tsx 文件)。在创建需要针对 Web 和 React Native 的不同实现的 React 组件时使用。

📖 中文导读:Web 与本机的特定于平台的代码模式(.native.tsx 文件)。在创建需要针对 Web 和 React Native 的不同实现的 React 组件时使用。 以下正文为该技能的原始 SKILL.md 内容(英文),上方安装命令可直接使用。

name: platform-code description: Platform-specific code patterns for web vs native (.native.tsx files). Use when creating React components that need different implementations for web and React Native.

Platform-Specific Code Pattern

Send uses file extension conventions to handle web vs. native differences.

File Naming

File Purpose
ComponentName.tsx Shared logic OR web-specific implementation
ComponentName.native.tsx React Native specific implementation

The bundler automatically resolves the correct file based on platform.

When to Create Platform Files

Create .native.tsx variants when:

  • UI needs different native implementation
  • Using platform-specific APIs or components
  • Optimizing for platform performance characteristics
  • Handling platform-specific UX patterns

Example: TokenActivityFeed

TokenActivityFeed.tsx        # Web: uses RecyclerList (virtualized)
TokenActivityFeed.native.tsx # Native: uses FlatList (RN optimized)

Both files export the same API - platform bundler picks the right one.

Guidelines

  1. Keep APIs identical between platform variants
  2. Share types/interfaces in a separate file when needed
  3. Platform-specific hooks: useX.ts / useX.native.ts
  4. Prefer shared code; only split when necessary