시작하기
앱 (Expo)
React Native에서는 같은 값을 Restyle의 Box · Text로 쓴다. 이름이 웹 클래스와 1:1로 맞는다.
1. 설치
Terminal
npm i github:ckdtjs505/sonia-ui @shopify/restyle react-native-safe-area-context
2. ThemeProvider로 감싸기
App.tsx
import { ThemeProvider, getTheme } from "sonia-ui/native";
export default function App() {
return (
<ThemeProvider theme={getTheme("dark")}>
<Home />
</ThemeProvider>
);
}
3. Box · Text 쓰기
Home.tsx
import { Box, Text } from "sonia-ui/native";
<Box backgroundColor="$surface" padding="lg" borderRadius="md">
<Text variant="title">안녕</Text>
<Text variant="caption">sonia-ui로 만든 카드</Text>
</Box>
웹 ↔ 앱 이름
| Class | Styles |
|---|---|
| bg-primary | backgroundColor="$primary" |
| text-muted | color="$muted" |
| p-lg | padding="lg" |
| gap-md | gap="md" |
| rounded-md | borderRadius="md" |
| text-title | variant="title" |
| data-theme="dark" | getTheme("dark") |
Jest
TS 소스를 그대로 배포하므로 transformIgnorePatterns 허용 목록에 sonia-ui를 넣는다.