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
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
1 change: 1 addition & 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
1 change: 1 addition & 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
Loading