Урок 11

UI-библиотеки

Готовые компоненты ускоряют разработку. Разберём основные.

React Native Paper

Material Design для React Native:

npm install react-native-paper
import { PaperProvider, Button, Card, TextInput, Appbar } from 'react-native-paper';

export default function App() {
    return (
        <PaperProvider>
            <Appbar.Header>
                <Appbar.Content title="Заголовок" />
                <Appbar.Action icon="magnify" onPress={() => {}} />
            </Appbar.Header>

            <Card>
                <Card.Title title="Заголовок" subtitle="Подзаголовок" />
                <Card.Content>
                    <TextInput label="Email" mode="outlined" />
                </Card.Content>
                <Card.Actions>
                    <Button mode="contained" onPress={() => {}}>Отправить</Button>
                </Card.Actions>
            </Card>
        </PaperProvider>
    );
}

Плюсы: полный набор, темы, типизация. Минусы: Material Design — не для всех.

React Native Elements

Универсальная библиотека:

npm install @rneui/themed @rneui/base
import { Button, Card, Input, Avatar } from '@rneui/themed';

<Button title="Нажми" onPress={() => {}} />
<Input placeholder="Email" leftIcon={{ type: 'feather', name: 'mail' }} />
<Card>
    <Card.Title>Заголовок</Card.Title>
    <Card.Divider />
    <Card.Image source={{ uri: url }} />
</Card>
<Avatar rounded source={{ uri: url }} />

Tamagui

Современная дизайн-система:

npm install tamagui @tamagui/config
import { Button, Text, View, TamaguiProvider } from 'tamagui';
import config from '@tamagui/config/v3';

<TamaguiProvider config={config}>
    <View padding="$4" backgroundColor="$background">
        <Text fontSize="$6" color="$color">Заголовок</Text>
        <Button theme="active">Нажми</Button>
    </View>
</TamaguiProvider>

Плюсы: темы, токены, работает на web и native. Минусы: кривая обучения.

Gluestack UI

Аналог shadcn/ui для React Native:

npm install @gluestack-ui/themed @gluestack-ui/config

Копируешь компоненты в проект, не зависишь от версий.

NativeBase

npm install native-base react-native-svg react-native-safe-area-context
import { Box, Button, Text, Input, VStack } from 'native-base';

<VStack space={4}>
    <Input placeholder="Email" />
    <Button>Отправить</Button>
</VStack>

Специализированные

  • react-native-gifted-chat — чат
  • react-native-calendars — календарь
  • react-native-maps — карты
  • @shopify/flash-list — быстрый список
  • react-native-bottom-sheet — bottom sheet

NativeWind

Tailwind для React Native:

npm install nativewind
<View className="flex-1 bg-white p-4">
    <Text className="text-xl font-bold text-gray-900">Заголовок</Text>
</View>

Работает как Tailwind в вебе. Плюс для тех, кто знает Tailwind.

Что выбрать

  • Material Design → React Native Paper
  • Универсально → React Native Elements
  • Современно, темы → Tamagui
  • Tailwind → NativeWind
  • Полный контроль → StyleSheet

Когда не использовать

Библиотеки экономят время, но добавляют зависимость. Если нужен один компонент — проще написать свой, чем тянуть всю библиотеку.

Итоги

  • React Native Paper — Material
  • Tamagui — современная дизайн-система
  • NativeWind — Tailwind
  • Специализированные для карт, чатов
  • Иногда проще свой компонент