反应本机专家

文档 社区

技能解读

当前原文的自动摘译,尚未人工审校。

何时使用

从头开始构建新的 React Native 或 Expo 移动应用程序 设置导航(选项卡、堆栈、抽屉、深度链接) 集成本机模块或特定于平台的代码 优化列表性能(FlatList、SectionList) 处理 SafeArea、键盘避免或平台差异

核心工作流程

设置 - Scaffold with Expo,配置 TypeScript → 运行npx expo doctor以验证环境和 SDK 兼容性;在继续之前修复所有报告的问题 结构 — 按功能组织,设置路由(Expo Router 或 React Navigation) 实施 — 使用平台处理构建组件 → 在 iOS 模拟器和 Android 模拟器上验证;在继续优化之前检查 Metro 捆绑器输出是否有错误 - 使用 Flipper 或 React DevTools 优化列表、图像、内存 → 配置文件

错误恢复

Metro 捆绑器错误 → 使用 npx expo start --clear 清除缓存,然后重新启动 iOS 构建失败 → 检查 Xcode 日志 → 解决本机依赖项或配置问题 → 使用 npx expo run:ios 重建 Android 构建失败 → 检查 adb logcat 或 Gradle 输出 → 解决 SDK/NDK 版本不匹配 → 使用 npx expo run:android 未找到本机模块重建 → 运行 npx expo install <module> 以确保版本兼容,然后重建本机层

必须做

对可滚动列表使用 FlatList/SectionList(对于大数据,切勿使用 ScrollView) 对列表项实施 memo + useCallback,以防止不必要的重新渲染 将顶级内容包装在 SafeAreaView 中以表示设备凹口和安全区域 对表单和文本输入屏幕使用 KeyboardAvoidingView 处理导航堆栈中的 Android 后退按钮行为

绝对不能做

将 ScrollView 用于大型或动态列表(导致内存和性能问题) 广泛使用内联样式(每次渲染都会创建新样式对象) 硬编码维度(使用 Flex、Dimensions API 或响应式助手) 忽略事件侦听器和订阅的内存泄漏 跳过特定于平台的测试 - iOS 和 Android 之间的行为不同

流狐档案 运行与权限由流狐静态检查推断,不代表作者声明或实际测试结果。
领域
文档
作者声明的智能体
未找到明确声明;不据此推断已兼容或已测试
静态检查
88 / 100 · 启发式扫描,不代表运行安全
运行环境证据
未执行;当前没有隔离运行测试证据
作者 / 版本 / 许可证
@tomevault-io · 未声明许可证
上下文用量评级
低消耗
接入复杂程度
即装即用
是否需要外部接口密钥
不需要
兼容的系统
macOS · Linux · Windows
运行环境要求
未检出明确要求
检测到的文件与系统行为
  • 只读
  • 允许写入 / 修改
网络行为
仅限本地
安装命令数
无(仅作为资料)

需要注意: 未声明工具权限范围;实际权限由运行环境决定。

作者说明文件(原文) SKILL.md

# React Native Expert

Senior mobile engineer building production-ready cross-platform applications with React Native and Expo.

## When to Use

- Building a new React Native or Expo mobile app from scratch
- Setting up navigation (tabs, stacks, drawers, deep linking)
- Integrating native modules or platform-specific code
- Optimizing list performance (FlatList, SectionList)
- Handling SafeArea, keyboard avoidance, or platform differences
- Debugging Metro bundler, Xcode, or Gradle build issues
- Configuring Expo SDK projects

**Don't use when:** Building web-only apps, native Swift/Objective-C iOS apps, or native Kotlin/Java Android apps — use the appropriate platform-specific skills instead.

## Core Workflow

1. **Setup** — Scaffold with Expo, configure TypeScript → run `npx expo doctor` to verify environment and SDK compatibility; fix any reported issues before proceeding
2. **Structure** — Organize by feature, set up routing (Expo Router or React Navigation)
3. **Implement** — Build components with platform handling → verify on iOS simulator and Android emulator; check Metro bundler output for errors before moving on
4. **Optimize** — Optimize lists, images, memory → profile with Flipper or React DevTools
5. **Test** — Test on both platforms, prioritize real devices over simulators

### Error Recovery

- **Metro bundler errors** → Clear cache with `npx expo start --clear`, then restart
- **iOS build fails** → Check Xcode logs → resolve native dependency or provisioning issue → rebuild with `npx expo run:ios`
- **Android build fails** → Check `adb logcat` or Gradle output → resolve SDK/NDK version mismatch → rebuild with `npx expo run:android`
- **Native module not found** → Run `npx expo install <module>` to ensure compatible version, then rebuild native layers

## Key Patterns

### Optimized FlatList with memo + useCallback

```tsx
import React, { memo, useCallback } from 'react';
import { FlatList, View, Text, StyleSheet } from 'react-native';

type Item = { id: string; title: string };

const ListItem = memo(({ title, onPress }: { title: string; onPress: () => void }) => (
  <View style={styles.item}>
    <Text onPress={onPress}>{title}</Text>
  </View>
));

const keyExtractor = (item: Item) => item.id;

export function ItemList({ data }: { data: Item[] }) {
  const renderItem = useCallback(
    ({ item }: { item: Item }) => (
      <ListItem title={item.title} onPress={() => console.log(item.id)} />
    ),
    []
  );

  return (
    <FlatList
      data={data}
      renderItem={renderItem}
      keyExtractor={keyExtractor}
      removeClippedSubviews
      maxToRenderPerBatch={10}
    />
  );
}

const styles = StyleSheet.create({
  item: { padding: 16, borderBottomWidth: 1, borderBottomColor: '#eee' },
});
```

### SafeAreaView + Keyboard Avoidance

```tsx
import React from 'react';
import { SafeAreaView, KeyboardAvoidingView, Platform, TextInput, StyleSheet } from 'react-native';

export function SafeForm() {
  return (
    <SafeAreaView style={styles.container}>
      <KeyboardAvoidingView
        behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
        style={styles.inner}
      >
        <TextInput placeholder="Enter text" style={styles.input} />
      </KeyboardAvoidingView>
    </SafeAreaView>
  );
}

const styles = StyleSheet.create({
  container: { flex: 1, backgroundColor: '#fff' },
  inner: { padding: 16 },
  input: { borderWidth: 1, borderColor: '#ccc', borderRadius: 8, padding: 12 },
});
```

### Platform-Specific Code

```tsx
import { Platform, StyleSheet } from 'react-native';

const styles = StyleSheet.create({
  container: {
    ...Platform.select({
      ios: { shadowColor: '#000', shadowOpacity: 0.25, shadowRadius: 4 },
      android: { elevation: 4 },
      default: {},
    }),
  },
});
```

## Constraints

### MUST DO

- Use FlatList/SectionList for scrollable lists (never ScrollView for large data)
- Implement `memo` + `useCallback` for list items to prevent unnecessary re-renders
- Wrap top-level content in `SafeAreaView` for device notches and safe areas
- Use `KeyboardAvoidingView` for forms and text input screens
- Handle Android back button behavior in navigation stacks
- Test on both iOS and Android — platform differences are common
- Use `npx expo install` (not `npm install`) for native modules to ensure SDK compatibility

### MUST NOT DO

- Use ScrollView for large or dynamic lists (causes memory and performance issues)
- Use inline styles extensively (creates new style objects every render)
- Hardcode dimensions (use flex, Dimensions API, or responsive helpers)
- Ignore memory leaks from event listeners and subscriptions
- Skip platform-specific testing — behavior differs between iOS and Android
- Use `waitFor`/`setTimeout` for animations (use `react-native-reanimated` instead)
- Render heavy lists without `removeClippedSubviews` or `maxToRenderPerBatch`

## Project Setup Checklist

- [ ] Expo SDK version matches across `package.json` and native binaries
- [ ] `npx expo doctor` passes with no issues
- [ ] TypeScript configured with strict mode
- [ ] Navigation library chosen (Expo Router recommended for file-based routing)
- [ ] Platform-specific folders (`ios/`, `android/`) exist and build successfully
- [ ] ESLint + Prettier configured for `.tsx`/`.ts` files
- [ ] Metro config customized if needed (asset extensions, resolver config)

## Performance Optimization

| Issue | Solution |
|-------|----------|
| Janky scrolling | Use `FlatList` with `removeClippedSubviews`, `maxToRenderPerBatch` |
| Slow re-renders | Wrap components with `memo`, use `useCallback` for handlers |
| Image loading delays | Use `react-native-fast-image`, implement caching |
| Navigation lag | Lazy-load screens, defer heavy computations |
| Memory leaks | Clean up subscriptions in cleanup functions, use `useEffect` return |
| Large bundle size | Use `@expo/config-plugins`, tree-shake unused dependencies |

## Cross-Team Integration

**Related Skills:** `react-expert`, `flutter-expert`, `test-driven-development`, `systematic-debugging`, `mobile-code-impact-assessment`

**Used By:** Any agent building mobile features, especially frontend engineers in DevForge AI or dedicated mobile engineering teams.

---
> Source: [Construct-AI-primary/z-docs-paperclip](https://github.com/Construct-AI-primary/z-docs-paperclip) — distributed by [TomeVault](https://tomevault.io).
<!-- tomevault:4.0:skill_md:2026-05-22 -->

讨论

基于 GitHub Discussions。登录 GitHub 即可参与讨论、点赞、订阅更新。