# Display and text size settings

> A React Native display settings screen for iOS, Android and the web: a brightness slider with icons, a text size slider that snaps to labelled marks, and focus hours as a range slider, all previewed live as you drag. One file, built with Patine's Slider.

# Display & text

Three sliders that preview as you drag: brightness dims the card above them, text size snaps to five labelled sizes like the system's Larger Text, and focus hours are a range across the day.

```tsx live device
import { useState } from 'react';
import { ScrollView, StyleSheet, View } from 'react-native';
import { Heading, HStack, Slider, Text, useTheme } from 'patine-ui';
import { Icon } from '@patine-ui/icons';

const TEXT_SIZES = [
  { value: 13, label: 'XS' },
  { value: 15, label: 'S' },
  { value: 17, label: 'M' },
  { value: 20, label: 'L' },
  { value: 24, label: 'XL' },
];
const HOURS = [
  { value: 0, label: '12a' },
  { value: 6, label: '6a' },
  { value: 12, label: 'Noon' },
  { value: 18, label: '6p' },
  { value: 24, label: '12a' },
];
const hour = (h: number) => `${h % 12 || 12} ${h % 24 < 12 ? 'AM' : 'PM'}`;

export default function DisplaySettings() {
  const { colors, radius } = useTheme();
  const [brightness, setBrightness] = useState(70);
  const [textSize, setTextSize] = useState(17);
  const [focus, setFocus] = useState<[number, number]>([9, 17]);

  return (
    <ScrollView style={{ backgroundColor: colors.background }} contentContainerStyle={styles.content}>
      <View style={styles.titles}>
        <Heading level={2}>Display & text</Heading>
        <Text color="textSecondary">
          Focus {hour(focus[0])} – {hour(focus[1])}
        </Text>
      </View>

      {/* Never fully dark, so the preview stays readable at the lowest brightness. */}
      <View style={[styles.preview, { backgroundColor: colors.surface, borderRadius: radius.lg, opacity: 0.3 + (0.7 * brightness) / 100 }]}>
        <Text weight="semibold" style={{ fontSize: textSize + 2 }}>
          Good morning
        </Text>
        <Text color="textSecondary" style={{ fontSize: textSize }}>
          Three meetings today, the first at 10.
        </Text>
      </View>

      <View style={styles.setting}>
        <HStack justify="space-between">
          <Text weight="medium">Brightness</Text>
          <Text color="textSecondary">{brightness}%</Text>
        </HStack>
        <Slider
          value={brightness}
          onValueChanging={setBrightness}
          onValueChange={setBrightness}
          minimumIcon={<Icon name="sun" size="sm" />}
          maximumIcon={<Icon name="sun" size="lg" />}
          formatValue={(v) => `${v}%`}
          accessibilityLabel="Brightness"
        />
      </View>

      <View style={styles.setting}>
        <HStack justify="space-between">
          <Text weight="medium">Text size</Text>
          <Text color="textSecondary">{TEXT_SIZES.find((s) => s.value === textSize)?.label}</Text>
        </HStack>
        <Slider
          min={13}
          max={24}
          marks={TEXT_SIZES}
          snapToMarks
          value={textSize}
          onValueChanging={setTextSize}
          onValueChange={setTextSize}
          formatValue={(v) => `${v} pt`}
          accessibilityLabel="Text size"
        />
      </View>

      <View style={styles.setting}>
        <HStack justify="space-between">
          <Text weight="medium">Focus hours</Text>
          <Text color="textSecondary">{focus[1] - focus[0]} h</Text>
        </HStack>
        <Slider
          range
          min={0}
          max={24}
          marks={HOURS}
          value={focus}
          onValueChanging={setFocus}
          onValueChange={setFocus}
          formatValue={hour}
          thumbLabels={['Focus starts', 'Focus ends']}
          accessibilityLabel="Focus hours"
        />
      </View>
    </ScrollView>
  );
}

const styles = StyleSheet.create({
  content: { gap: 24, padding: 20 },
  titles: { gap: 4 },
  preview: { gap: 4, padding: 16 },
  setting: { gap: 6 },
});
```

## Components used

- [Slider](/docs/components/slider): `minimumIcon` and `maximumIcon`, `marks` with `snapToMarks`, `range` with `thumbLabels`, and `onValueChanging` for the live preview
- [Heading, Text](/docs/components/text), [HStack](/docs/components/stack), [Patine Icons](/docs/components/icons)

## How it works

- **Live while dragging.** `onValueChanging` fires on every move, so the preview follows the finger; `onValueChange` fires when it's let go, which is where you'd save.
- **Only real sizes.** With `snapToMarks`, the text size can only land on one of the five marks, and the screen reader reads the mark.
- **A range of hours.** `range` gives two thumbs, each with its own label for screen readers.
