Convert Figma logo to code with AI

wix logoreact-native-notifications

React Native Notifications

3,224
761
3,224
52

Top Related Projects

React Native Local and Remote Notifications

🔥 A well-tested feature-rich modular Firebase implementation for React Native. Supports both iOS & Android platforms for all Firebase services.

React Native Library for OneSignal Push Notifications Service

Quick Overview

React Native Notifications is a comprehensive library for handling push notifications in React Native applications. It provides a unified API for both iOS and Android platforms, allowing developers to easily integrate and manage push notifications in their cross-platform mobile apps.

Pros

  • Cross-platform compatibility with a unified API for iOS and Android
  • Rich notification support, including custom layouts and actions
  • Seamless integration with popular push notification services
  • Extensive documentation and active community support

Cons

  • Occasional compatibility issues with newer React Native versions
  • Some advanced features may require platform-specific code
  • Setup process can be complex for beginners
  • Limited support for web applications

Code Examples

  1. Registering for push notifications:
import { Notifications } from 'react-native-notifications';

Notifications.registerRemoteNotifications();

Notifications.events().registerRemoteNotificationsRegistered((event) => {
  console.log("Device Token Received", event.deviceToken);
});
  1. Handling incoming notifications:
Notifications.events().registerNotificationReceivedForeground((notification, completion) => {
  console.log("Notification Received - Foreground", notification.payload);
  completion({alert: false, sound: false, badge: false});
});

Notifications.events().registerNotificationOpened((notification, completion) => {
  console.log("Notification opened", notification.payload);
  completion();
});
  1. Sending a local notification:
Notifications.postLocalNotification({
  body: "Local notification!",
  title: "Local Notification Title",
  sound: "chime.aiff",
  category: "SOME_CATEGORY",
  link: "localNotificationLink"
});

Getting Started

  1. Install the library:

    npm install react-native-notifications --save
    
  2. Link the native modules:

    react-native link react-native-notifications
    
  3. For iOS, add the following to your AppDelegate.m:

    #import <ReactNativeNotifications/ReactNativeNotifications.h>
    
    // ...
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
      [ReactNativeNotifications startMonitorNotifications];
      // ...
    }
    
  4. For Android, update your MainActivity.java:

    import com.wix.reactnativenotifications.RNNotificationsPackage;
    
    // ...
    
    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
        new MainReactPackage(),
        new RNNotificationsPackage()
      );
    }
    
  5. Initialize the library in your JavaScript code:

    import { Notifications } from 'react-native-notifications';
    
    Notifications.registerRemoteNotifications();
    

Competitor Comparisons

React Native Local and Remote Notifications

Pros of react-native-push-notification

  • More active development with frequent updates and bug fixes
  • Broader community support and larger user base
  • Extensive documentation and examples for various use cases

Cons of react-native-push-notification

  • Slightly more complex setup process
  • May require additional configuration for certain advanced features
  • Potential compatibility issues with newer React Native versions

Code Comparison

react-native-push-notification:

PushNotification.configure({
  onNotification: function (notification) {
    console.log("NOTIFICATION:", notification);
  },
  permissions: {
    alert: true,
    badge: true,
    sound: true,
  },
});

react-native-notifications:

Notifications.registerRemoteNotifications();
Notifications.events().registerNotificationReceivedForeground((notification, completion) => {
  console.log("Notification Received - Foreground", notification.payload);
  completion({alert: false, sound: false, badge: false});
});

Both libraries offer similar functionality for handling push notifications in React Native applications. react-native-push-notification provides a more straightforward configuration process, while react-native-notifications offers more granular control over notification handling.

The choice between these libraries depends on specific project requirements, desired level of customization, and compatibility with other dependencies in your React Native project.

🔥 A well-tested feature-rich modular Firebase implementation for React Native. Supports both iOS & Android platforms for all Firebase services.

Pros of react-native-firebase

  • Comprehensive Firebase integration: Offers a wide range of Firebase services beyond just notifications
  • Active development and community support: Regular updates and extensive documentation
  • Seamless integration with other Firebase features: Easy to implement analytics, authentication, and more

Cons of react-native-firebase

  • Larger package size: Includes multiple Firebase services, which may increase app size
  • Steeper learning curve: More complex setup and configuration due to its extensive feature set
  • Potential performance impact: Integrating multiple Firebase services may affect app performance

Code Comparison

react-native-notifications:

import NotificationsIOS from 'react-native-notifications';

NotificationsIOS.addEventListener('notificationReceivedForeground', (notification) => {
  console.log("Notification Received - Foreground", notification);
});

react-native-firebase:

import messaging from '@react-native-firebase/messaging';

messaging().onMessage(async remoteMessage => {
  console.log('A new FCM message arrived!', JSON.stringify(remoteMessage));
});

Both libraries provide similar functionality for handling notifications, but react-native-firebase offers a more Firebase-specific implementation. The react-native-notifications library is more focused on general push notifications, while react-native-firebase provides a broader range of Firebase services and integrations.

React Native Library for OneSignal Push Notifications Service

Pros of react-native-onesignal

  • Comprehensive documentation and extensive features for push notifications
  • Built-in analytics and user segmentation capabilities
  • Easier setup process with guided integration steps

Cons of react-native-onesignal

  • Tied to OneSignal's platform, potentially limiting flexibility
  • May have a steeper learning curve for developers new to OneSignal
  • Some advanced features may require a paid plan

Code Comparison

react-native-notifications:

import { Notifications } from 'react-native-notifications';

Notifications.registerRemoteNotifications();

Notifications.events().registerNotificationReceivedForeground((notification, completion) => {
  console.log(`Notification received in foreground: ${notification.title}`);
  completion({alert: false, sound: false, badge: false});
});

react-native-onesignal:

import OneSignal from 'react-native-onesignal';

OneSignal.setAppId('YOUR_ONESIGNAL_APP_ID');

OneSignal.setNotificationWillShowInForegroundHandler(notificationReceivedEvent => {
  console.log("OneSignal: notification will show in foreground:", notificationReceivedEvent);
  let notification = notificationReceivedEvent.getNotification();
  notificationReceivedEvent.complete(notification);
});

The code comparison shows that react-native-onesignal requires an app ID and offers a more streamlined API for handling notifications. react-native-notifications provides a more granular approach to notification management, which may be preferred for custom implementations.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README


React Native Notifications

npm Build Status npm (tag) npm (tag)

Handle all the aspects of push notifications for your app, including remote and local notifications, interactive notifications, silent notifications, and more.

All the native iOS notifications features are supported!

For information regarding proper integration with react-native-navigation, follow this wiki.

Requirements

Apps using React Native Notifications may target iOS 10 and Android 5.0 (API 21). You may use Windows, macOS or Linux as your development operating system.

iOS

  • Remote (push) notifications
  • Local notifications
  • Background/Managed notifications (notifications that can be cleared from the server, like Facebook messenger and Whatsapp web)
  • PushKit API (for VoIP and other background messages)
  • Interactive notifications (allows you to provide additional functionality to your users outside of your application such as action buttons)

Android

  • Receiving notifications in any App state (foreground, background, "dead")
  • Built-in notification drawer management
  • High degree of code extensibility to allow for advanced custom layouts and any specific notifications behavior as available by Android's API
  • Android equivalent of React-Native's implementation of PushNotificationsIOS.getInitialNotification().

Upcoming: local notifications, background-state Rx queue (iOS equivalent)

Quick Links

License

The MIT License.

See LICENSE

NPM DownloadsLast 30 Days