Skip to content
Tutorials Center
My learning

Topics

Lesson 26 of 71 ยท Components and Interaction

UI Recipes: Radio Buttons, Tables, Search Bars, FABs, Avatars, Menus and Calendars

Build common React Native UI pieces: radio groups, data tables, search bars, floating action buttons, avatars, progress bars, menus, image preview, GIFs and calendars.

React Native gives you primitives: View, Text, Pressable, FlatList. Real apps need bigger pieces that those primitives do not provide by themselves: a group of radio buttons, a table, a search bar, a floating action button, an avatar, a progress bar, a drop-down menu. You can build every one of them in a few lines from the core components, or take them from a UI library such as React Native Paper or React Native Elements. This lesson shows both: what the library version looks like, and a stand-in that implements the logic (selection, sorting, filtering, clamping, date maths) so you understand what the library does for you.

What runs on this site. React Native Paper, React Native Elements, the image picker and calendar packages need a native runtime, so their real code is read-only. The runnable examples are stand-ins with the same props, written with plain React and HTML.

Radio buttons

React Native has no built-in radio button. A radio group is one piece of state (selected) and a list of options, each rendering as a Pressable with a ring that is filled when selected. The important parts are the single selection, the accessibility role (radio inside a radiogroup) and a big enough tap target.

JSX
import { useState } from 'react';
import { Pressable, Text, View } from 'react-native';

export function RadioGroup({ options, value, onChange }) {
  return (
    <View accessibilityRole="radiogroup" style={{ gap: 8 }}>
      {options.map((o) => {
        const selected = o.value === value;
        return (
          <Pressable
            key={o.value}
            onPress={() => onChange(o.value)}
            accessibilityRole="radio"
            accessibilityState={{ checked: selected }}
            style={{ flexDirection: 'row', alignItems: 'center', gap: 10, minHeight: 44 }}
          >
            <View style={[ring, selected && ringOn]}>{selected && <View style={dot} />}</View>
            <Text>{o.label}</Text>
          </Pressable>
        );
      })}
    </View>
  );
}

With React Native Paper the same thing is <RadioButton.Group value={value} onValueChange={setValue}> containing <RadioButton.Item label="Small" value="s" /> rows. A custom radio button, in any library, follows the same state rule.

Data tables

A table on a phone is a list of rows with fixed columns. Build it with a header row and a FlatList of rows; give each column flex or a width so cells line up. Sorting and paging are plain array operations. Paper offers DataTable with DataTable.Header, DataTable.Title, DataTable.Row, DataTable.Cell and DataTable.Pagination.

Search bars

A search bar is a TextInput with an icon, a clear button and a filter function. Keep the query in state and derive the visible list during render; do not store the filtered list as separate state, or the two will get out of step. For large data or network search, debounce the query (see TextInput in Depth). The React Native Elements SearchBar has props such as value, onChangeText, onClear, showCancel (iOS style), lightTheme, round, inputStyle and inputContainerStyle; Paper's Searchbar has value, onChangeText, placeholder and onIconPress.

Radio group, search bar and sortable table (stand-ins)

Notice that rows is derived from team, query and sort, and that changing a filter resets the page to the first one. Forgetting that reset is the usual bug: you filter down to two rows while still on page 3 and see an empty table.

Avatars

An avatar is a round image with fallbacks: the picture if it loads, otherwise initials on a colored circle. A round view needs borderRadius equal to half its size, and the Image inside needs the same radius (images are not clipped by the parent's borderRadius unless the style is also on the image or the parent has overflow: 'hidden').

JSX
function Avatar({ uri, name, size = 48 }) {
  const [failed, setFailed] = useState(false);
  const initials = name.split(' ').map((w) => w[0]).slice(0, 2).join('').toUpperCase();
  const radius = size / 2;
  if (uri && !failed) {
    return <Image source={{ uri }} onError={() => setFailed(true)} style={{ width: size, height: size, borderRadius: radius }} />;
  }
  return (
    <View style={{ width: size, height: size, borderRadius: radius, backgroundColor: '#2563eb', alignItems: 'center', justifyContent: 'center' }}>
      <Text style={{ color: 'white', fontSize: size / 2.5 }}>{initials}</Text>
    </View>
  );
}

Paper provides Avatar.Image, Avatar.Text and Avatar.Icon.

Progress bars

A progress bar is two views: a track and a filled child whose width is a percentage. The value must be clamped to the range 0 to 1, and NaN guarded, because progress callbacks sometimes overshoot.

JSX
function ProgressBar({ progress, color = '#2563eb' }) {
  const p = Number.isFinite(progress) ? Math.min(1, Math.max(0, progress)) : 0;
  return (
    <View
      accessibilityRole="progressbar"
      accessibilityValue={{ min: 0, max: 100, now: Math.round(p * 100) }}
      style={{ height: 8, borderRadius: 4, backgroundColor: '#e2e8f0', overflow: 'hidden' }}
    >
      <View style={{ width: `${p * 100}%`, height: '100%', backgroundColor: color }} />
    </View>
  );
}

Paper's ProgressBar takes progress (0 to 1), color and indeterminate. To animate the fill smoothly, animate the width or a scaleX transform with the Animated API.

Floating action button (FAB)

A FAB is a round button with a shadow, pinned over the content, usually at the bottom right. Use position: 'absolute' with right and bottom, add the safe-area inset so the home indicator does not cover it, and give it an accessibilityLabel because it only shows an icon. The list underneath needs bottom padding so the last row is not hidden behind it. A menu that expands from the FAB (a speed dial) is just a FAB plus a boolean open that renders the extra buttons.

A menu opens next to an anchor (a button) and closes on a tap outside. The pieces are an open flag, the anchor, and an overlay. In Paper, Menu takes visible, onDismiss and anchor, and contains Menu.Item rows; you write the openMenu and closeMenu functions that set the flag. On iOS 14 and later, the OS also has native context menus through libraries such as @react-native-menu/menu. For a short list of actions on mobile, an action sheet (see Modals, Alerts and Sheets) is often a better fit than a drop-down.

Avatar, progress bar, FAB and menu (stand-ins)

Previewing a picked image

Picking and showing a photo takes three steps: ask for permission, open the picker, and keep the chosen image's URI in state. With Expo:

JSX
import * as ImagePicker from 'expo-image-picker';

async function pick() {
  const result = await ImagePicker.launchImageLibraryAsync({
    mediaTypes: ['images'],
    allowsEditing: true,
    quality: 0.8,
  });
  if (!result.canceled) {
    setPhoto(result.assets[0].uri);
  }
}

// ...
{photo ? <Image source={{ uri: photo }} style={{ width: 200, height: 200 }} /> : <Text>No image yet</Text>}

result.canceled is true if the user backed out, so always check it before reading assets. Uploading the file is a separate step: send it as FormData with the URI, a name and a MIME type (see Networking with fetch and Device Features).

GIFs and animated images

The Image component can display animated GIFs from a local require or a URL on iOS, and on Android in current templates and Expo. Older bare Android projects needed extra Fresco dependencies in build.gradle for GIF and animated WebP support; if a GIF shows only its first frame on Android, that is the first thing to check. Large GIFs are heavy (every frame is decoded), so for anything big prefer a short looping video, an animated WebP or a Lottie animation, and expo-image, which handles animated formats well.

Fade in and fade out

A fade is an Animated.Value for opacity and Animated.timing. The key facts: use useNativeDriver: true for opacity, keep the value in a useRef, and run the animation in an effect when a prop changes.

JSX
const opacity = useRef(new Animated.Value(0)).current;

useEffect(() => {
  Animated.timing(opacity, { toValue: visible ? 1 : 0, duration: 250, useNativeDriver: true }).start();
}, [visible]);

return <Animated.View style={{ opacity }}>{children}</Animated.View>;

See The Animated API for the complete tour.

Calendars

For a date picker or an agenda, use a library (react-native-calendars is a popular one: <Calendar onDayPress={...} markedDates={...} />). Underneath, every calendar is the same date calculation: the weekday of the first day, the number of days in the month, and padding so the grid starts on the right column. Doing it yourself takes ten lines.

A month grid from plain date maths

February 2026 starts on a Sunday and has 28 days, so it fills exactly four rows. Move to March and the leading blanks appear.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why should a filtered list be derived during render instead of stored in its own state?

    Store the query and the source data, and compute the filtered rows from them. A second state copy needs manual updates and goes stale.
  2. 2. Why is progress clamped to 0..1 before computing the fill width?

    Values above 1 would overflow the track and NaN gives an invalid width.
  3. 3. What must you check after launchImageLibraryAsync before reading the image?

    If the user backs out, canceled is true and there are no assets.
  4. 4. Which is the usual cause of a GIF that shows only its first frame on older bare Android projects?

    Older bare Android templates needed extra Fresco modules for animated formats; current templates and Expo include support.

Summary

  • Radio groups, tables, search bars, avatars, progress bars, FABs and menus are small compositions of View, Text, Pressable and FlatList; libraries like Paper and Elements package them.
  • Keep the source data and the controls in state and derive the filtered, sorted and paged rows.
  • Clamp progress values, give avatars an initials fallback, pad lists under a FAB and label icon-only buttons.
  • Check result.canceled after the image picker; animated GIFs may need platform support, and big ones are better as video or WebP.
  • A calendar grid is date maths: weekday of the first day, days in the month, and padding.

Next: FlatList.