Skip to content
2 changes: 1 addition & 1 deletion apps/landing/src/app/(detail)/docs/LeftMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +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 to="/docs/react-native">{t('reactNative')}</MenuItem>
<MenuItem
subMenu={[
{
Expand Down
111 changes: 111 additions & 0 deletions apps/landing/src/app/(detail)/docs/react-native/page.ko.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
export const metadata = {
title: 'React Native',
alternates: {
canonical: '/ko/docs/react-native',
languages: {
en: '/docs/react-native',
ko: '/ko/docs/react-native',
'x-default': '/docs/react-native',
},
},
}

# React Native

> **실험적 기능(0.x).** React Native 지원은 진행 중이며
> ([#411](https://github.com/dev-five-git/devup-ui/issues/411)),
> `@devup-ui/metro-plugin`은 아직 배포되지 않았습니다. API는 바뀔 수 있습니다.

Devup UI는 React Native와 Expo의 번들러인 Metro에서 React Native용으로
컴파일됩니다. `Box`, `Text`, `css`, `styled` 등은 그대로 `@devup-ui/react`에서
import합니다. 빌드 시점에 각 요소는 React Native 컴포넌트가 되고, 스타일 props는
파일마다 하나의 `StyleSheet.create`로 끌어올려진 스타일 객체가 됩니다. 런타임에
CSS를 파싱하는 일은 없습니다.

## 설정

```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는 설정을 읽을 때 `df/theme.d.ts`와 `df/native.d.ts`를 생성합니다. 이 파일들
덕분에 에디터에서 테마 토큰이 자동 완성되고, 각 컴포넌트는 자신이 렌더링하는
React Native 컴포넌트의 props(`onPress`, `onChangeText`, `testID` 등)를 받습니다.

## 요소

| 요소 | React Native |
| --------------------------------- | ------------------------------- |
| `Box`, `Flex`, `VStack`, `Center` | `View` |
| `Text` | `Text` |
| `Image` | `Image` (`src`는 `source`가 됨) |
| `Input` | `TextInput` |
| `Button` | `Pressable` |

## 웹과의 차이

같은 컴포넌트 코드가 양쪽 모두로 빌드되지만, React Native에는 CSS가 없기 때문에
일부는 다르게 동작합니다.

| | 웹 | React Native |
| ------------------------------------------ | ------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| 출력 | 스타일시트의 아토믹 CSS 클래스 | 파일마다 하나의 `StyleSheet.create` 안의 스타일 객체 |
| 런타임 | 없음 | 정적 스타일에는 없습니다. 작은 런타임(gzip 약 1.3 kB)이 테마, 창, 동작 줄이기 설정, 입력 요소의 포커스를 읽지만, 이를 사용하는 스타일에만 쓰입니다. `runtime: false`로 설정하면 그런 스타일은 대신 빌드 오류가 됩니다. |
| 숫자 | `p={4}`는 `16px` | `p={4}`는 `16`: 밀도 독립 픽셀이며, 웹과 같은 배율을 사용합니다 |
| 단위 | 모든 CSS 단위 | 픽셀, `rem`과 `em`(각각 16픽셀), 백분율, `auto`. `vw`, `vh`, `vmin`, `vmax`는 창 크기에 대한 곱셈 한 번이 되며, 창 크기가 바뀌면 이를 사용하는 컴포넌트만 다시 렌더링됩니다. |
| 테마 | `data-theme`으로 전환되는 CSS 변수 | 런타임이 현재 테마의 스타일 객체를 고릅니다. `setTheme`, `useTheme`, `getTheme`가 동작하며, 시스템 화면 모드에 따라 `light` 또는 `dark`가 선택됩니다. |
| 브레이크포인트 | 미디어 쿼리 | devup.json의 `breakpoints`를 기준으로 한 창 너비. 창이 다른 브레이크포인트로 넘어갈 때만 컴포넌트가 다시 렌더링됩니다. |
| `_active`, `_hover`, `_focus`, `_disabled` | CSS 가상 클래스 | `Pressable`이 스타일 함수에 눌림, 호버, 포커스 여부를 알려 줍니다. `Button`은 `Pressable`이며, 이런 스타일을 가진 `Box`는 `Pressable`이 됩니다. `Input`의 `_focus`는 런타임을 통해 동작합니다. `_disabled`는 `disabled` prop을 읽습니다. 호버와 포커스는 웹처럼 포인터나 키보드 포커스가 있는 곳에서만 일어납니다. |
| 그 밖의 선택자 | `_before`, `_focusVisible`, `selectors` 등 | 빌드 오류: React Native에는 선택자가 없습니다 |
| `_ios`, `_android`, `_web` | — | 해당 플랫폼에서만 적용 |
| `_portrait`, `_landscape` | 미디어 쿼리 | 창의 방향 |
| `_motionReduce`, `_motionSafe` | `prefers-reduced-motion` 미디어 쿼리 | 시스템이 앱에 동작 줄이기를 요청하는지 여부(`AccessibilityInfo`) |
| `className={css(...)}` | 클래스 | 빌드가 이를 요소의 스타일로 바꿉니다 |
| `keyframes`, `animation*`, `transition*` | CSS 애니메이션 | [react-native-reanimated](https://docs.swmansion.com/react-native-reanimated/): 애니메이션되는 요소는 Reanimated의 animated 컴포넌트를 렌더링합니다. Reanimated가 설치되어 있지 않으면 빌드 오류가 됩니다. |
| `globalCss`, `Grid` | 지원 | 빌드 오류 |
| styled-components와 Emotion | `styled-components`, `@emotion/styled` 등 | `styled-components/native`와 `@emotion/native`도 같은 방식으로 컴파일됩니다. 숫자는 해당 패키지가 해석하는 대로 픽셀입니다. |
| 지원하지 않는 속성 | — | React Native에 해당 스타일이 없는 속성(`gridTemplateColumns`, `float` 등)은 빌드 오류입니다 |

빌드 오류는 웹과 마찬가지로 스타일이 있는 파일, 줄, 열을 가리킵니다.

## Expo 웹

웹에서 Expo는 [react-native-web](https://necolas.github.io/react-native-web/)을
통해 Metro로 앱을 번들링하며, 같은 네이티브 출력이 그곳에서 CSS로 바뀝니다. Expo
앱이 아닌 사이트는 계속 [Vite, Next.js, Webpack, Rsbuild 또는 Bun 플러그인](/docs/installation)을
사용하며, 이 플러그인들은 대신 아토믹 CSS를 출력합니다.

각 옵션과 기능의 자세한 내용은
[`@devup-ui/metro-plugin` README](https://github.com/dev-five-git/devup-ui/tree/main/packages/metro-plugin)를
참고하세요.
9 changes: 8 additions & 1 deletion apps/landing/src/app/(detail)/docs/react-native/page.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
export const metadata = {
title: 'React Native',
alternates: { canonical: '/docs/react-native' },
alternates: {
canonical: '/docs/react-native',
languages: {
en: '/docs/react-native',
ko: '/ko/docs/react-native',
'x-default': '/docs/react-native',
},
},
}

# React Native
Expand Down
2 changes: 2 additions & 0 deletions apps/landing/src/app/(detail)/page.ko.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { Metadata } from 'next'

import { Bench } from '@/app/Bench'
import { Feature } from '@/app/Feature'
import { ReactNative } from '@/app/ReactNative'
import { TopBanner } from '@/app/TopBanner'
import { Container } from '@/components/Container'
import { Discord } from '@/components/Discord'
Expand Down Expand Up @@ -37,6 +38,7 @@ export default function HomePage() {
<TopBanner locale="ko" />
<Bench locale="ko" />
<Feature locale="ko" />
<ReactNative locale="ko" />
<Container>
<Box px={4} py="40px">
<Discord locale="ko" />
Expand Down
2 changes: 2 additions & 0 deletions apps/landing/src/app/(detail)/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Discord } from '@/components/Discord'

import { Bench } from '../Bench'
import { Feature } from '../Feature'
import { ReactNative } from '../ReactNative'
import { TopBanner } from '../TopBanner'

export const metadata: Metadata = {
Expand All @@ -25,6 +26,7 @@ export default function HomePage() {
<TopBanner />
<Bench />
<Feature />
<ReactNative />
<Container>
<Box px={4} py="40px">
<Discord />
Expand Down
66 changes: 66 additions & 0 deletions apps/landing/src/app/ReactNative.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { css, Flex, Grid, Image, Text, VStack } from '@devup-ui/react'
import type { Locale } from 'next-intl'
import { getTranslations } from 'next-intl/server'

import { Link } from '@/i18n/navigation'

const POINTS = ['metro', 'styleSheet', 'runtime'] as const

export async function ReactNative({ locale = 'en' }: { locale?: Locale }) {
const t = await getTranslations({ locale, namespace: 'Home' })
return (
<VStack alignItems="center" py={['30px', null, '50px']} w="100%">
<VStack gap="40px" maxW="1440px" px={['16px', null, '40px']} w="100%">
<VStack gap="16px">
<Text as="h2" color="$title" m="0" typography="h4">
{t('reactNativeTitle')}
</Text>
<Text color="$text" typography="textL">
{t('reactNativeDescription')}
</Text>
</VStack>
<Grid gap="16px" gridTemplateColumns={['1fr', null, 'repeat(3, 1fr)']}>
{POINTS.map((key) => (
<VStack
key={key}
bg="$containerBackground"
border="1px solid $border"
borderRadius="20px"
boxShadow="0 4px 12px 0 rgba(135, 135, 135, 0.06)"
gap="10px"
h="100%"
p={['20px', null, '30px']}
>
<Text as="h3" color="$title" m="0" typography="h6">
{t(`reactNative.${key}.title`)}
</Text>
<Text color="$text" typography="body">
{t(`reactNative.${key}.description`)}
</Text>
</VStack>
))}
</Grid>
<Link
className={css({ textDecoration: 'none', w: 'fit-content' })}
href="/docs/react-native"
>
<Flex
_active={{ bg: '$menuActive' }}
_hover={{ bg: '$menuHover' }}
alignItems="center"
borderRadius="8px"
gap="10px"
ml="-8px"
p="8px"
transition="background-color 0.2s ease"
>
<Text color="$primary" typography="buttonL">
{t('reactNativeDocs')}
</Text>
<Image bg="$primary" boxSize="24px" maskImage="url(/arrow.svg)" />
</Flex>
</Link>
</VStack>
</VStack>
)
}
18 changes: 18 additions & 0 deletions apps/landing/src/i18n/messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"optimizeCss": "Optimize CSS",
"overview": "Overview",
"quickStart": "Quick Start",
"reactNative": "React Native",
"selector": "Selector",
"shadow": "Shadow",
"styleProps": "Style Props",
Expand Down Expand Up @@ -79,6 +80,23 @@
"joinDiscord": "Join our Discord",
"openKakaoTalk": "Open KakaoTalk",
"preprocessor": "CSS in JS Preprocessor",
"reactNative": {
"metro": {
"title": "Metro plugin",
"description": "Wrap your Metro config with withDevupUI, in Expo or the React Native CLI. Keep importing Box, Text, css and styled from @devup-ui/react."
},
"runtime": {
"description": "Static styles need no runtime. A tiny one (about 1.3 kB gzip) is imported only by styles that read the theme or the window, such as themes and responsive values. _pressed compiles to the Pressable style function.",
"title": "Minimal runtime"
},
"styleSheet": {
"description": "Each element becomes a React Native component, and its style props become style objects in one StyleSheet.create per file. CSS is never parsed at runtime.",
"title": "StyleSheet at build time"
}
},
"reactNativeDescription": "The same components now compile for React Native too. Experimental for now.",
"reactNativeDocs": "Read the React Native docs",
"reactNativeTitle": "React Native",
"tagline": "Building the Future of CSS-in-JS<br></br>Analyze all possible scenarios at the fastest speed and style with optimal performance."
},
"RightIndex": {
Expand Down
18 changes: 18 additions & 0 deletions apps/landing/src/i18n/messages/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"optimizeCss": "CSS 최적화",
"overview": "개요",
"quickStart": "빠른 시작",
"reactNative": "React Native",
"selector": "선택자",
"shadow": "그림자",
"styleProps": "스타일 속성",
Expand Down Expand Up @@ -79,6 +80,23 @@
"joinDiscord": "Discord 참여하기",
"openKakaoTalk": "카카오톡 오픈채팅 열기",
"preprocessor": "CSS-in-JS 전처리기",
"reactNative": {
"metro": {
"title": "Metro 플러그인",
"description": "Expo나 React Native CLI의 Metro 설정을 withDevupUI로 감싸면 됩니다. Box, Text, css, styled는 그대로 @devup-ui/react에서 import합니다."
},
"runtime": {
"description": "정적 스타일에는 런타임이 필요 없습니다. 작은 런타임(gzip 약 1.3 kB)은 테마나 창 크기를 읽는 스타일(테마, 반응형 값 등)에서만 import됩니다. _pressed는 Pressable의 스타일 함수로 컴파일됩니다.",
"title": "최소한의 런타임"
},
"styleSheet": {
"description": "각 요소는 React Native 컴포넌트가 되고, 스타일 props는 파일마다 하나의 StyleSheet.create 안의 스타일 객체가 됩니다. 런타임에 CSS를 파싱하는 일은 없습니다.",
"title": "빌드 시점의 StyleSheet"
}
},
"reactNativeDescription": "이제 같은 컴포넌트를 React Native용으로도 컴파일할 수 있습니다. 현재는 실험적 기능입니다.",
"reactNativeDocs": "React Native 문서 보기",
"reactNativeTitle": "React Native",
"tagline": "CSS-in-JS의 미래를 만듭니다<br></br>가능한 모든 시나리오를 가장 빠르게 분석하고, 최적의 성능으로 스타일을 적용합니다."
},
"RightIndex": {
Expand Down
18 changes: 18 additions & 0 deletions e2e/landing-visual-dark.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,24 @@ test.describe('Landing Page - Dark Mode Visual Regression', () => {
await expect(featureSection).toHaveScreenshot('dark-section-features.png')
})

test('React Native section (dark)', async ({ page }) => {
const reactNativeHeading = page.getByRole('heading', {
name: 'React Native',
exact: true,
})
await reactNativeHeading.scrollIntoViewIfNeeded()
await waitForStyleSettle(page)

const reactNativeSection = reactNativeHeading
.locator('..')
.locator('..')
.locator('..')

await expect(reactNativeSection).toHaveScreenshot(
'dark-section-react-native.png',
)
})

test('Bench section (dark)', async ({ page }) => {
const benchHeading = page.getByText('Comparison Benchmarks').first()
await benchHeading.scrollIntoViewIfNeeded()
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading