Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changepacks/changepack_log_metro_expo_web.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"changes": {
"packages/metro-plugin/package.json": "Patch"
},
"note": "Document Expo web (part of #411): Metro compiles the web build through react-native-web with the same output as iOS and Android, which the Expo example now exports and checks in Chromium.",
"date": "2026-11-21T00:00:00.000Z"
}
7 changes: 7 additions & 0 deletions .changepacks/changepack_log_metro_types.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"changes": {
"packages/metro-plugin/package.json": "Patch"
},
"note": "Write `df/theme.d.ts` (the tokens of devup.json) and `df/native.d.ts` (React Native props for each component) when Metro reads the config, with a `distDir` option, as the web plugins do.",
"date": "2026-11-21T00:00:00.000Z"
}
7 changes: 7 additions & 0 deletions .changepacks/changepack_log_react_native_types.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"changes": {
"packages/react/package.json": "Patch"
},
"note": "Add `@devup-ui/react/native/types`, which types each component as the React Native component it renders (`Box` takes `ViewProps`, `Button` takes `PressableProps`, ...) through the new `DevupElementProps` augmentation point. Web types are unchanged.",
"date": "2026-11-21T00:00:00.000Z"
}
2 changes: 1 addition & 1 deletion apps/expo/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"name": "Devup UI Expo",
"slug": "devup-ui-expo",
"version": "0.1.0",
"platforms": ["ios", "android"]
"platforms": ["ios", "android", "web"]
}
}
2 changes: 1 addition & 1 deletion apps/expo/check-bundle.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ function runtimeUsers(code, locate) {
return users
}

for (const platform of ['ios', 'android']) {
for (const platform of ['ios', 'android', 'web']) {
const directory = join(root, platform)
const bundles = readdirSync(directory).filter((file) => file.endsWith('.js'))
if (bundles.length === 0) failures.push(`${platform}: no JavaScript bundle`)
Expand Down
102 changes: 102 additions & 0 deletions apps/expo/check-web.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
// Opens the web export (`expo export --platform web` wrote dist/) in Chromium
// and checks that react-native-web renders the styles Devup UI compiled: the
// card takes the theme's color and switches with the theme, the input takes
// its focus style through the runtime's `Focused`, and the button, a
// `Pressable`, counts a press.
import { createReadStream, existsSync, statSync } from 'node:fs'
import { createServer } from 'node:http'
import { extname, join, normalize } from 'node:path'

import { chromium } from '@playwright/test'

const root = join(import.meta.dirname, 'dist')
const TYPES = {
'.html': 'text/html',
'.js': 'text/javascript',
'.json': 'application/json',
'.png': 'image/png',
}

const server = createServer((request, response) => {
const path = join(root, normalize(new URL(request.url, 'http://x').pathname))
if (!path.startsWith(root)) {
response.writeHead(404).end()
return
}
// A path that is no file is the app's page
const file =
existsSync(path) && statSync(path).isFile()
? path
: join(root, 'index.html')
response.writeHead(200, {
'content-type': TYPES[extname(file)] ?? 'application/octet-stream',
})
createReadStream(file).pipe(response)
})
await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve))
const url = `http://127.0.0.1:${server.address().port}/`

const failures = []
/** Fail with `message` unless `actual` is `expected` */
function expectEqual(actual, expected, message) {
if (actual !== expected) {
failures.push(`${message}: expected ${expected}, got ${actual}`)
}
}

const browser = await chromium.launch()
try {
const page = await browser.newPage({ colorScheme: 'light' })
const errors = []
page.on('pageerror', (error) => errors.push(error.message))
await page.goto(url)
const card = page.getByTestId('card')
const name = page.getByTestId('name')
const count = page.getByTestId('count')
await card.waitFor()
/** The computed style `property` of `locator` */
const style = (locator, property) =>
locator.evaluate(
(element, property) => getComputedStyle(element)[property],
property,
)

expectEqual(
await style(card, 'backgroundColor'),
'rgb(255, 255, 255)',
'the card in the light theme',
)
expectEqual(
await style(count, 'backgroundColor'),
'rgb(90, 68, 255)',
'the count button',
)
await name.focus()
expectEqual(
await style(name, 'borderTopColor'),
'rgb(90, 68, 255)',
'the focused input',
)
await count.click()
expectEqual(
(await count.textContent())?.trim(),
'Pressed 1 times',
'the count after a press',
)
await page.getByTestId('theme').click()
expectEqual(
await style(card, 'backgroundColor'),
'rgb(31, 31, 46)',
'the card in the dark theme',
)
for (const error of errors) failures.push(`page error: ${error}`)
} finally {
await browser.close()
server.close()
}

if (failures.length > 0) {
console.error(failures.join('\n'))
process.exit(1)
}
console.info('web: react-native-web renders the compiled styles')
9 changes: 7 additions & 2 deletions apps/expo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,20 @@
"main": "index.ts",
"scripts": {
"start": "expo start",
"export": "expo export --platform ios --platform android --no-bytecode --source-maps",
"check": "node check-bundle.mjs"
"export": "expo export --platform ios --platform android --platform web --no-bytecode --source-maps",
"check": "node check-bundle.mjs",
"check:web": "node check-web.mjs",
"typecheck": "bun ../../node_modules/@typescript/native/bin/tsc --noEmit"
},
"dependencies": {
"@devup-ui/react": "workspace:^",
"@expo/metro-runtime": "~58.0.17",
"expo": "~58.0.26",
"react": "^19.3.1",
"react-dom": "^19.3.1",
"react-native": "0.88.1",
"react-native-reanimated": "~4.7.1",
"react-native-web": "~0.21.4",
"react-native-worklets": "0.13.0"
},
"devDependencies": {
Expand Down
4 changes: 4 additions & 0 deletions apps/expo/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export function App() {
boxShadow="$raised"
maxW={[null, null, '480px']}
p={[4, null, 6]}
testID="card"
w="100%"
>
<Text color="$muted" fontSize="14px" mb={2}>
Expand All @@ -72,6 +73,7 @@ export function App() {
onChangeText={setName}
px={3}
py={2}
testID="name"
value={name}
/>
<Text color={name ? '$text' : '$placeholder'} mt={2}>
Expand All @@ -88,6 +90,7 @@ export function App() {
bg="#5a44ff"
className={button}
onPress={() => setCount(count + 1)}
testID="count"
>
<Text color="#fff" fontWeight="600">
Pressed {count} times
Expand All @@ -98,6 +101,7 @@ export function App() {
border="1px solid $border"
className={button}
onPress={() => setTheme(theme === 'dark' ? 'light' : 'dark')}
testID="theme"
>
<Text color="$text">
Switch to {theme === 'dark' ? 'light' : 'dark'}
Expand Down
1 change: 1 addition & 0 deletions apps/landing/src/app/(detail)/docs/LeftMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export function LeftMenu() {
<MenuItem to="/docs/features">{t('features')}</MenuItem>
<MenuItem to="/docs/limitations">{t('limitations')}</MenuItem>
<MenuItem to="/docs/build-errors">{t('buildErrors')}</MenuItem>
<MenuItem to="/docs/react-native">React Native</MenuItem>
<MenuItem
subMenu={[
{
Expand Down
105 changes: 105 additions & 0 deletions apps/landing/src/app/(detail)/docs/react-native/page.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
export const metadata = {
title: 'React Native',
alternates: { canonical: '/docs/react-native' },
}

# 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 (
<Flex bg="$card" borderRadius="12px" gap={2} p={[4, null, 6]}>
<Text color="$text" typography="title">
Hello
</Text>
<Box bg="red" h="8px" w="8px" />
</Flex>
)
}
```

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.
Loading
Loading