Expo router native ui

From findscripter/everything-skills · View interactive version

Expo router native ui is an AI agent skill from the GitHub repository findscripter/everything-skills. 当用 Expo Router 构建有原生质感的 React Native 应用(导航、原生组件、动画、原生 Tabs、Header/搜索、表单 Sheet、视觉特效)时使用;产出遵循 Apple HIG、优先 Expo Go、用内联样式+文件路由的可运行 UI 结构与代码;不适用于纯原生 Swift/Kotlin、纯 Web/H5 或与 Expo 无关的后端任务。触发词:Expo、Expo Router、React Native、NativeTabs、expo-router

How to use this skill

Skill file

何时使用

不该用的边界:

步骤

  1. 先跑 Expo Go,别急着自定义构建(关键约束):npx expo start 扫码进 Expo Go 充分测试。绝大多数 expo-* 包、Expo Router、reanimated、推送、深链都开箱即用。
  2. 仅在这些情况才需要自定义构建(npx expo run:ios/android 或 eas build):本地 Expo 模块(modules/ 自定义原生代码)、Apple targets(小组件/扩展,@bacons/apple-targets)、Expo Go 不含的第三方原生模块、app.json 表达不了的原生配置。自定义构建更慢、要 Xcode/Android Studio,不确定就先 Expo Go。
  3. 搭路由:路由放 app/ 目录,用 _layout.tsx 定义 Stack/Tabs;保证存在匹配 / 的路由(可在 group 内)。绝不在 app/ 里同放组件/类型/工具(反模式);移动路由时删旧文件。
  4. 写 UI:根组件套 ScrollView 保证响应式;遵循 Apple HIG;用内联样式(不支持 CSS/Tailwind)。
  5. 加原生细节:导航标题用 Stack 而非页面里的自定义文本;多用 Link.Preview 与上下文菜单;iOS 上条件性用 expo-haptics。

指令

库选型(用新弃旧):

响应式与安全区:

样式规则:

代码风格: 文件名 kebab-case(如 comment-card.tsx)、无特殊字符;import 置顶;注意转义嵌套反引号与引号;tsconfig.json 配路径别名并优先用别名。

导航: 路由间用 expo-router 的 <Link href="/path" />,包裹自定义组件用 asChild;Stack 用 expo-router/stack,总是用 _layout.tsx 定义;标题用 <Stack.Screen options={{ title: "Home" }} />;搜索栏优先 Stack.Screen 的 headerSearchBarOptions。

示例

带原生 Tabs + 共享 group 的标准布局:

// app/_layout.tsx
import { NativeTabs, Icon, Label } from "expo-router/unstable-native-tabs";
import { Theme } from "../components/theme";

export default function Layout() {
  return (
    <Theme>
      <NativeTabs>
        <NativeTabs.Trigger name="(index)">
          <Icon sf="list.dash" />
          <Label>Items</Label>
        </NativeTabs.Trigger>
        <NativeTabs.Trigger name="(search)" role="search" />
      </NativeTabs>
    </Theme>
  );
}
// app/(index,search)/_layout.tsx —— 两个 tab 共享、可各自 push 公共屏
import { Stack } from "expo-router/stack";
import { PlatformColor } from "react-native";

export default function Layout({ segment }) {
  const screen = segment.match(/\((.*)\)/)?.[1]!;
  const titles: Record<string, string> = { index: "Items", search: "Search" };
  return (
    <Stack screenOptions={{
      headerTransparent: true, headerShadowVisible: false,
      headerLargeStyle: { backgroundColor: "transparent" },
      headerTitleStyle: { color: PlatformColor("label") },
      headerLargeTitle: true, headerBlurEffect: "none",
      headerBackButtonDisplayMode: "minimal",
    }}>
      <Stack.Screen name={screen} options={{ title: titles[screen] }} />
      <Stack.Screen name="i/[id]" options={{ headerLargeTitle: false }} />
    </Stack>
  );
}

模态 / 表单 Sheet:

<Stack.Screen name="modal" options={{ presentation: "modal" }} />

<Stack.Screen name="sheet" options={{
  presentation: "formSheet",
  sheetGrabberVisible: true,
  sheetAllowedDetents: [0.5, 1.0],
  contentStyle: { backgroundColor: "transparent" }, // iOS 26+ 背景变液态玻璃
}} />

优先用上述原生 modal/sheet,而非手写自定义弹窗组件。

Link 上下文菜单 + 预览:

<Link href="/settings" asChild>
  <Link.Trigger><Pressable><Card /></Pressable></Link.Trigger>
  <Link.Menu>
    <Link.MenuAction title="Share" icon="square.and.arrow.up" onPress={onShare} />
    <Link.MenuAction title="Block" icon="nosign" destructive onPress={onBlock} />
  </Link.Menu>
  <Link.Preview />
</Link>

阴影(CSS boxShadow,非 legacy):

<View style={{ boxShadow: "0 1px 2px rgba(0, 0, 0, 0.05)" }} />

源仓库还附 references/ 专题(按需查阅):animations / controls / form-sheet / gradients / icons / media / route-structure / search / storage / tabs / toolbar-and-headers / visual-effects / webgpu-three / zoom-transitions。

注意事项

互见


采编自 sickn33/antigravity-awesome-skills(MIT 许可)。

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.