React Native · Components
NotificationCenter
Notification center (same API as web): a bell button, an unread count badge and the notification list it opens.
Live example
The preview runs in the browser with the web component; the native component takes the same props and looks the same on iOS and Android.
Preview
Code
Events
- Events appear here when you interact with the preview.
Import
NotificationCenter
componentNotification center (same API as web): a bell button, an unread count badge and the notification list it opens.
- List: grouped by day (Today, Yesterday…), times written relatively; unread ones dotted and highlighted. An icon or avatar, action buttons, deleting with ×. Long lists scroll in a virtual list.
- Tabs: All / Unread or your own categories.
- Read: on press, when the panel closes, or manually (
readOn). - Live: when a new notification arrives the bell shakes and screen readers announce it (no shake with reduced motion).
- Mobile: on a phone the panel is a bottom sheet; pulling down and the back button close it. Embedded in the screen with
inline.
If you do not want to hold the state yourself, see useNotifications.
Examples
useNotifications
functionReady-made state for NotificationCenter: add, mark as read, delete. If you need to save to a server, bind the component's events yourself; this hook only holds client state.
Examples
NotificationItemAction
interfaceAn action button on a NotificationItem ("Accept", "Decline"). NotificationAction on web; on native that name is the action of device notifications.
| Name | Type | Default | Description |
|---|---|---|---|
label | ReactNode | Button text. | |
onPress | () => unknown | Called when pressed. If it returns a Promise the button shows loading until it finishes. | |
primary? | boolean | false | The primary action is filled, others are outlined. |
NotificationItem
interfaceA notification in the NotificationCenter (same fields as on web).
| Name | Type | Default | Description |
|---|---|---|---|
id | string | Unique id. | |
title | ReactNode | Title ("Jane commented"). | |
description? | ReactNode | Details; at most two lines are visible. | |
date | Date | string | number | Time of the notification; written relatively like "3 min ago", grouped by day. | |
read? | boolean | false | Whether it is read. Unread ones are highlighted and dotted. |
icon? | IconProp | Leading icon (when there is no avatar). | |
tone? | Tone | "primary" | Icon color. |
avatar? | string | ReactNode | Avatar on the left: an image address or an element (e.g. <Avatar … />). | |
href? | string | Address to open when pressed (openLink: in-app paths navigate). | |
actions? | readonly NotificationItemAction[] | Action buttons below the row. | |
category? | string | Category for splitting into tabs (e.g. "mention", "system"). |
NotificationTab
interfaceA tab on top of the NotificationCenter.
| Name | Type | Description |
|---|---|---|
value | string | Key of the tab: "all", "unread" or a category. |
label | ReactNode | Tab text. |
When the NotificationCenter counts notifications as read (same as web).
NotificationCenterStyles
interfaceStyles of the inner parts of NotificationCenter.
| Name | Type | Description |
|---|---|---|
trigger? | ViewStyle | Bell button. |
badge? | ViewStyle | Unread count badge. |
panel? | ViewStyle | The opened panel (or the inline box). |
item? | ViewStyle | Notification row. |
group? | ViewStyle | Day heading. |
NotificationCenterProps
interfaceProps of the NotificationCenter component (same names as on web).
| Name | Type | Default | Description |
|---|---|---|---|
items | readonly NotificationItem[] | Notifications; they need not be sorted, they are ordered newest first. | |
onRead? | (ids: string[]) => void | Called with the ids when notifications are read. | |
onReadAll? | () => void | "Mark all as read". If omitted onRead is called with all unread ones. | |
onRemove? | (id: string) => void | When deleted with × on a row; if omitted × is not shown. | |
onClear? | () => void | "Clear all"; if omitted the button is not shown. | |
onSelect? | (item: NotificationItem) => void | Called when a notification is pressed (before navigating). | |
readOn? | NotificationReadMode | "click" | When it counts as read. |
tabs? | boolean | readonly NotificationTab[] | true | Tabs on top: true All/Unread, an array your own tabs, false none. |
groupByDay? | boolean | true | Group by day ("Today", "Yesterday")? |
title? | ReactNode | the `notifications` text | Panel title. |
actions? | ReactNode | Extra content next to the title (e.g. a settings button). | |
footer? | ReactNode | Bottom of the panel (e.g. "See all"). | |
empty? | ReactNode | Content shown when there are no notifications. | |
onLoadMore? | () => unknown | Loads the next page; called when reaching the end of the list. | |
hasMore? | boolean | false | Whether there are more notifications to load. |
loading? | boolean | Whether the initial load is in progress. | |
inline? | boolean | A list embedded in the screen instead of a panel (e.g. a notifications screen). No bell is drawn. | |
trigger? | ReactElement | Open button to use instead of the bell. | |
icon? | IconProp | bell | Bell icon. |
badgeTone? | Tone | "danger" | Badge color. |
announce? | boolean | true | Shake the bell and announce to screen readers when a new notification arrives? |
side? | Placement | "bottom-right" | Panel position (on a tablet); on a phone it opens from the bottom. |
open? | boolean | Whether the panel is open in controlled use. | |
defaultOpen? | boolean | false | Open initially in uncontrolled use? |
onOpenChange? | (open: boolean) => void | When the panel opens or closes. | |
maxHeight? | number | List height limit (dp). If omitted, as much as fits the screen (at most 512). | |
style? | ViewStyle | Container style. | |
styles? | NotificationCenterStyles | Styles of the inner parts. | |
effect? | EffectProp | Effect of the rows (e.g. "ripple"). Defaults to appearance.defaults.notificationCenter.effect. | |
testID? | string | Test id (bell button). |
UseNotificationsResult
interfaceValue returned by the useNotifications hook.
| Name | Type | Description |
|---|---|---|
items | NotificationItem[] | Notifications, newest to oldest. |
unreadCount | number | Number of unread notifications. |
add | (item: Omit<NotificationItem, "id" | "date"> & Partial<Pick<NotificationItem, "id" | "date">>) => string | Adds a new notification (at the top); an id is generated if not given, date defaults to now. |
markRead | (ids: readonly string[]) => void | Marks the given notifications as read. |
markAllRead | () => void | Marks all as read. |
remove | (id: string) => void | Deletes a notification. |
clear | () => void | Deletes all. |
setItems | (items: NotificationItem[]) => void | Replaces the list (e.g. the first page from the server). |
props | { items: NotificationItem[]; onRead: (ids: string[]) => void; onReadAll: () => void; onRemove: (id: string) => void; onClear: () => void; } | Props to spread onto NotificationCenter: <NotificationCenter {...notifications.props} />. |