# Settings screen

> A React Native settings screen for iOS, Android and the web: a profile row with an avatar, grouped lists with icons, switches that depend on each other, language and appearance selects shown as list rows, and a destructive sign-out. One file, built with Patine's Header, List, ListItem, Switch, Select and Avatar.

# Settings

The settings screen every app ends up with: the account at the top, grouped rows with icons, switches (the ones under **Push notifications** turn off with it), language and appearance as rows that open a picker, and **Sign out** in red at the bottom.

```tsx live device
import { useState } from 'react';
import { ScrollView, StyleSheet, View } from 'react-native';
import { Avatar, Header, List, ListItem, Select, Switch, useTheme } from 'patine-ui';
import { Icon } from '@patine-ui/icons';
import type { IconName } from '@patine-ui/icons';

const LANGUAGES = [
  { label: 'English', value: 'en' },
  { label: 'Español', value: 'es' },
  { label: 'Français', value: 'fr' },
  { label: 'Português', value: 'pt' },
  { label: 'עברית', value: 'he' },
];
const APPEARANCES = [
  { label: 'System', value: 'system' },
  { label: 'Light', value: 'light' },
  { label: 'Dark', value: 'dark' },
];

/** A row's icon on a tinted square, like the system settings. */
const RowIcon = ({ name, color }: { name: IconName; color: string }) => (
  <View style={[styles.rowIcon, { backgroundColor: color }]}>
    <Icon name={name} size="sm" color="#fff" />
  </View>
);

export default function Settings() {
  const { colors } = useTheme();
  const [push, setPush] = useState(true);
  const [mentions, setMentions] = useState(true);
  const [digest, setDigest] = useState(false);
  const [faceId, setFaceId] = useState(true);
  const [language, setLanguage] = useState('en');
  const [appearance, setAppearance] = useState('system');

  return (
    <View style={[styles.screen, { backgroundColor: colors.background }]}>
      <Header title="Settings" />
      <ScrollView contentContainerStyle={styles.content}>
        <List>
          <ListItem
            title="Ana Ribeiro"
            description="ana@ribeiro.pt · Family plan"
            leading={<Avatar name="Ana Ribeiro" src="https://picsum.photos/id/64/160/160" size="lg" />}
            onPress={() => {}}
          />
        </List>

        <List title="Notifications" footer="Quiet hours still apply to everything above.">
          <ListItem
            title="Push notifications"
            leading={<RowIcon name="bell" color="#E5484D" />}
            trailing={<Switch accessibilityLabel="Push notifications" checked={push} onCheckedChange={setPush} />}
          />
          <ListItem
            title="Replies and mentions"
            leading={<RowIcon name="at" color="#3E63DD" />}
            disabled={!push}
            trailing={
              <Switch accessibilityLabel="Replies and mentions" checked={push && mentions} onCheckedChange={setMentions} disabled={!push} />
            }
          />
          <ListItem
            title="Weekly digest"
            description="Mondays at 9:00"
            leading={<RowIcon name="mail" color="#8E4EC6" />}
            trailing={<Switch accessibilityLabel="Weekly digest" checked={digest} onCheckedChange={setDigest} />}
          />
        </List>

        <List title="Preferences">
          <Select
            sheetTitle="Language"
            options={LANGUAGES}
            value={language}
            onValueChange={setLanguage}
            renderTrigger={({ open, selected }) => (
              <ListItem
                title="Language"
                value={selected[0]?.label}
                leading={<RowIcon name="globe" color="#0090FF" />}
                onPress={open}
              />
            )}
          />
          <Select
            sheetTitle="Appearance"
            options={APPEARANCES}
            value={appearance}
            onValueChange={setAppearance}
            renderTrigger={({ open, selected }) => (
              <ListItem title="Appearance" value={selected[0]?.label} leading={<RowIcon name="moon" color="#5B5BD6" />} onPress={open} />
            )}
          />
        </List>

        <List title="Privacy & security">
          <ListItem
            title="Unlock with Face ID"
            leading={<RowIcon name="fingerprint" color="#30A46C" />}
            trailing={<Switch accessibilityLabel="Unlock with Face ID" checked={faceId} onCheckedChange={setFaceId} />}
          />
          <ListItem title="Connected devices" value="3" leading={<RowIcon name="smartphone" color="#F76B15" />} onPress={() => {}} />
          <ListItem title="Download my data" leading={<RowIcon name="download" color="#687076" />} onPress={() => {}} />
        </List>

        <List>
          <ListItem title="Sign out" destructive showChevron={false} onPress={() => {}} />
        </List>
      </ScrollView>
    </View>
  );
}

const styles = StyleSheet.create({
  screen: { flex: 1 },
  content: { gap: 24, paddingVertical: 16 },
  rowIcon: { width: 28, height: 28, borderRadius: 7, alignItems: 'center', justifyContent: 'center' },
});
```

## Components used

- [Header](/docs/components/header): the screen's title bar
- [List, ListItem](/docs/components/list): grouped rows with `leading`, `trailing`, `value`, `description`, `disabled` and `destructive`
- [Switch](/docs/components/switch): each toggle, with an `accessibilityLabel` since the row holds the visible label
- [Select](/docs/components/select): `renderTrigger` turns the field into a list row that opens the options
- [Avatar](/docs/components/avatar): the account's photo, with initials while it loads
- [Patine Icons](/docs/components/icons)

## How it works

- **A select as a row.** `renderTrigger` gets `open` and the `selected` options, so the row shows the current language and opens the same sheet (or dropdown on the web) a field would.
- **Dependent switches.** The rows under Push notifications read `push`: off greys them out and shows them off, without forgetting what they were set to.
