mcpField
R
react-native-architecture

react-native-architecture

github.com/wshobson开发41.9k15.3k 次安装2 周前更新
代码仓库

关于 react-native-architecture

面向移动应用开发者的 React Native 与 Expo 架构指南,涵盖项目结构、导航、状态管理、原生模块、离线优先设计、性能与发布配置。

主要功能

  1. 01React Native 与 Expo 项目结构
  2. 02导航模式
  3. 03状态管理指导
  4. 04原生模块集成
  5. 05离线优先架构
  6. 06性能与 CI/CD 指导

适用场景

  1. 01启动 React Native 或 Expo 项目
  2. 02构建复杂导航
  3. 03集成原生 API
  4. 04开发离线优先的移动应用

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/wshobson/agents --skill react-native-architecture

安装后在 Claude Code 中输入/react-native-architecture确认已加载。

附带文件references/details.md

详细介绍

React Native 架构

适用于使用 Expo 进行 React Native 开发的生产级模式,包括导航、状态管理、原生模块和离线优先架构。

何时使用本技能

  • 启动新的 React Native 或 Expo 项目
  • 实现复杂的导航模式
  • 集成原生模块和平台 API
  • 构建离线优先的移动应用
  • 优化 React Native 性能
  • 为移动端发布设置 CI/CD

核心概念

1. 项目结构
src/
├── app/                    # Expo Router screens
│   ├── (auth)/            # Auth group
│   ├── (tabs)/            # Tab navigation
│   └── _layout.tsx        # Root layout
├── components/
│   ├── ui/                # Reusable UI components
│   └── features/          # Feature-specific components
├── hooks/                 # Custom hooks
├── services/              # API and native services
├── stores/                # State management
├── utils/                 # Utilities
└── types/                 # TypeScript types
2. Expo 与 Bare React Native
特性ExpoBare RN
设置复杂度低高
原生模块EAS Build手动链接
OTA 更新内置手动设置
构建服务EAS自定义 CI
自定义原生代码Config plugins直接访问

快速开始

# Create new Expo project
npx create-expo-app@latest my-app -t expo-template-blank-typescript

# Install essential dependencies
npx expo install expo-router expo-status-bar react-native-safe-area-context
npx expo install @react-native-async-storage/async-storage
npx expo install expo-secure-store expo-haptics
// app/_layout.tsx
import { Stack } from 'expo-router'
import { ThemeProvider } from '@/providers/ThemeProvider'
import { QueryProvider } from '@/providers/QueryProvider'

export default function RootLayout() {
  return (
    <QueryProvider>
      <ThemeProvider>
        <Stack screenOptions={{ headerShown: false }}>
          <Stack.Screen name="(tabs)" />
          <Stack.Screen name="(auth)" />
          <Stack.Screen name="modal" options={{ presentation: 'modal' }} />
        </Stack>
      </ThemeProvider>
    </QueryProvider>
  )
}

详细模式与完整示例

详细的模式文档位于 references/details.md。当上述导航层级不够用时,请阅读该文件。

最佳实践

推荐做法
  • 使用 Expo - 更快的开发、OTA 更新、托管的原生代码
  • 用 FlashList 替代 FlatList - 长列表性能更佳
  • 记忆化组件 - 防止不必要的重新渲染
  • 使用 Reanimated - 在原生线程上实现 60fps 动画
  • 在真机上测试 - 模拟器会遗漏真实环境中的问题
避免做法
  • 不要使用内联样式 - 使用 StyleSheet.create 以提升性能
  • 不要在渲染中获取数据 - 使用 useEffect 或 React Query
  • 不要忽视平台差异 - 在 iOS 和 Android 上都进行测试
  • 不要在代码中存储密钥 - 使用环境变量
  • 不要跳过错误边界 - 移动端崩溃的代价很严重

评论

支持 Markdown