diff --git a/apps/landing/src/app/(detail)/docs/LeftMenu.tsx b/apps/landing/src/app/(detail)/docs/LeftMenu.tsx index 402cd2450..cfe87c0ba 100644 --- a/apps/landing/src/app/(detail)/docs/LeftMenu.tsx +++ b/apps/landing/src/app/(detail)/docs/LeftMenu.tsx @@ -44,7 +44,7 @@ export function LeftMenu() { {t('features')} {t('limitations')} {t('buildErrors')} - React Native + {t('reactNative')} **실험적 기능(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 ( + + + Hello + + + + ) +} +``` + +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)를 +참고하세요. diff --git a/apps/landing/src/app/(detail)/docs/react-native/page.mdx b/apps/landing/src/app/(detail)/docs/react-native/page.mdx index 0b3daca29..e276a6fc9 100644 --- a/apps/landing/src/app/(detail)/docs/react-native/page.mdx +++ b/apps/landing/src/app/(detail)/docs/react-native/page.mdx @@ -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 diff --git a/apps/landing/src/app/(detail)/page.ko.tsx b/apps/landing/src/app/(detail)/page.ko.tsx index d25bbed21..be5daf3f0 100644 --- a/apps/landing/src/app/(detail)/page.ko.tsx +++ b/apps/landing/src/app/(detail)/page.ko.tsx @@ -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' @@ -37,6 +38,7 @@ export default function HomePage() { + diff --git a/apps/landing/src/app/(detail)/page.tsx b/apps/landing/src/app/(detail)/page.tsx index 8b4b56389..977515c34 100644 --- a/apps/landing/src/app/(detail)/page.tsx +++ b/apps/landing/src/app/(detail)/page.tsx @@ -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 = { @@ -25,6 +26,7 @@ export default function HomePage() { + diff --git a/apps/landing/src/app/ReactNative.tsx b/apps/landing/src/app/ReactNative.tsx new file mode 100644 index 000000000..8dbae1f08 --- /dev/null +++ b/apps/landing/src/app/ReactNative.tsx @@ -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 ( + + + + + {t('reactNativeTitle')} + + + {t('reactNativeDescription')} + + + + {POINTS.map((key) => ( + + + {t(`reactNative.${key}.title`)} + + + {t(`reactNative.${key}.description`)} + + + ))} + + + + + {t('reactNativeDocs')} + + + + + + + ) +} diff --git a/apps/landing/src/i18n/messages/en.json b/apps/landing/src/i18n/messages/en.json index 770e2709a..a985a788f 100644 --- a/apps/landing/src/i18n/messages/en.json +++ b/apps/landing/src/i18n/messages/en.json @@ -27,6 +27,7 @@ "optimizeCss": "Optimize CSS", "overview": "Overview", "quickStart": "Quick Start", + "reactNative": "React Native", "selector": "Selector", "shadow": "Shadow", "styleProps": "Style Props", @@ -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

Analyze all possible scenarios at the fastest speed and style with optimal performance." }, "RightIndex": { diff --git a/apps/landing/src/i18n/messages/ko.json b/apps/landing/src/i18n/messages/ko.json index 904e0f555..b47a98422 100644 --- a/apps/landing/src/i18n/messages/ko.json +++ b/apps/landing/src/i18n/messages/ko.json @@ -27,6 +27,7 @@ "optimizeCss": "CSS 최적화", "overview": "개요", "quickStart": "빠른 시작", + "reactNative": "React Native", "selector": "선택자", "shadow": "그림자", "styleProps": "스타일 속성", @@ -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의 미래를 만듭니다

가능한 모든 시나리오를 가장 빠르게 분석하고, 최적의 성능으로 스타일을 적용합니다." }, "RightIndex": { diff --git a/e2e/landing-visual-dark.spec.ts b/e2e/landing-visual-dark.spec.ts index aa3a310a1..c995355d6 100644 --- a/e2e/landing-visual-dark.spec.ts +++ b/e2e/landing-visual-dark.spec.ts @@ -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() diff --git a/e2e/landing-visual-dark.spec.ts-snapshots/dark-full-page-desktop-linux.png b/e2e/landing-visual-dark.spec.ts-snapshots/dark-full-page-desktop-linux.png index 556d79d32..fecaa2591 100644 Binary files a/e2e/landing-visual-dark.spec.ts-snapshots/dark-full-page-desktop-linux.png and b/e2e/landing-visual-dark.spec.ts-snapshots/dark-full-page-desktop-linux.png differ diff --git a/e2e/landing-visual-dark.spec.ts-snapshots/dark-full-page-mobile-linux.png b/e2e/landing-visual-dark.spec.ts-snapshots/dark-full-page-mobile-linux.png index 769cae3f2..ed55cde0e 100644 Binary files a/e2e/landing-visual-dark.spec.ts-snapshots/dark-full-page-mobile-linux.png and b/e2e/landing-visual-dark.spec.ts-snapshots/dark-full-page-mobile-linux.png differ diff --git a/e2e/landing-visual-dark.spec.ts-snapshots/dark-section-react-native-linux.png b/e2e/landing-visual-dark.spec.ts-snapshots/dark-section-react-native-linux.png new file mode 100644 index 000000000..858243d62 Binary files /dev/null and b/e2e/landing-visual-dark.spec.ts-snapshots/dark-section-react-native-linux.png differ diff --git a/e2e/landing-visual-dark.spec.ts-snapshots/dark-section-react-native-win32.png b/e2e/landing-visual-dark.spec.ts-snapshots/dark-section-react-native-win32.png new file mode 100644 index 000000000..41bf3141e Binary files /dev/null and b/e2e/landing-visual-dark.spec.ts-snapshots/dark-section-react-native-win32.png differ diff --git a/e2e/landing-visual-dark.spec.ts-snapshots/dark-section-top-banner-linux.png b/e2e/landing-visual-dark.spec.ts-snapshots/dark-section-top-banner-linux.png index 9010ed39e..e5e09e862 100644 Binary files a/e2e/landing-visual-dark.spec.ts-snapshots/dark-section-top-banner-linux.png and b/e2e/landing-visual-dark.spec.ts-snapshots/dark-section-top-banner-linux.png differ diff --git a/e2e/landing-visual.spec.ts b/e2e/landing-visual.spec.ts index a22b3612c..3b8ab14fb 100644 --- a/e2e/landing-visual.spec.ts +++ b/e2e/landing-visual.spec.ts @@ -83,6 +83,24 @@ test.describe('Landing Page - Visual Regression', () => { await expect(featureSection).toHaveScreenshot('section-features.png') }) + test('React Native section', 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( + 'section-react-native.png', + ) + }) + test('Bench section', async ({ page }) => { const benchHeading = page.getByText('Comparison Benchmarks').first() await benchHeading.scrollIntoViewIfNeeded() diff --git a/e2e/landing-visual.spec.ts-snapshots/full-page-desktop-linux.png b/e2e/landing-visual.spec.ts-snapshots/full-page-desktop-linux.png index 709909682..96d8f6113 100644 Binary files a/e2e/landing-visual.spec.ts-snapshots/full-page-desktop-linux.png and b/e2e/landing-visual.spec.ts-snapshots/full-page-desktop-linux.png differ diff --git a/e2e/landing-visual.spec.ts-snapshots/full-page-mobile-linux.png b/e2e/landing-visual.spec.ts-snapshots/full-page-mobile-linux.png index d23321e04..b23bec2cf 100644 Binary files a/e2e/landing-visual.spec.ts-snapshots/full-page-mobile-linux.png and b/e2e/landing-visual.spec.ts-snapshots/full-page-mobile-linux.png differ diff --git a/e2e/landing-visual.spec.ts-snapshots/section-react-native-linux.png b/e2e/landing-visual.spec.ts-snapshots/section-react-native-linux.png new file mode 100644 index 000000000..0016ff6c3 Binary files /dev/null and b/e2e/landing-visual.spec.ts-snapshots/section-react-native-linux.png differ diff --git a/e2e/landing-visual.spec.ts-snapshots/section-react-native-win32.png b/e2e/landing-visual.spec.ts-snapshots/section-react-native-win32.png new file mode 100644 index 000000000..38f56e751 Binary files /dev/null and b/e2e/landing-visual.spec.ts-snapshots/section-react-native-win32.png differ diff --git a/e2e/landing-visual.spec.ts-snapshots/section-top-banner-linux.png b/e2e/landing-visual.spec.ts-snapshots/section-top-banner-linux.png index 437b9834c..469795cf3 100644 Binary files a/e2e/landing-visual.spec.ts-snapshots/section-top-banner-linux.png and b/e2e/landing-visual.spec.ts-snapshots/section-top-banner-linux.png differ