AGENT SKILL

React Native 跨平台移动应用开发

mobile-app

使用 React Native 与 Expo 构建跨平台移动应用。涵盖项目搭建、导航(React Navigation、Expo Router)、原生模块、推送通知、离线优先架构、应用商店部署、响应式布局、平台特定代码、状态管理与性能优化。在构建移动应用或跨平台体验时使用。

License 许可
MIT
最近更新
2026-09-14
Stars
★ 68
Forks
15

01 前言 Front Matter

name
mobile-app
description
Build cross-platform mobile applications with React Native and Expo. Covers project setup, navigation (React Navigation, Expo Router), native modules, push notifications, offline-first architecture, app store deployment, responsive layouts, platform-specific code, state management, and performance optimization. Use when building mobile apps or cross-platform experiences.

03 SKILL.md 正文

Mobile App Development

Stack Selection

Approach Best For Trade-offs
Expo (managed) Most apps, fast iteration Limited native module access
Expo (dev build) Full native access + Expo DX Requires native build
React Native CLI Maximum control, custom native More setup, slower iteration
Progressive Web App Simple mobile web experience Limited device APIs

Project Setup (Expo Router)

npx -y create-expo-app@latest my-app --template tabs
cd my-app && npx expo start

Navigation (Expo Router)

app/
├── _layout.tsx           # Root layout
├── (tabs)/
│   ├── _layout.tsx       # Tab bar layout
│   ├── index.tsx         # Home tab
│   ├── explore.tsx       # Explore tab
│   └── profile.tsx       # Profile tab
├── (auth)/
│   ├── _layout.tsx       # Auth flow layout
│   ├── login.tsx
│   └── register.tsx
├── [id].tsx              # Dynamic route
└── modal.tsx             # Modal screen

Tab Layout

import { Tabs } from "expo-router";
import { Home, Search, User } from "lucide-react-native";

export default function TabLayout() {
  return (
    <Tabs screenOptions={{
      tabBarActiveTintColor: "#8b5cf6",
      tabBarStyle: { backgroundColor: "#0a0a0a", borderTopColor: "#1a1a1a" },
      headerStyle: { backgroundColor: "#0a0a0a" },
      headerTintColor: "#fff",
    }}>
      <Tabs.Screen name="index" options={{ title: "Home", tabBarIcon: ({ color }) => <Home size={22} color={color} /> }} />
      <Tabs.Screen name="explore" options={{ title: "Explore", tabBarIcon: ({ color }) => <Search size={22} color={color} /> }} />
      <Tabs.Screen name="profile" options={{ title: "Profile", tabBarIcon: ({ color }) => <User size={22} color={color} /> }} />
    </Tabs>
  );
}

Styling (NativeWind / StyleSheet)

import { StyleSheet, View, Text } from "react-native";

export function Card({ title, description }: { title: string; description: string }) {
  return (
    <View style={styles.card}>
      <Text style={styles.title}>{title}</Text>
      <Text style={styles.description}>{description}</Text>
    </View>
  );
}

const styles = StyleSheet.create({
  card: {
    backgroundColor: "#1a1a1a",
    borderRadius: 16,
    padding: 16,
    marginVertical: 8,
    borderWidth: 1,
    borderColor: "#2a2a2a",
  },
  title: { fontSize: 18, fontWeight: "700", color: "#fff", marginBottom: 4 },
  description: { fontSize: 14, color: "#999", lineHeight: 20 },
});

Data Fetching (TanStack Query)

import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";

function useUsers() {
  return useQuery({
    queryKey: ["users"],
    queryFn: () => fetch("/api/users").then((r) => r.json()),
    staleTime: 5 * 60 * 1000,
  });
}

function useCreateUser() {
  const queryClient = useQueryClient();
  return useMutation({
    mutationFn: (data: CreateUserInput) =>
      fetch("/api/users", { method: "POST", body: JSON.stringify(data) }).then((r) => r.json()),
    onSuccess: () => queryClient.invalidateQueries({ queryKey: ["users"] }),
  });
}

Offline-First Pattern

import AsyncStorage from "@react-native-async-storage/async-storage";
import NetInfo from "@react-native-community/netinfo";

async function fetchWithOffline<T>(key: string, fetchFn: () => Promise<T>): Promise<T> {
  const isConnected = (await NetInfo.fetch()).isConnected;

  if (isConnected) {
    try {
      const data = await fetchFn();
      await AsyncStorage.setItem(key, JSON.stringify(data));
      return data;
    } catch {
      // Fall through to cache
    }
  }

  const cached = await AsyncStorage.getItem(key);
  if (cached) return JSON.parse(cached);
  throw new Error("No data available offline");
}

Push Notifications (Expo)

import * as Notifications from "expo-notifications";
import * as Device from "expo-device";

async function registerForPushNotifications(): Promise<string | null> {
  if (!Device.isDevice) return null;
  const { status } = await Notifications.requestPermissionsAsync();
  if (status !== "granted") return null;
  const token = await Notifications.getExpoPushTokenAsync({ projectId: "your-project-id" });
  return token.data;
}

Platform-Specific Code

import { Platform } from "react-native";

const styles = StyleSheet.create({
  shadow: Platform.select({
    ios: { shadowColor: "#000", shadowOffset: { width: 0, height: 2 }, shadowOpacity: 0.1, shadowRadius: 8 },
    android: { elevation: 4 },
    default: {},
  }),
});

Performance Rules

  • Use FlatList for long lists — never ScrollView with .map()
  • Memoize expensive computations with useMemo and useCallback
  • Use React.memo for list items
  • Optimize images: resize, compress, use expo-image for caching
  • Avoid inline styles (create StyleSheet once)
  • Use Animated API or react-native-reanimated for smooth animations

04 同仓库更多 Skills

RaheesAhmed
RaheesAhmed/SajiCode

演示测试技能

demo-skill

用于测试的演示插件技能。

普通用户示例与演示技能
★ 68
RaheesAhmed
RaheesAhmed/SajiCode

智能体技能开发

write-a-skill

创建新的智能体技能,具备合理的结构、渐进式披露(progressive disclosure)机制和配套捆绑资源。当用户想要创建、编写或构建新技能时使用。

AI 工程师插件与技能管理
★ 68
RaheesAhmed
RaheesAhmed/SajiCode

网络调研与数据提取

web-research

深度网络研究与数据提取技能。通过获取 URL、阅读文档、爬取 API 文档、评估 npm/pypi 包、比较技术,并将研究发现综合为可操作的建议,系统地研究任意主题。适用于研究库、框架、API、解决方案,或任何需要网络调查的主题。

知识工作者网页搜索与信息研究
★ 68
RaheesAhmed
RaheesAhmed/SajiCode

自动化测试套件设计与实现

testing

设计并实现全面的测试套件。涵盖单元测试、集成测试、使用 Playwright 的 E2E 测试、API 测试、mock 策略、测试数据工厂、TDD 工作流、快照测试、覆盖率目标以及 CI 集成。适用于编写测试、设计测试架构或排查测试失败。

测试工程师测试与质量保障
★ 68
RaheesAhmed
RaheesAhmed/SajiCode

工程开发工作流与质量规范

superpowers

核心工程工作流,在每一项任务中都会激活。强制执行系统化的“先计划后编码”方法论、多文件重构安全、依赖感知的变更、预检验证以及零占位符质量标准。在所有编码任务中主动(PROACTIVELY)使用。

软件开发工程师工程实践准则
★ 68
RaheesAhmed
RaheesAhmed/SajiCode

CSS样式系统设计与实现

styling

使用 Tailwind CSS、原生 CSS 或 CSS-in-JS 实现生产级样式系统。涵盖 CSS 架构(BEM、utility-first、模块化)、设计令牌、响应式模式、动画系统、暗黑模式、容器查询、打印样式以及性能优化。适用于实现设计或构建 CSS 架构。

软件开发工程师前端开发与界面实现
★ 68