Caracal Starter
UI & Theming

Custom Components

Documentation for custom UI components built specifically for Caracal starter.

While most UI components come from HeroUI Native, the Caracal starter includes a small set of custom components designed for specific needs not covered by the UI library.

Design Philosophy: We keep custom components minimal and focused. For general UI needs (buttons, inputs, cards, etc.), use HeroUI Native components. Only use these custom components for their specific purposes.

Custom Components Overview

Located in src/components/ui/, these are some of the starter’s shared components:

  1. Image - Expo Image wrapper with Uniwind support
  2. Text - React Native text with template typography
  3. ControlledInput - Form input with react-hook-form integration
  4. List - LegendList re-export
  5. Modal - Bottom sheet modal wrapper
  6. FocusAwareStatusBar - Status bar that updates on screen focus

Image Component

A wrapper around expo-image with Uniwind (TailwindCSS) styling support via the className prop.

Why a custom Image?

  • Uniwind Integration: Native expo-image doesn't support className — this wrapper adds it
  • Performance: Uses expo-image which is faster and more efficient than React Native's Image
  • Consistent API: Provides the same styling approach as other components

Props:

  • All expo-image props are supported
  • className - Uniwind class names for styling

Example:

import { Image } from '@/components/ui';

export function ProfilePicture() {
  return (
    <Image
      className="h-24 w-24 rounded-full"
      source={{ uri: 'https://example.com/avatar.jpg' }}
      contentFit="cover"
    />
  );
}

Common Use Cases:

// Avatar image
<Image className="h-16 w-16 rounded-full" source={avatarUri} />

// Full width banner
<Image className="h-48 w-full" source={bannerUri} contentFit="cover" />

// Card thumbnail
<Image className="h-32 w-32 rounded-lg" source={thumbUri} />

// Icon image
<Image className="h-6 w-6" source={iconUri} contentFit="contain" />

Text Component

Text sets the template’s default font and forwards React Native text props. Use the translation hook for localized copy.

const { t } = useTranslation();
return <Text className="font-bold">{t('settings.language')}</Text>;

ControlledInput Component

A react-hook-form field built from HeroUI Native's TextField, Label, Input / InputGroup, Description and FieldError (src/components/ui/controlled-input.tsx).

Why a custom ControlledInput?

  • Form Integration: Pre-wired with react-hook-form's useController
  • Translated errors: Zod messages are translation keys; the field renders t(message) in a FieldErrorMessage with an alert icon, and the field turns to the red error state while the label stays in the normal color
  • Password toggle: isPassword adds a show/hide eye button (PasswordToggle)
  • Label accessory: Room for an action next to the label, such as "Forgot password?"

Props:

  • control, name — react-hook-form control and field name (required)
  • label — visible label (required)
  • testID — test id of the input (required); the password toggle gets ${testID}-toggle
  • placeholder, description — optional hint text; the description hides while an error shows
  • isPassword — secure entry with a show/hide toggle
  • showPasswordToggle — set to false to hide that toggle (Create account does)
  • icon — an Ionicons name rendered at the start of the field, such as mail-outline
  • fieldClassName — extra classes for the field, for example h-12 for a shorter input
  • labelAccessory — a node rendered at the end of the label row
  • keyboardType, autoComplete, autoCapitalize, textContentType — passed to the input

Example:

import { zodResolver } from '@hookform/resolvers/zod';
import { Button } from 'heroui-native';
import { useForm } from 'react-hook-form';
import { useTranslation } from 'react-i18next';
import * as z from 'zod';

import { ControlledInput, View } from '@/components/ui';

const schema = z.object({
  email: z.string().email('auth.validation.email_invalid'),
  password: z.string().min(6, 'auth.validation.password_min'),
});

type FormData = z.infer<typeof schema>;

export function LoginForm({ onSubmit }: { onSubmit: (data: FormData) => void }) {
  const { t } = useTranslation();
  const { control, handleSubmit } = useForm<FormData>({
    resolver: zodResolver(schema),
    defaultValues: { email: '', password: '' },
  });

  return (
    <View className="gap-4">
      <ControlledInput
        control={control}
        name="email"
        label={t('auth.email')}
        testID="login-email-input"
        keyboardType="email-address"
        autoCapitalize="none"
      />
      <ControlledInput
        control={control}
        name="password"
        label={t('auth.password')}
        testID="login-password-input"
        isPassword
      />
      <Button onPress={handleSubmit(onSubmit)}>{t('auth.login.submit')}</Button>
    </View>
  );
}

See Also: Forms documentation for complete form handling patterns.


List Component

List re-exports LegendList from @legendapp/list/react-native. The Home feed enables recycleItems to reuse offscreen cells. Supply a ListEmptyComponent when the screen needs its own empty state. The feed’s empty-state component lives in src/components/home/post-empty-state.tsx.

The template’s Modal wraps HeroUI Native’s BottomSheet (TrueSheet). It provides an optional title, a close button, and a backdrop with 40% dimming. The sheet fits its content by default.

import { Button } from 'heroui-native';
import { Modal, Text, useModal, View } from '@/components/ui';

export function SettingsExample() {
  const modal = useModal();

  return (
    <View>
      <Button onPress={modal.present}>Open settings</Button>
      <Modal ref={modal.ref} title="Settings">
        <Text>Choose your preferences.</Text>
        <Button onPress={modal.dismiss}>Done</Button>
      </Modal>
    </View>
  );
}

For multiple heights, pass up to three detents in ascending order, such as detents={[0.6, 0.9]}. Fractions refer to the available height. Call modal.ref.current?.present(1) to open at the second height or modal.ref.current?.resize(1) on an open sheet. For scrollable content, use a bounded detent and pass the inner React Native ScrollView ref to scrollableRef. Use HeroUI’s compound BottomSheet directly for a custom header or sticky footer. HeroUI BottomSheet API


FocusAwareStatusBar Component

A status bar for the currently focused Expo Router screen, built on StatusBar from expo-status-bar.

Why FocusAwareStatusBar?

  • Theme-aware: The status bar text is dark in the light theme and light in the dark theme, following the app theme rather than the system setting.
  • Route-aware: Only the focused screen renders it, so a screen can hide the status bar without affecting the others.
  • Edge-to-edge ready: Expo SDK 58 always draws Android apps edge-to-edge with transparent system bars. Use safe area insets to keep content clear of them.

Props:

  • hidden (optional, default false): hides the status bar while the screen is focused.

Example:

import { FocusAwareStatusBar, View, Text } from '@/components/ui';

export default function FullscreenScreen() {
  return (
    <View className="flex-1">
      <FocusAwareStatusBar hidden />
      <Text className="text-2xl">Fullscreen content</Text>
    </View>
  );
}

Re-exported React Native Components

src/components/ui/index.tsx also re-exports common React Native components with Uniwind support:

import {
  View,              // React Native View
  ScrollView,        // React Native ScrollView
  ActivityIndicator, // React Native ActivityIndicator
  Pressable,         // React Native Pressable
  TouchableOpacity,  // React Native TouchableOpacity
  StyledSafeAreaView,      // react-native-safe-area-context
} from '@/components/ui';

Usage:

import { View, ScrollView, StyledSafeAreaView } from '@/components/ui';

export function MyScreen() {
  return (
    <StyledSafeAreaView className="flex-1">
      <ScrollView className="flex-1">
        <View className="p-4">
          {/* Content */}
        </View>
      </ScrollView>
    </StyledSafeAreaView>
  );
}

When to Create Custom Components

Create a custom component when:

  1. HeroUI Native doesn't provide it — for example, the template’s default typography
  2. Specific integration needed — like ControlledInput for react-hook-form
  3. Performance optimization required — like List wrapping LegendList
  4. Platform-specific behavior — like FocusAwareStatusBar for Expo Router

Don't create custom components for:

  • Buttons, inputs, cards, dialogs → use HeroUI Native
  • Standard layouts → use View, ScrollView from @/components/ui
  • Icons → create SVG components alongside the component that owns them

Import Patterns

Correct imports:

// Custom components
import {
  Image,
  Text,
  View,
  ControlledInput,
  List,
  Modal,
  FocusAwareStatusBar,
} from '@/components/ui';

// HeroUI Native components
import {
  Button,
  TextField,
  Card,
  Dialog,
} from 'heroui-native';

Incorrect imports:

// Don't import HeroUI Native components from @/components/ui
import { Button } from '@/components/ui';

// Don't import custom components from heroui-native
import { Text } from 'heroui-native';

Adding New Custom Components

If you need to add a custom component:

  1. Check HeroUI Native first — does it already provide what you need?
  2. Create in src/components/ui/ — follow existing file structure
  3. Export from index.tsx — add to the main export file
  4. Support className — use withUniwind() if needed
  5. Keep it simple — avoid over-engineering

Example structure:

// src/components/ui/my-component.tsx
import * as React from 'react';
import { View } from 'react-native';
import { withUniwind } from 'uniwind';

type MyComponentProps = {
  children: React.ReactNode;
  className?: string;
};

const MyComponentBase = ({ children, ...props }: MyComponentProps) => {
  return <View {...props}>{children}</View>;
};

export const MyComponent = withUniwind(MyComponentBase);
// src/components/ui/index.tsx
export * from './my-component';

Styling Custom Components

All custom components support the className prop for Uniwind styling:

import { Text, View, Image } from '@/components/ui';

<View className="flex-1 bg-white p-4">
  <Image className="h-32 w-32 rounded-full mb-4" source={avatar} />
  <Text className="text-2xl font-bold text-gray-900">Title</Text>
  <Text className="text-base text-gray-600">Subtitle</Text>
</View>

Exception: Components using Animated.View from react-native-reanimated must use the style prop:

import Animated from 'react-native-reanimated';

// Won't work
<Animated.View className="flex-1" />

// Correct
<Animated.View style={{ flex: 1 }} />

Resources


Summary

Use HeroUI Native for:

  • Buttons, TextField, Card, Dialog, Tabs, Checkbox, Switch, Select, etc.
  • Any standard UI component
  • Form controls

Use Custom Components for:

  • Image (Uniwind support)
  • Text (template typography)
  • ControlledInput (form integration)
  • List (LegendList wrapper)
  • Modal (bottom sheet)
  • FocusAwareStatusBar (Expo Router integration)

On this page