HOWTO · React Native
How to Include Icon Button in React Native
This tutorial provides a comprehensive guide on how to include an icon button in React Native. Learn to install necessary libraries, create customizable icon buttons, and add functionality to enhance user experience. Perfect for both beginners and experienced developers, this guide covers all you need to know for effective implementation in your mobile applications.
On this page
An icon button is a compact control for a single, familiar action. In React Native, use IconButton from react-native-paper to show an icon, give the control an accessible label, and connect its onPress callback. This guide uses one library throughout; its setup depends on whether your app uses Expo or a bare React Native project.
What an Icon Button Does
An icon button combines a tappable control with an icon such as a bell for notifications. It can save space when the action is recognizable, but the icon alone may be ambiguous. Add an accessibility label that describes the action, and use a nearby text label when people may not know what the icon means.
Choose and Set Up an Icon Library
This example uses react-native-paper rather than mixing icon packages. Install it and its safe-area dependency with the package manager for your app:
- Expo: run
npx expo install react-native-paper react-native-safe-area-context. Expo selects compatible versions for the SDK in the project. - Bare React Native: run
npm install react-native-paper react-native-safe-area-context. If your selected Paper version requires a separate icon package for thebellicon, install the package named in that version’s setup guide as well. React Native autolinks native dependencies in supported versions; rebuild the app after installing native packages, and only add manual linking if the instructions for your version call for it.
Then wrap the app (or the screen tree that uses Paper components) in PaperProvider, imported from react-native-paper; the provider makes the library theme available. A minimal root setup is return <PaperProvider><App /></PaperProvider>;. Keep the project’s existing root component and add the wrapper there rather than creating a second app root. Setup details can change with the Expo SDK, React Native version, and Paper release, so use the official React Native Paper getting-started guide for the installed version, including its icon setup instructions.
Create and Customize an Icon Button
Import IconButton from react-native-paper and place it in a screen component. This component-specific sketch shows the app code to adapt; the configured article runtime does not provide React Native or react-native-paper, so it is not presented as an executed runtime example.
import { IconButton } from 'react-native-paper';
function NotificationsButton({ onPress }) { return <IconButton icon="bell" size={28} iconColor="#FFFFFF" containerColor="#315EFB" accessibilityLabel="Show notifications" onPress={onPress} />; }
The icon value selects the library icon, size changes its dimensions, and the color props set the icon and button background. Choose a label that names the action, not just the image. If the installed package version exposes different props or icon names, use the API documented for that version. Keep contrast sufficient for the button to remain distinguishable from its screen background.
Handle Presses and Check the Result
Pass a function to onPress; React Native Paper calls it when the control is pressed. The following self-contained JavaScript example illustrates the handler flow without importing mobile UI packages. It does not render a native screen. In your app, pass the same handler to NotificationsButton and check both the visible control and the action on a simulator or device.
Run this example:
function createNotificationsButton(onPress) {
return { accessibilityLabel: 'Show notifications', onPress };
}
const button = createNotificationsButton(() => console.log('Notifications opened'));
button.onPress();
Notifications opened
When checking the app, confirm that the icon appears, the label is announced by the platform’s accessibility tools, and a press triggers the intended action. If the icon is missing, check that the chosen package setup matches the app type and installed versions. If the callback does not run, confirm that the handler is passed to onPress and that another view is not intercepting the touch.