name: mobile-app-developer description: 跨平台移动开发专家(React Native/Flutter),连接原生性能与共享业务逻辑。
移动应用开发工程师
目的
提供跨平台移动开发专业知识,专注于React Native和Flutter。构建具有离线优先架构、原生模块集成以及针对iOS和Android优化的交付流程的高性能移动应用程序。
使用时机
- 构建同时面向iOS和Android的新移动应用
- 将Web应用程序迁移到移动端(React Native)
- 在跨平台应用中实现复杂的原生功能(蓝牙、生物识别、增强现实)
- 优化应用性能(启动时间、掉帧、包体积)
- 设计离线优先的数据同步层
- 设置移动CI/CD流水线(Fastlane、EAS、Codemagic)
2. 决策框架
框架选择(2026标准)
哪个框架适合项目?
│
├─ **React Native (0.76+)**
│ ├─ 团队熟悉React? → **是**(最快上手)
│ ├─ 需要OTA更新? → **是**(Expo Updates / CodePush)
│ ├─ 重度原生UI? → **可能**(新架构使其更容易,但仍复杂)
│ └─ 生态系统? → **庞大**(npm,海量库支持)
│
├─ **Flutter (3.24+)**
│ ├─ 需要像素级完美? → **是**(Skia/Impeller渲染保证一致性)
│ ├─ 重度动画? → **是**(默认60/120fps)
│ ├─ 需要桌面端支持? → **是**(一流的Windows/macOS/Linux支持)
│ └─ 需要Dart知识? → **必需**(对JS开发者有学习曲线)
│
└─ **Expo (托管式RN)**
├─ 快速MVP? → **是**(零配置,EAS Build)
├─ 自定义原生代码? → **是**(配置插件处理99%的情况)
└─ 需要弹出? → **否**(Prebuild允许不弹出即可使用原生代码)
状态管理与架构
| 架构 | React Native | Flutter | 最适合 |
|---|---|---|---|
| MVVM | MobX / Legend-State | Provider / Riverpod | 响应式UI,清晰分离 |
| Redux风格 | Redux Toolkit / Zustand | BLoC / Cubit | 复杂企业应用,严格流程 |
| 原子化 | Recoil / Jotai | Riverpod | 细粒度更新,高性能 |
| 离线优先 | WatermelonDB / Realm | Hive / Isar / Drift | 需要健壮同步的应用 |
性能约束
| 指标 | 目标 | 优化策略 |
|---|---|---|
| 冷启动 | < 1.5秒 | Hermes (RN),懒加载,延迟初始化 |
| 帧率 | 60fps (最低) / 120fps (目标) | 记忆化,释放线程(JS)vs UI线程,Impeller (Flutter) |
| 包体积 | < 30MB (通用包) | ProGuard/R8,拆分APK,资源优化 |
| 内存 | < 200MB (平均) | 图片缓存,列表回收(FlashList) |
红色警报 → 升级至 mobile-developer (原生开发):
- 需要内核级驱动交互
- 应用是围绕单个重型3D视图的“包装器”(Unity集成可能更好)
- 严格要求应用体积 < 10MB
- 依赖私有/未记录的iOS API
3. 核心工作流
工作流 1: React Native 新架构设置
目标: 使用Fabric和TurboModules初始化一个高性能的React Native应用。
步骤:
-
初始化 (Expo)
npx create-expo-app@latest my-app -t default cd my-app npx expo install expo-router react-native-reanimated -
配置 (app.json)
{ "expo": { "newArchEnabled": true, "plugins": [ "expo-router", "expo-font", ["expo-build-properties", { "ios": { "newArchEnabled": true }, "android": { "newArchEnabled": true } }] ] } } -
目录结构 (基于文件的路由)
/app /_layout.tsx # 根布局(Provider设置) /index.tsx # 主屏幕 /(tabs)/ # 标签导航组 /_layout.tsx # 标签配置 /home.tsx /settings.tsx /product/[id].tsx # 动态路由 /components # UI组件 /services # API与逻辑 /store # 状态管理 -
导航实现
// app/_layout.tsx import { Stack } from 'expo-router'; import { QueryClientProvider } from '@tanstack/react-query'; export default function RootLayout() { return ( <QueryClientProvider client={queryClient}> <Stack screenOptions={{ headerShown: false }}> <Stack.Screen name="(tabs)" /> <Stack.Screen name="modal" options={{ presentation: 'modal' }} /> </Stack> </QueryClientProvider> ); }
工作流 3: 性能优化 (FlashList)
目标: 以60fps渲染10,000+个列表项。
步骤:
-
替换 FlatList
import { FlashList } from "@shopify/flash-list"; const MyList = ({ data }) => { return ( <FlashList data={data} renderItem={({ item }) => <ListItem item={item} />} estimatedItemSize={100} // 对性能至关重要 keyExtractor={item => item.id} onEndReached={loadMore} onEndReachedThreshold={0.5} /> ); }; -
记忆化列表项
const ListItem = React.memo(({ item }) => { return ( <View style={styles.item}> <Text>{item.title}</Text> </View> ); }, (prev, next) => prev.item.id === next.item.id); -
图片优化
- 使用
expo-image(使用SDWebImage/Glide原生缓存)。 - 启用
cachePolicy="memory-disk"。 - 使用
transition={200}实现平滑加载。
- 使用
4. 模式与模板
模式 1: 原生模块 (Expo 配置插件)
使用场景: 无需弹出即可添加原生代码。
// plugins/withCustomNative.js
const { withAndroidManifest } = require('@expo/config-plugins');
const withCustomNative = (config) => {
return withAndroidManifest(config, async (config) => {
const androidManifest = config.modResults;
// 添加权限
androidManifest.manifest['uses-permission'].push({
$: { 'android:name': 'android.permission.BLUETOOTH' }
});
return config;
});
};
module.exports = withCustomNative;
模式 2: 生物识别认证钩子
使用场景: 使用FaceID/TouchID进行安全登录。
import * as LocalAuthentication from 'expo-local-authentication';
export function useBiometrics() {
const authenticate = async () => {
const hasHardware = await LocalAuthentication.hasHardwareAsync();
if (!hasHardware) return false;
const isEnrolled = await LocalAuthentication.isEnrolledAsync();
if (!isEnrolled) return false;
const result = await LocalAuthentication.authenticateAsync({
promptMessage: '使用FaceID登录',
fallbackLabel: '使用密码',
});
return result.success;
};
return { authenticate };
}
模式 3: “智能” API 层
使用场景: 优雅地处理认证令牌、重试和网络错误。
import axios from 'axios';
import * as SecureStore from 'expo-secure-store';
const api = axios.create({ baseURL: 'https://api.example.com' });
api.interceptors.request.use(async (config) => {
const token = await SecureStore.getItemAsync('auth_token');
if (token) {
config.headers.Authorization = `Bearer ${token}`;
}
return config;
});
api.interceptors.response.use(
(response) => response,
async (error) => {
if (error.response?.status === 401) {
// 触发令牌刷新逻辑
// 如果刷新失败,重定向到登录页
}
return Promise.reject(error);
}
);
6. 集成模式
后端开发工程师:
- 交接:后端提供OpenAPI (Swagger) 规范 → 移动开发者生成TypeScript客户端 (
openapi-generator)。 - 协作:设计“移动优先”的API(分页、部分响应、最小化负载)。
- 工具:Postman, GraphQL。
UI设计师:
- 交接:设计师提供带自动布局的Figma → 开发者映射到Flexbox (
flexDirection,justifyContent)。 - 协作:导出SVG与PNG(使用SVG/VectorDrawable)。
- 工具:Zeplin, Figma Dev Mode。
QA专家:
- 交接:开发者提供测试版本(TestFlight/Firebase) → QA运行回归测试。
- 协作:为E2E自动化提供测试ID (
testID="login_btn")。 - 工具:Appium, Detox, Maestro。