From d70930f58589ad27ba2f793ed550fd4b38d894f5 Mon Sep 17 00:00:00 2001 From: owjs3901 Date: Sat, 21 Nov 2026 16:07:54 +0900 Subject: [PATCH] docs(landing): document React Native and its differences from the web A React Native page in the docs: setup with Metro, the elements, a table of what differs from the web (output, runtime, units, themes, breakpoints, states, selectors, animations, compat) and Expo web. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/publish.yml | 1 + .../src/app/(detail)/docs/LeftMenu.tsx | 1 + .../app/(detail)/docs/react-native/page.mdx | 105 ++++++++++++++++++ e2e/exported-routes.ts | 1 + 4 files changed, 108 insertions(+) create mode 100644 apps/landing/src/app/(detail)/docs/react-native/page.mdx diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 1c506448b..0a3a8da91 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -18,6 +18,7 @@ on: - feat/react-native-animations - feat/react-native-compat - feat/react-native-web + - feat/react-native-types # Pull requests and every job below run read-only. Only the `release` and # `deploy-pages` jobs get write permissions, and they run on pushes to main diff --git a/apps/landing/src/app/(detail)/docs/LeftMenu.tsx b/apps/landing/src/app/(detail)/docs/LeftMenu.tsx index 67873d607..f42f9fb84 100644 --- a/apps/landing/src/app/(detail)/docs/LeftMenu.tsx +++ b/apps/landing/src/app/(detail)/docs/LeftMenu.tsx @@ -38,6 +38,7 @@ export function LeftMenu() { Features Supported Syntax & Limitations Build Errors + React Native **Experimental (0.x).** React Native support is in progress +> ([#411](https://github.com/dev-five-git/devup-ui/issues/411)) and +> `@devup-ui/metro-plugin` is not published yet. Its API may change. + +Devup UI compiles for React Native in Metro, the bundler of React Native and +Expo. You keep importing `Box`, `Text`, `css`, `styled`, ... from +`@devup-ui/react`. At build time each element becomes a React Native component, +and its style props become style objects hoisted into one `StyleSheet.create` +per file. CSS is never parsed at runtime. + +## Setup + +```bash +npm install @devup-ui/react @devup-ui/metro-plugin +``` + +```js +// metro.config.js (Expo) +const { getDefaultConfig } = require('expo/metro-config') +const { withDevupUI } = require('@devup-ui/metro-plugin') + +module.exports = withDevupUI(getDefaultConfig(__dirname)) +``` + +```js +// metro.config.js (React Native CLI) +const { getDefaultConfig } = require('@react-native/metro-config') +const { withDevupUI } = require('@devup-ui/metro-plugin') + +module.exports = withDevupUI(getDefaultConfig(__dirname)) +``` + +```tsx +import { Box, Flex, Text } from '@devup-ui/react' + +export function Card() { + return ( + + + Hello + + + + ) +} +``` + +Metro writes `df/theme.d.ts` and `df/native.d.ts` when it reads the config. +With them, theme tokens complete in your editor, and each component takes the +props of the React Native component it renders (`onPress`, `onChangeText`, +`testID`, ...). + +## Elements + +| Element | React Native | +| --------------------------------- | -------------------------------- | +| `Box`, `Flex`, `VStack`, `Center` | `View` | +| `Text` | `Text` | +| `Image` | `Image` (`src` becomes `source`) | +| `Input` | `TextInput` | +| `Button` | `Pressable` | + +## Differences from the web + +The same component code builds for both, but React Native has no CSS, so some +things work differently. + +| | Web | React Native | +| ------------------------------------------ | -------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| Output | Atomic CSS classes in a stylesheet | Style objects in one `StyleSheet.create` per file | +| Runtime | None | None for static styles. A small runtime (about 1.2 kB gzip) reads the theme, the window and press, hover and focus states, but only for the styles that use them. With `runtime: false`, those styles are build errors instead. | +| Numbers | `p={4}` is `16px` | `p={4}` is `16`: density-independent pixels, with the same scale as the web | +| Units | Any CSS unit | Pixels, `rem` and `em` (16 pixels each), percentages and `auto`. `vw`, `vh` and other units are build errors. | +| Themes | CSS variables, switched by `data-theme` | The runtime picks the style object of the current theme. `setTheme`, `useTheme` and `getTheme` work, and the system appearance picks `light` or `dark`. | +| Breakpoints | Media queries | The window width, with the `breakpoints` of devup.json. A component renders again only when the window crosses into another breakpoint. | +| `_active`, `_hover`, `_focus`, `_disabled` | CSS pseudo-classes | `Pressable` tells its style function whether it is pressed, hovered or focused: a `Button` is one, and a `Box` with these styles becomes one. `_focus` on an `Input` works through the runtime. `_disabled` reads the `disabled` prop. Hover and focus happen only where there is a pointer or keyboard focus, such as the web. | +| Other selectors | `_before`, `_focusVisible`, `selectors`, ... | Build errors: React Native has no selectors | +| `_ios`, `_android`, `_web` | — | Apply on that platform only | +| `_portrait`, `_landscape` | Media queries | The window's orientation | +| `className={css(...)}` | A class | The build turns it into the element's styles | +| `keyframes`, `animation*`, `transition*` | CSS animations | [react-native-reanimated](https://docs.swmansion.com/react-native-reanimated/): an element that animates renders Reanimated's animated component. Without Reanimated installed, these are build errors. | +| `globalCss`, `Grid` | Supported | Build errors | +| styled-components and Emotion | `styled-components`, `@emotion/styled`, ... | `styled-components/native` and `@emotion/native` compile the same way. Their numbers are pixels, as those packages read them. | +| Unsupported properties | — | A property React Native has no style for (`gridTemplateColumns`, `float`, ...) is a build error | + +Build errors point at the file, line and column of the style, as on the web. + +## Expo web + +On the web, Expo bundles the app with Metro through +[react-native-web](https://necolas.github.io/react-native-web/), and the same +native output turns into CSS there. A site that is not an Expo app keeps using +the [Vite, Next.js, Webpack, Rsbuild or Bun plugin](/docs/installation), which +output atomic CSS instead. + +See the +[`@devup-ui/metro-plugin` README](https://github.com/dev-five-git/devup-ui/tree/main/packages/metro-plugin) +for every option and each feature in detail. diff --git a/e2e/exported-routes.ts b/e2e/exported-routes.ts index 5b3935adb..4e003afa7 100644 --- a/e2e/exported-routes.ts +++ b/e2e/exported-routes.ts @@ -89,6 +89,7 @@ const ENGLISH_EXPORTED_ROUTES = [ '/docs/migration/vanilla-extract', '/docs/overview', '/docs/quick-start', + '/docs/react-native', '/showcase', '/team', ] as const