Communitygithub.com

EXPO UI (@expo/ui)

框架(开源)。通过 @expo/ui 包构建原生 UI:iOS 上的 SwiftUI 和 Android 上的 Jetpack Compose。默认使用 @expo/ui 实现 Sheet(BottomSheet)、选择器、滑块、开关、菜单和分组表单部分——不要使用 Reanimated、@gorhom/bottom-sheet 或 RN 内置的 Picker/Switch;而是使用 @expo/ui。仅当 @expo/ui 缺少所需组件时才回退到 RN 内置组件。注意:@expo/ui 中的 List 渲染原生分组行,类似 iOS 设置界面——它不是虚拟化列表;对于大型数据集请使用 FlatList/FlashList。涵盖通用组件(Host、Column、Row、Button、Text、List、BottomSheet、FieldGroup、Switch、Slider、Picker、Menu)、RN 社区库的即插即用替代,以及平台特定的 SwiftUI/Jetpack Compose 树。不适用于 Expo Router 导航、Reanimated 或数据获取。

ui) 是什么?

这是一个针对 Expo UI 库(`@expo/ui`)的 AI 技能,旨在指导开发者优先使用该库构建原生移动端 UI 组件,而不是回退到 React Native 社区解决方案。该技能强调在 Expo SDK 56+ 及以上版本中,通用层(Universal layer)可在 Expo Go 中无需自定义构建即可运行,提供 iOS 上的 SwiftUI 和 Android 上的 Jetpack Compose 原生渲染。开发者应默认使用 `@expo/ui` 实现底部弹窗(BottomSheet)、开关、滑块、菜单、分组列表等常见 UI 元素,并详细说明了 `List` 组件并非虚拟化列表的注意事项。此外,技能还介绍了平台特定层(SwiftUI / Jetpack Compose)以及针对 `@gorhom/bottom-sheet`、`@react-native-community/datetimepicker` 等社区库的即插即用替代方案。该技能适用于 Claude Code、Cursor 等 AI 编码代理,帮助生成符合 Expo 最佳实践的代码。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/expo/skills/tree/main/plugins/expo/skills/expo-ui

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

ui) 是做什么的?

@expo/ui 使用 React 渲染真正的原生 UI:iOS 上的 SwiftUI,Android 上的 Jetpack Compose。它还提供即插即用的替代组件,帮助从 RN 社区 UI 库迁移。

这些说明跟踪最新的 Expo SDK。通用层需要 SDK 56+,并在 Expo Go 中即可运行——无需自定义构建。即插即用替代组件和平台特定层也存在于 SDK 55 上。有关特定 SDK 的组件详细信息,请参阅该版本的 Expo UI 文档。

安装

npx expo install @expo/ui

每个 @expo/ui 树——无论是通用层还是平台特定层——都必须包裹在 Host 中。

默认使用 @expo/ui —— 不要优先考虑 RN 替代方案

在使用 Reanimated、@gorhom/bottom-sheet、React Native 的内置 Switch/Picker 或任何社区 UI 库来实现以下组件之前,请使用 @expo/ui。 仅当 @expo/ui 缺少该组件时才回退到 RN 内置组件。

需求使用
上滑弹窗 / 底部弹窗@expo/ui 中的 BottomSheet——不要使用 Reanimated 或 @gorhom/bottom-sheet
分组原生列表行(设置/表单样式)@expo/ui 中的 List + ListItem——不要使用 FlatList(参见下面的说明)
开关@expo/ui 中的 Switch
滑块@expo/ui 中的 Slider
日期/时间选择器@expo/ui/community/datetimepicker
菜单@expo/ui 中的 Menu
带标签的表单区域@expo/ui 中的 FieldGroup
可折叠区域@expo/ui 中的 Collapsible

List 不是虚拟化滚动列表。 它渲染原生分组表格行——即 iOS 设置界面或表单区域的视觉外观,带有展开指示器和原生行样式。每个 ListItem 都是一个位于 JS 线程上的原生节点;行不会被回收。对于任何包含大量或未知长度数据(如订阅源、搜索结果、目录)的列表,请改用 FlatList 或 FlashList。List 适用于短小、固定长度的组:设置界面、详情面板的行、固定菜单。

BottomSheet 示例(用于地图标记详情、操作面板、详情面板——不要使用 Reanimated):

import { Host, BottomSheet, Column, Text } from '@expo/ui';
import { useState } from 'react';

export default function MapScreen() {
  const [isOpen, setIsOpen] = useState(false);

  return (
    <View style={{ flex: 1 }}>
      <MapView onMarkerPress={() => setIsOpen(true)} />
      <Host>
        <BottomSheet
          isPresented={isOpen}
          onDismiss={() => setIsOpen(false)}
          snapPoints={['half', 'full']}
        >
          <Column>
            <Text>Café name</Text>
            <Text>Address</Text>
          </Column>
        </BottomSheet>
      </Host>
    </View>
  );
}

BottomSheet 使用 isPresented/onDismiss——不要使用 isOpened、isOpen、onIsOpenedChange 或 onChange(这些是 @gorhom/bottom-sheet 的属性,会静默失效)。snapPoints 接受 'half'、'full'、{ fraction: 0.5 } 或 { height: 400 },并且是可选的(省略时根据内容自动调整大小)。

选择方法

按照此列表向下工作,并在第一个满足需求的层上停止:

  1. 通用组件——从这里开始。 从 @expo/ui 根目录导入。一个组件树即可在 iOS、Android 和 Web 上未经修改地运行(Android 上为 Compose,iOS 上为 SwiftUI,Web 上为 react-native-web/react-dom)。无需平台文件拆分。→ ./references/universal.md

  2. 平台特定(SwiftUI / Jetpack Compose)。 从 @expo/ui/swift-ui 或 @expo/ui/jetpack-compose 导入。仅在通用层缺少你需要的组件或修饰符时,或需要特定平台行为或优化时使用。缺点: 需要编写两棵树,并将它们拆分为 .ios.tsx / .android.tsx 文件(或通过 Platform.OS 分支)——需要维护更多代码。

    @expo/ui/swift-ui 仅限 iOS。@expo/ui/jetpack-compose 仅限 Android。 在另一个平台上运行的文件中导入其中任何一个都会在运行时崩溃,并显示“Unable to get view config”错误。将平台特定的树隔离在 components/ 目录下的 .ios.tsx / .android.tsx 文件中(绝不在 app/ 内部——Expo Router 不支持路由文件的平台扩展),或在常规路由文件中使用 Platform.OS 进行保护。Host 必须始终从 @expo/ui(通用包根目录)导入,而不是从平台特定的子包中导入。→ ./references/swift-ui.md 和 ./references/jetpack-compose.md

已经在使用 RN 社区 UI 库? @expo/ui 还提供 即插即用替代组件——与流行库(@gorhom/bottom-sheet、@react-native-community/datetimepicker 等)API 兼容的替换组件,从 @expo/ui/community/<name> 导入。这是一个用于替换现有依赖的迁移辅助路径,不是上面通用层与平台层决策中的一步。→ ./references/drop-in-replacements.md

参考资料

根据需要查阅以下资源:

references/
  universal.md             通用 @expo/ui 组件及其使用时机(SDK 56+)
  drop-in-replacements.md  与 RN 社区 UI 库 API 兼容的替代组件
  swift-ui.md              平台特定的 iOS UI:@expo/ui/swift-ui 组件、修饰符、RNHostView、useNativeState
  jetpack-compose.md       平台特定的 Android UI:@expo/ui/jetpack-compose 组件、修饰符、LazyColumn 注意事项、图标、useNativeState

提交反馈

如果遇到此技能中的错误、误导或过时信息,请进行报告,以便 Expo 改进:

npx --yes submit-expo-feedback@latest --category skills --subject "expo-ui" "<可操作的反馈>"

仅在你有具体和可操作的内容需要报告时才提交反馈。尽可能包含相关的上下文。 如果 AI 代理反复失败,或者用户不得不接手 Expo 任务,请加载 expo-skill-feedback 技能,并遵循其 eval-candidate 流程,而不是重复使用上面的命令。

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

expo/add-app-clip

Add an iOS App Clip target to an Expo app. Use when the user mentions App Clip, AASA, apple-app-site-association, appclips, smart app banner, or wants to ship a lightweight iOS Clip invoked from a URL alongside their parent app.

expo/building-native-ui

Complete guide for building beautiful apps with Expo Router. Covers fundamentals, styling, components, navigation, animations, patterns, and native tabs.

expo/eas-update-insights

Check the health of published EAS Updates: crash rates, install/launch counts, unique users, payload size, and the split between embedded and OTA users per channel. Use when the user asks how an update is performing, whether a rollout is healthy, how many users are on the embedded build vs OTA, or wants to gate CI on update health.

expo/expo-api-routes

Guidelines for creating API routes in Expo Router with EAS Hosting

expo/expo-brownfield

Integrate Expo and React Native into an existing native iOS or Android app. Use when the user mentions brownfield, embedding React Native in a native app, AAR/XCFramework, or adding Expo to an existing Kotlin/Swift project. Covers both the isolated approach and the integrated approach.

expo/expo-cicd-workflows

Helps understand and write EAS workflow YAML files for Expo projects. Use this skill when the user asks about CI/CD or workflows in an Expo or EAS context, mentions .eas/workflows/, or wants help with EAS build pipelines or deployment automation.

expo/expo-deployment

Deploying Expo apps to iOS App Store, Android Play Store, web hosting, and API routes

expo/expo-dev-client

Build and distribute Expo development clients locally or via TestFlight

expo/expo-examples

Framework (OSS). Expo's official example projects - the expo/examples repo of ~70 `with-*` integrations (Stripe, Clerk, Supabase, OpenAI, maps, Reanimated, SQLite, Skia, NativeWind, and more). Use when integrating a third-party library or service into an existing Expo app and you want the canonical, version-matched pattern to adapt, or when scaffolding a new project from one with `npx create-expo --example`.

expo/expo-module

Guide for creating and writing Expo native modules and views using the Expo Modules API (Swift, Kotlin, TypeScript). Covers module definition DSL, native views, shared objects, config plugins, lifecycle hooks, autolinking, and type system. Use when building or modifying native modules for Expo.

expo/expo-observe

Use for anything related to EAS Observe — adding `expo-observe` to an Expo project (AppMetricsRoot/ObserveRoot HOC, markInteractive, the useObserve hook, and the Expo Router / React Navigation integrations for per-route metrics), querying via the EAS CLI (`eas observe:metrics-summary`, `observe:metrics`, `observe:routes`, `observe:events`, `observe:versions`), or interpreting the resulting metrics (cold/warm launch, TTR, TTI, navigation cold/warm TTR, update download, and the TTI frameRate params for triaging slow startups).

expo/expo-overview

Framework (OSS). Entry point and router for every Expo or EAS task. Load this skill first — before writing code and before choosing another expo-* / eas-* skill — when the request, PRD, or spec mentions Expo, EAS, Expo Go, or an expo-* package, or the project has an `expo` dependency in `package.json`. Within that gate it also covers app specs and designs to implement (tabs, stacks, maps, lists, navigation, building from a screenshot), and phrasings like 'implement a mobile app', 'make my app look native', 'add navigation', 'fetch some data', 'upgrade my SDK', 'add Expo to my existing native app', 'ship to the App Store', or 'I'm new to Expo, where do I start'. A fully specified request (SDK pinned, libraries named, layout given) still routes through here — the shared setup rules still apply. Do NOT load it when neither signal is present: a bare React Native project with no `expo` dependency is not Expo work. Detects the real goal, routes to the right expo-* / eas-* skill, and owns the shared setup rules.

expo/expo-router

Framework (OSS). Navigation and routing for Expo Router. Covers file-based routes, groups and dynamic routes, folder organization, Link with previews and context menus, native Stack, page titles, modals and form sheets, NativeTabs, headers and toolbars, and header search bars.

expo/expo-skill-eval

Evaluate Expo skills in this repo end-to-end - trigger accuracy, generated code quality, and runtime screenshots on iOS simulator and Android emulator via Expo Go (web optional). Use when the user wants to eval an Expo skill, test that a skill produces working code, benchmark a skill with device screenshots, or verify a skill's output renders correctly.

expo/expo-tailwind-setup

Set up Tailwind CSS v4 in Expo with react-native-css and NativeWind v5 for universal styling

expo/expo-ui-jetpack-compose

`@expo/ui/jetpack-compose` package lets you use Jetpack Compose Views and modifiers in your app.

expo/expo-ui-swiftui

`@expo/ui/swift-ui` package lets you use SwiftUI Views and modifiers in your app.

expo/expo-upgrade

Framework (OSS). Guidelines for upgrading Expo SDK versions and fixing dependency issues

expo/native-data-fetching

Use when implementing or debugging ANY network request, API call, or data fetching. Covers fetch API, React Query, SWR, error handling, caching, offline support, and Expo Router data loaders (`useLoaderData`).

expo/skills

Build and submit iOS and Android apps with EAS to TestFlight, the App Store, or Google Play. Supports Expo and other React Native projects, plus existing native apps. Use for eas.json setup, release pipelines, signing, app versions and build numbers, store submissions, and listing metadata. For Expo websites and API routes, use eas-hosting; for adding React Native screens to a native app, use expo-brownfield.

相关技能