Teardown

Notification Adapters

Push notification adapters for token registration and management.

Notification adapters handle push notification token registration and management with your push notification provider.

Available Adapters

AdapterPackageBest For
ExpoNotificationsAdapterexpo-notificationsExpo projects
FirebaseMessagingAdapter@react-native-firebase/messagingFirebase Cloud Messaging
WixNotificationsAdapterreact-native-notificationsWix notifications library

Usage

Notification adapters are optional and used separately from the core SDK:

import { ExpoNotificationsAdapter } from '@teardown/react-native/expo-notifications';

const notificationsAdapter = new ExpoNotificationsAdapter();

// Get push token
const token = await notificationsAdapter.getToken();

// Register token with your backend
await registerPushToken(token);

Adapter Interface

All notification adapters implement:

interface NotificationsAdapter {
  /** Get the push notification token */
  getToken(): Promise<string | null>;

  /** Request notification permissions */
  requestPermissions(): Promise<boolean>;

  /** Check if notifications are enabled */
  isEnabled(): Promise<boolean>;

  /** Subscribe to incoming notifications */
  onNotification(handler: (notification: Notification) => void): () => void;

  /** Subscribe to notification responses (user taps) */
  onNotificationResponse(handler: (response: NotificationResponse) => void): () => void;
}

Choosing an Adapter

If you're using...Use this adapter
Expo with expo-notificationsExpoNotificationsAdapter
Firebase Cloud MessagingFirebaseMessagingAdapter
Wix react-native-notificationsWixNotificationsAdapter
Other push libraryImplement custom adapter

Custom Adapter

Implement the NotificationsAdapter interface:

import type { NotificationsAdapter, Notification, NotificationResponse } from '@teardown/react-native';

class CustomNotificationsAdapter implements NotificationsAdapter {
  async getToken(): Promise<string | null> {
    // Return push token from your notification library
    return await myNotificationLib.getToken();
  }

  async requestPermissions(): Promise<boolean> {
    // Request notification permissions
    return await myNotificationLib.requestPermission();
  }

  async isEnabled(): Promise<boolean> {
    // Check if notifications are enabled
    return await myNotificationLib.areNotificationsEnabled();
  }

  onNotification(handler: (notification: Notification) => void): () => void {
    // Subscribe to incoming notifications
    const subscription = myNotificationLib.onNotification(handler);
    return () => subscription.remove();
  }

  onNotificationResponse(handler: (response: NotificationResponse) => void): () => void {
    // Subscribe to notification taps
    const subscription = myNotificationLib.onNotificationOpened(handler);
    return () => subscription.remove();
  }
}